接下来开始代码部分,首先引入相关jar包,只需要两个jar包
org.apache.poi
poi
3.8
org.apache.poi
poi-ooxml
3.8
然后是导出的主代码
/**
*
* @param reportList 需要导出的数据
* @throws Exception
*/
public static void exportImage(List reportList,File resultFile)throws Exception {
long startTime = System.currentTimeMillis(); //获取开始时间
XSSFWorkbook input_work = new XSSFWorkbook();
XSSFSheet inpub_sheet = input_work.createSheet("报送记录");
// 设置样式
XSSFCellStyle textStyle10 = input_work.createCellStyle();
textStyle10.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中
// 设置垂直居中
textStyle10.setAlignment(HorizontalAlignment.CENTER);
textStyle10.setVerticalAlignment((short) 1);
// 设置细边框
textStyle10.setWrapText(true);
XSSFFont fontText2 = input_work.createFont();
// 字体号码
fontText2.setFontHeightInPoints((short) 11);
// 字体名称
fontText2.setFontName("微软雅黑");
textStyle10.setFont(fontText2);
textStyle10.setAlignment(HorizontalAlignment.CENTER);//上下居中
// 设置样式
XSSFCellStyle textStyle = input_work.createCellStyle();
textStyle.setAlignment(XSSFCellStyle.ALI