动态的导出excel设置
1.添加pom插件导入
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16-beta2</version>
</dependency>
2.接口里加入List getAll方法、接口的实现类实现方法
3.控制器中设置
@RequestMapping("export")
public void export(HttpServletResponse response) throws IOException {
List<SalesChance> list = salesChanceService.getAll();
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet();
int startRow = 1;
Row row=null;
Cell cell = null;
int startColum = 1;
for(SalesChance salesChance : list) {
row = sheet.createRow(startRow++);
startColum=1;
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getId());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getSupplier().getId());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getSupplierName());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getSalDate());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getGoods().getId());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getGoodsNum());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getPrice());
cell = row.createCell(startColum++);
cell.setCellValue(salesChance.getSalPrice());
}
cell.setCellValue("tom");
response.setContentType("application/vnd.ms-excel");
ServletOutputStream outputStream = response.getOutputStream();
wb.write(outputStream);
outputStream.close();
wb.close();
}