项目地址:https://gitee.com/sanri/sanri-excel-poi
优势:简单的配置便可实现导出精美的 Excel 表格,能够不用配置来导入一列数据,导入 map 数据,简单配置能够导入实体数据。
解决了一些常见问题,好比java
发现BUG能够提Issue,能够给我发邮件,能够加我QQ,能够进9420技术群讨论.git
做者QQ: 2441719087redis
做者邮箱: ningxiangsanri@163.com数据库
9420 技术交流群: 645576465apache
做者微信:sanri1993-微信
之后会上传中央仓库,引用 maven 地址为maven
<dependency> <groupId>com.sanri.excel</groupId> <artifactId>sanri-excel-poi</artifactId> <version>1.0-RELEASE</version> </dependency>
目前须要本身下载代码来构建,或下载已经构建好的 release 包 :工具
https://gitee.com/sanri/sanri-excel-poi/repository/archive/v1.0-RELEASE?format=zip大数据
<!-- Excel poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.10-FINAL</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>3.10-FINAL</version> </dependency> <!--apache commons --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.8.1</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-csv</artifactId> <version>1.2</version> </dependency> <!-- slf4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.21</version> </dependency>
@ExcelExport @ExcelImport(startRow = 1) @Data public class Simple { @ExcelColumn(value = "年龄",order = 2) private int age; @ExcelColumn(value = "级别",order = 1) private Integer level; @ExcelColumn(value = "姓名",order = 0,chineseWidth = true) private String name; @ExcelColumn(value = "生日",order = 3) private Date birthday; @ExcelColumn(value = "序号",order = 4,hidden = true) private long id; @ExcelColumn(value = "是否成功",order = 5) private boolean success; @ExcelColumn(value = "薪水",order = 6,precision = 2) private double money; @ExcelColumn(value = "奖金",order = 7,precision = 2) private float comm; }
实测在 i5 3 代 cpu ,8 G 内存,导出 10 万数据,用时 5 秒spa
// 从数据库,redis,消息中间件...... 获取的数据 List<Simple> simpleList= simpleBeanDatas(10); // 建立导出类 ExcelExportWriter excelExportWriter = new ExcelExportWriter(Simple.class); // 开始导出 excelExportWriter.export(simpleList); // 写到输出流 excelExportWriter.writeTo(new FileOutputStream("d:/test/"+System.currentTimeMillis()+".xlsx"));
FileInputStream fileInputStream = FileUtils.openInputStream(new File("D:\\test/1567833685699.xlsx")); // 0 表明导入第 0 列数据,1 表示从第 1 行开始 List<String> strings = ExcelImportUtil.importListData(fileInputStream, String.class, 0, 1);
FileInputStream fileInputStream = FileUtils.openInputStream(new File("D:\\test/1567833685699.xlsx")); // 0 表示 key 的列为第 0 列;8 表示第 8 列为值列; 1 表示从第 1 行开始 Map<String, String> stringStringMap = ExcelImportUtil.importMapData(fileInputStream, String.class, 0, 8, 1);
FileInputStream fileInputStream = FileUtils.openInputStream(new File("D:\\test/1567833427823.xlsx")); List<Simple> simples = ExcelImportUtil.importData(fileInputStream, Simple.class);
// Excel 导出版本,可选值 ExcelVersion.EXCEL2007,ExcelVersion.EXCEL2003 ExcelVersion version() default ExcelVersion.EXCEL2007; // 当导出有设置标题时,设置标题行的高度 short titleRowHeight() default 40; // 头部行的高度,即列说明行的高度 short headRowHeight() default 30; // 每一行数据的高度 short bodyRowHeight() default 25; // 是否自动宽度,Excel 的自动宽度对中文支持很差,我这里对中文宽度作了适应 boolean autoWidth() default true; // 一个 sheet 页的最大数据量,设置 -1 表示不限制,2003 版本最大 60000 行;超过的行数会另起 sheet 页 int sheetMaxRow() default -1; // 快速导出模式,使用 new SXSSFWorkbook(rowAccessWindowSize) workbook 对象 boolean fastModel() default true; // 快速导出模式的一个设置,通常默认就行 int rowAccessWindowSize() default 1000;
// 数据起始行,通常设置 1 就行,从 0 开始 int startRow(); // 支持导入的版本,默认都支持 ExcelVersion[] support() default {ExcelVersion.EXCEL2003,ExcelVersion.EXCEL2007};
// 导出的中文头部列的值,导入不用管 String value(); // 导入的顺序,默认从 0 开始,导出不用管 int order() default -1; // 宽度,Excel 宽度单元 int width() default -1; // 使用字符数来定义宽度,一个中文算一个字符 int charWidth() default -1; // 使用像素值来定义宽度 int pxWidth() default -1; // 在使用自动宽度的时候,标记当前列是中文列 boolean chineseWidth() default false; // 导出是否隐藏当前列 boolean hidden() default false; // 导入的时候对当前列作字符串先后空格过滤 boolean trim() default true; // 导出的时候的单元格类型,可选值有CELL_TYPE_NUMERIC,CELL_TYPE_STRING,CELL_TYPE_BLANK,CELL_TYPE_BOOLEAN CellType cellType() default CellType.CELL_TYPE_STRING; // 导入、导出日期格式 String pattern() default "yyyy-MM-dd"; // 导入、导出的数字精度设置,会对浮点型作处理 int precision() default -1;