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         }

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

  • 相关阅读:
    D. Constructing the Array
    B. Navigation System
    B. Dreamoon Likes Sequences
    A. Linova and Kingdom
    G. Special Permutation
    B. Xenia and Colorful Gems
    Firetrucks Are Red
    java getInstance()的使用
    java 静态代理和动态代理
    java 类加载机制和反射机制
  • 原文地址:https://www.cnblogs.com/xiaoyao-001/p/9330535.html
Copyright © 2011-2022 走看看