@Override
public void excelBusinessData(HttpServletResponse response) {
//查询数据库获取营业数据
List<Report> reportList = reportMapper.excelBusinessData();
//通过poi将数据写入到excel文件中
InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("template/template.xlsx");
//基于模版文件创建一个新的excel
try {
XSSFWorkbook excel = new XSSFWorkbook(resourceAsStream);
//获取标签页
XSSFSheet sheet1 = excel.getSheet("Sheet1");
sheet1.getRow(1).getCell(1).setCellValue("我是第二行第二列");
//获得第三行
XSSFRow row = sheet1.getRow(2);
row.getCell(0).setCellValue("我是第三行第一列");
row.getCell(1).setCellValue("我是第三行第二列");
row.getCell(2).setCellValue("我是第三行第三列");
row.getCell(3).setCellValue("我是第三行第四列");
//填充真实数据
for (Report report : reportList) {
//获得某一行
row.getCell(7 );
row.getCell(0).setCellValue(report.getFilName());
row.getCell(1).setCellValue(report.getRepOrder());
row.getCell(2).setCellValue(report.getRepPdfUrl());
row.getCell(3).setCellValue(report.getStatus());
row.getCell(4).setCellValue(report.getUserName());
}
/* for (int i = 0; i < 30; i++) {
//获得某一行
row.getCell(7 + i);
row.getCell(0).setCellValue(report.getFilName());
}
*/
//通过输出流将excel文件下载到客户端的浏览器
ServletOutputStream outputStream = response.getOutputStream();
excel.write(outputStream);
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
excel意思理解帮助
最新推荐文章于 2024-06-15 04:25:16 发布