将数据写入已有的excel文件

 1     /**
 2      * 将反馈结果写入excel中
 3      * */
 4     public static void writeExcelResult(String url,List<Integer> result) throws Exception{
 5 //        支持excel2003、2007
 6         File excelFile = new File(url);//创建excel文件对象
 7         InputStream is = new FileInputStream(excelFile);//创建输入流对象
 8         checkExcelVaild(excelFile);
 9         Workbook workbook = getWorkBook(is, excelFile);
10 //        Workbook workbook = WorkbookFactory.create(is);//同时支持2003、2007、2010
11 //        获取Sheet数量
12         int sheetNum = workbook.getNumberOfSheets();
13         sheetNum = 1;//限制模板只在一个工作簿上操作
14 //        遍历工作簿中的sheet,第一层循环所有sheet表
15         for(int index = 0;index<sheetNum;index++){
16             Sheet sheet = workbook.getSheetAt(index);
17             if(sheet==null){
18                 continue;
19             }
20 //            如果当前行没有数据跳出循环,第二层循环单sheet表中所有行
21             for(int rowIndex=3;rowIndex<=sheet.getLastRowNum();rowIndex++){
22                 Row row = sheet.getRow(rowIndex);
23                 row.createCell(1).setCellValue(result.get(rowIndex-3));
24             }
25             
26         }
27         FileOutputStream outputStream = new FileOutputStream(url);
28         workbook.write(outputStream);
29         outputStream.close();
30         }

写入本地某一文件,写入下面模板的红色方框中

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值