项目案例:Excel导出
预算中心部门 | 业绩来源 | 近三年销售数据及预测 | 预算分解 | |||||||||||||||||||||||||||||||||||||||||
机构简称 | 一级部门 | 二级部门 | 三级部门 | 四级部门 | 销售人员 | 省 | 市 | 县或区 | 渠道分类 | 渠道名称 | 订单类型 | 门店 | 订单数量 | 订单金额 | 订单数量 | 订单金额 | ||||||||||||||||||||||||||||
2018 | 2019 | 2020 | 2021 | 2018 | 2019 | 2020 | 2021 | 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月 | 1月 | 2月 | 3月 | 4月 | 5月 | 6月 | 7月 | 8月 | 9月 | 10月 | 11月 | 12月 |
关键技术: POI
使用apache poi 3.17的版本开发
(JAR包下载: https://n459.com/file/29938189-468251056)
第一需要解决跨行跨列问题
关键方法:new CellRangeAddress(0, 0, 0, 5)
poi的row,cell都是以0开始的,方法中的四个参数分表表示:开始行数,跨行截止行数;开始列数,跨列截止列数。
/*构建第一行*/ Row row = sheet.createRow(0); Cell cell = row.createCell(0); cell.setCellValue("预算中心部门"); cell.setCellStyle(styles.get("style_tan")); sheet.addMergedRegion( new CellRangeAddress(0, 0, 0, 5)); cell = row.createCell(6); cell.setCellValue("业绩来源"); cell.setCellStyle(styles.get("blue_data")); sheet.addMergedRegion( new CellRangeAddress(0, 0, 6, 12)); cell = row.createCell(13); cell.setCellValue("近三年销售数据及预测"); cell.setCellStyle(styles.get("tan_data")); sheet.addMergedRegion( new CellRangeAddress(0, 0, 13, 20)); cell = row.createCell(21); cell.setCellValue("预算分解"); cell.setCellStyle(styles.get("white_data")); sheet.addMergedRegion( new CellRangeAddress(0, 0, 21, 44));
第二个就比较简单了,实现样式
主要是设置颜色:setFillForegroundColor
样式代码
CellStyle styleTan = wb.createCellStyle(); styleTan.setFillForegroundColor(IndexedColors.TAN.getIndex()); styleTan.setFillPattern(FillPatternType.SOLID_FOREGROUND); styleTan.setAlignment(HorizontalAlignment.CENTER); styleTan.setVerticalAlignment(VerticalAlignment.CENTER); styleTan.setBorderRight(BorderStyle.THIN); styleTan.setBorderLeft(BorderStyle.THIN); styleTan.setBorderTop(BorderStyle.THIN); styleTan.setBorderBottom(BorderStyle.THIN); Font fontRed = wb.createFont(); fontRed.setFontName("Arial"); fontRed.setFontHeightInPoints((short) 10); fontRed.setColor(IndexedColors.RED.getIndex()); styleTan.setFont(fontRed); styles.put("style_tan_red", styleTan);
最后送上前端、后端开发工具下载链接
https://n459.com/dir/29938189-41206693-20c570
需要的小朋友可以下载
- node-v12.13.1-x64.msi
- yarn-1.21.1.msi
- ideaIU-2019.2.3.exe
- jdk-8u191-windows-x64.exe
- apache-maven-3.5.4.zip
- redis64-3.0.501
- mysql-5.7.26-winx64.zip
- navicat 破解版
- postman
- redis-desktop