public static Workbook fillExcelDataWithTemplate(List<StatisticsDTO> list ,String templateFileUrl) {
Workbook wb = null ;
try {
File file = new File(templateFileUrl);
if(!file.exists()){
file.createNewFile();
}
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
wb = new HSSFWorkbook(fs);
// 取得 模板的 第一个sheet 页
Sheet sheet = wb.getSheetAt(0);
// 拿到sheet页有 多少列
int cellNums = sheet.getRow(0).getLastCellNum();
// 从第2行 开搞 下标1 就是第2行
int rowIndex = 1;
Row row ;
for(StatisticsDTO statisticsDTO : list){
row = sheet.createRow(rowIndex);
rowIndex ++;
row.createCell( 0).setCellValue(statisticsDTO.getId());
row.createCell(1).setCellValue(statisticsDTO.getNewUserCount());
row.createCell(2).setCellValue(statisticsDTO.getTotalPayCount());
row.createCell(3).setCellValue(statisticsDTO.getTotalPayNum());
row.createCell(4).setCellValue(statisticsDTO.getWeixinpayPayCount());
row.createCell(5).setCellValue(statisticsDTO.getWeixinpayPayNum());
row.createCell(6).setCellValue(statisticsDTO.getAlipayPayCount());
row.createCell(7).setCellValue(statisticsDTO.getAlipayPayNum());
row.createCell(8).setCellValue(statisticsDTO.getDggPayCount());
row.createCell(9).setCellValue(statisticsDTO.getDggPayNum());
row.createCell(10).setCellValue(DateUtil.formatDate(statisticsDTO.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
}
} catch (IOException e) {
e.printStackTrace();
}
return wb;
}