实用网站开发,app开发网站排行榜,怎么做网站里的资讯,百度网盘登录入口工作台——需求分析与设计
产品原型 接口设计 工作台——代码导入
将提供的代码导入对应的位置。
工作台——功能测试 Apache POI_介绍 应用场景 Apache POI_入门案例
导入坐标 !-- poi --dependencygroupIdorg.apache.poi/groupIdar…工作台——需求分析与设计
产品原型 接口设计 工作台——代码导入
将提供的代码导入对应的位置。
工作台——功能测试 Apache POI_介绍 应用场景 Apache POI_入门案例
导入坐标 !-- poi --dependencygroupIdorg.apache.poi/groupIdartifactIdpoi/artifactIdversion3.16/version/dependencydependencygroupIdorg.apache.poi/groupIdartifactIdpoi-ooxml/artifactIdversion3.16/version/dependency
通过POI向Excel文件写入文件内容
/*** 使用POI操作Excel文件**/
public class POITest {/*** 通过POI创建Excel文件并且写入文件内容*/public static void write() throws IOException {//在内存中创建一个Excel文件XSSFWorkbook excelnew XSSFWorkbook();//在Excel文件中创建一个Sheet页XSSFSheet sheet excel.createSheet(info);//在Sheet中创建行对象,编号从0开始1表示第二行XSSFRow row sheet.createRow(1);//创建单元格同样从0开始1,2表示第2和第3格XSSFCell cell1 row.createCell(1);XSSFCell cell2 row.createCell(2);//在单元格写入文本内容cell1.setCellValue(姓名);cell2.setCellValue(城市);//创建一个新行row sheet.createRow(2);row.createCell(1).setCellValue(张三);row.createCell(2).setCellValue(北京);row sheet.createRow(3);row.createCell(1).setCellValue(鼠鼠);row.createCell(2).setCellValue(北岭山);//通过输出流将内存中的Excel文件写入到磁盘FileOutputStream out new FileOutputStream(new File(H:\\workspace\\changqiong\\info.xlsx));excel.write(out);//关闭资源out.close();excel.close();}public static void main(String[] args) throws IOException {write();}
}
效果展示 通过POI读取Excel文件内容 /*** 通过POI读取Excel文件内容* throws Exception*/public static void read() throws Exception{InputStream in new FileInputStream(new File(H:\\workspace\\changqiong\\info.xlsx));//读取磁盘上已经存在的Excel文件XSSFWorkbook excelnew XSSFWorkbook(in);//读取Excel文件中的第一个Sheet页XSSFSheet sheet excel.getSheetAt(0);//获取有文字的最后一行的行号int lastRowNum sheet.getLastRowNum();for(int i1;ilastRowNum;i){//获得某一行XSSFRow row sheet.getRow(i);//获得单元格String CellValue1 row.getCell(1).getStringCellValue();String CellValue2 row.getCell(2).getStringCellValue();System.out.println(CellValue1 CellValue2);}//关闭资源in.close();excel.close();}
读取上面创建的Excel文件并输出得到 导出运营数据Excel报表——需求分析与设计
产品原型 接口设计 导出运营数据Excel报表——代码开发
实现步骤 Controller中 /*** 导出运营数据报表* param response*/ApiOperation(导出运营数据报表)GetMapping(export)public void export(HttpServletResponse response){reportService.exportBusinessData(response);}
Service中
/*** 导出运营数据报表* param response*/Overridepublic void exportBusinessData(HttpServletResponse response) {//1.查询数据库获取营业数据----查询最近30天运营数据LocalDate dateBegin LocalDate.now().minusDays(30);LocalDate dateEnd LocalDate.now().minusDays(1);//查询概览数据BusinessDataVO businessDataVO workspaceService.getBusinessData(LocalDateTime.of(dateBegin, LocalTime.MIN), LocalDateTime.of(dateEnd, LocalTime.MAX));//2.通过POI将数据写入到Excel文件中//获得这个类对象获得类加载器从类路径下读取资源返回一个输入流对象InputStream in this.getClass().getClassLoader().getResourceAsStream(template/运营数据报表模板.xlsx);try {//基于模板文件创建一个新的Excel文件XSSFWorkbook excelnew XSSFWorkbook(in);//获取表格文件的Sheet页XSSFSheet sheet excel.getSheet(Sheet1);//填充数据--时间sheet.getRow(1).getCell(1).setCellValue(时间:dateBegin至dateEnd);//获得第4行XSSFRow row sheet.getRow(3);row.getCell(2).setCellValue(businessDataVO.getTurnover());row.getCell(4).setCellValue(businessDataVO.getOrderCompletionRate());row.getCell(6).setCellValue(businessDataVO.getNewUsers());//获得第5行row sheet.getRow(4);row.getCell(2).setCellValue(businessDataVO.getValidOrderCount());row.getCell(4).setCellValue(businessDataVO.getUnitPrice());//填充明细数据for(int i0;i30;i){LocalDate date dateBegin.plusDays(i);//查询某一天的营业数据BusinessDataVO businessData workspaceService.getBusinessData(LocalDateTime.of(date, LocalTime.MIN), LocalDateTime.of(date, LocalTime.MAX));//获得某一行row sheet.getRow(7 i);row.getCell(1).setCellValue(date.toString());row.getCell(2).setCellValue(businessData.getTurnover());row.getCell(3).setCellValue(businessData.getValidOrderCount());row.getCell(4).setCellValue(businessData.getOrderCompletionRate());row.getCell(5).setCellValue(businessData.getUnitPrice());row.getCell(6).setCellValue(businessData.getNewUsers());}//3.通过输出流将Excel下载到客户端浏览器ServletOutputStream out response.getOutputStream();excel.write(out);//关闭资源out.close();excel.close();} catch (IOException e) {throw new RuntimeException(e);}}
Mapper中
使用了workspaceService里面的方法中的Mapper 导出运营数据Excel报表——功能测试