一、使用excel工具自带的图形工具建立一个图:apache
二、绑定数据区域:xss
三、数据区域绑定完成,咱们要作的就是将数据写入到数据区域中:工具
四、标记3d
五、POI 引入包excel
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.14</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.14</version> </dependency>
六、代码:code
FileInputStream is = new FileInputStream("刚才建立的文件所在目录+文件名"); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is); FileOutputStream os = new FileOutputStream("导出的位置"); //获取建立工做簿的第一页 XSSFSheet sheet = xssfWorkbook.getSheetAt(0); //自动计算 sheet.setForceFormulaRecalculation(true); //给指定的sheet命名 xssfWorkbook.setSheetName(0, "sheet0"); //初始化当前的索引,设为当前sheet的最后一行行数 int allRows = sheet.getLastRowNum(); //存储当前表格的样式 XSSFCellStyle cellStyle = xssfWorkbook.createCellStyle(); //填充数据 for(int i=allRows;i<=allRows;i++){ XSSFRow row = sheet.getRow(i); if (row == null) { continue; } //遍历列 for (int j = 1; j <=dailyReportPart8.size(); j++) { XSSFCell cell = row.getCell(j) != null ? row.getCell(j) : row.createCell(j); String cellValue = cell.getStringCellValue(); if (cellValue.startsWith("#a1")) { cell.setCellValue(1); } } } //写出 xssfWorkbook.write(os); //TODO 流的处理 is.close(); os.flush(); os.close();