/**
*
* @param excelPath excel模板路径
* @param downloadPath 文件下载路径
* @param list 报表数据
* @param response
* @return
* @throws Exception
*/
@SuppressWarnings("resource")
public AjaxResult excel(String excelPath, String downloadPath, List<QuestionReport> list, HttpServletResponse response) throws Exception{
OutputStream out = null;
//获取excel模板路径
File fi = new File(excelPath);
//获取文件名称
String fileName = fi.getName();
//读取excel模板
InputStream inp = new FileInputStream(fi);
//创建xlsx-excel文件
XSSFWorkbook wb = new XSSFWorkbook(inp);
//获取第一个sheet
XSSFSheet sheet = wb.getSheetAt(0);
//填充数据
for (int i = 0; i < list.size(); i++) {
//从第三行开始创建
XSSFRow row = sheet.createRow(2 + i);
QuestionReport questionReport = list.get(i);
//填充第三行第一个数据
row.createCell(0).setCellValue(1 + i);
row.createCell(1).setCellValue(questionReport.getProjectCode());
row.createCell(2).setCellValue(questionReport.getProjectName());
row.createCell(3).setCellValue(questionReport.getProjectDept());
row.createCell(4).setCellValue(questionReport.getBuildQualityHead());
row.createCell(5).setCellValue(questionReport.getProjectBuildingNos());
row.createCell(6).setCellValue(questionReport.getZlQuestion());
row.createCell(7).setCellValue(questionReport.getZlYZG());
row.createCell(8).setCellValue(questionReport.getZlDzg());
row.createCell(9).setCellValue(questionReport.getAqQuestion());
row.createCell(10).setCellValue(questionReport.getAqYZG());
row.createCell(11).setCellValue(questionReport.getAqDzg());
row.createCell(12).setCellValue(questionReport.getCbQuestion());
row.createCell(13).setCellValue(questionReport.getCbYZG());
row.createCell(14).setCellValue(questionReport.getCbDzg());
row.createCell(15).setCellValue(questionReport.getCbQuestion());
row.createCell(16).setCellValue(questionReport.getCbYZG());
row.createCell(17).setCellValue(questionReport.getCbDzg());
}
//修改模板内容导出新模板
fileName ="报事工单报表" + ".xlsx";
out = new FileOutputStream(downloadPath + fileName);
wb.write(out);
out.close();
out.flush();
return AjaxResult.success(fileName);
}