zoukankan      html  css  js  c++  java
  • 将数据写入已有的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         }

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

  • 相关阅读:
    VLAN应用实例
    eNSP 简介及基础操作
    管道符、重定向
    使用Bind提供域名解析服务-DNS
    Samba服务
    虚拟网站主机功能
    springboot接受表单400错误
    Java方法遍历一次数组返回两个结果(最大值与最小值)
    Java异常总结
    Java内部类
  • 原文地址:https://www.cnblogs.com/xiaoyao-001/p/9330535.html
Copyright © 2011-2022 走看看