Browse Source

优化读写逻辑

developing
罗成 5 years ago
parent
commit
6b37ba2f26
  1. 1
      .travis.yml
  2. 26
      README.md
  3. 4
      pom.xml
  4. 114
      quickstart.md
  5. 97
      src/main/java/com/alibaba/excel/EasyExcelFactory.java
  6. 1
      src/main/java/com/alibaba/excel/ExcelReader.java
  7. 3
      src/main/java/com/alibaba/excel/analysis/ExcelAnalyser.java
  8. 2
      src/main/java/com/alibaba/excel/analysis/ExcelExecutor.java
  9. 11
      src/main/java/com/alibaba/excel/analysis/v03/XlsRecordHandler.java
  10. 6
      src/main/java/com/alibaba/excel/analysis/v07/XlsxCellHandler.java
  11. 14
      src/main/java/com/alibaba/excel/annotation/ExcelProperty.java
  12. 12
      src/main/java/com/alibaba/excel/annotation/format/DateTimeFormat.java
  13. 10
      src/main/java/com/alibaba/excel/annotation/format/NumberFormat.java
  14. 2
      src/main/java/com/alibaba/excel/annotation/write/style/ColumnWidth.java
  15. 2
      src/main/java/com/alibaba/excel/annotation/write/style/ContentRowHeight.java
  16. 2
      src/main/java/com/alibaba/excel/annotation/write/style/HeadRowHeight.java
  17. 5
      src/main/java/com/alibaba/excel/cache/ReadCache.java
  18. 13
      src/main/java/com/alibaba/excel/context/AnalysisContext.java
  19. 22
      src/main/java/com/alibaba/excel/converters/Converter.java
  20. 2
      src/main/java/com/alibaba/excel/event/WriteHandler.java
  21. 3
      src/main/java/com/alibaba/excel/exception/ExcelAnalysisException.java
  22. 1
      src/main/java/com/alibaba/excel/exception/ExcelGenerateException.java
  23. 6
      src/main/java/com/alibaba/excel/metadata/AbstractHolder.java
  24. 2
      src/main/java/com/alibaba/excel/metadata/CellData.java
  25. 6
      src/main/java/com/alibaba/excel/metadata/ConfigurationHolder.java
  26. 2
      src/main/java/com/alibaba/excel/metadata/Holder.java
  27. 13
      src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java
  28. 11
      src/main/java/com/alibaba/excel/read/builder/ExcelReaderSheetBuilder.java
  29. 3
      src/main/java/com/alibaba/excel/read/listener/ReadListenerRegistryCenter.java
  30. 9
      src/main/java/com/alibaba/excel/read/metadata/ReadBasicParameter.java
  31. 9
      src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java
  32. 9
      src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
  33. 6
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java
  34. 3
      src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
  35. 2
      src/main/java/com/alibaba/excel/util/BooleanUtils.java
  36. 4
      src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java
  37. 6
      src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
  38. 3
      src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java
  39. 3
      src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java
  40. 3
      src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataTest.java
  41. 27
      src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java
  42. 6
      src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java
  43. 45
      src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java
  44. 18
      src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java
  45. 108
      src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

1
.travis.yml

@ -7,3 +7,4 @@ before_install:
- chmod +x mvnw - chmod +x mvnw
install: install:
- ./mvnw install -Dgpg.skip -B -V -Dmaven.test.skip=true - ./mvnw install -Dgpg.skip -B -V -Dmaven.test.skip=true
- ./mvnw javadoc:javadoc

26
README.md

@ -25,10 +25,10 @@ Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
<version>2.0.0</version> <version>2.0.0-beta1</version>
</dependency> </dependency>
``` ```
## 最新版本:2.0.0 ## 最新版本:2.0.0-beta1
## 维护者 ## 维护者
姬朋飞(玉霄) 姬朋飞(玉霄)
## 快速开始 ## 快速开始
@ -38,9 +38,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java ```java
/** /**
* 最简单的读 * 最简单的读
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@Test @Test
public void simpleRead() { public void simpleRead() {
@ -55,8 +55,8 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java ```java
/** /**
* 最简单的写 * 最简单的写
* <li>1. 创建excel对应的实体对象 参照{@link com.alibaba.easyexcel.test.demo.write.DemoData} * <p>1. 创建excel对应的实体对象 参照{@link com.alibaba.easyexcel.test.demo.write.DemoData}
* <li>2. 直接写即可 * <p>2. 直接写即可
*/ */
@Test @Test
public void simpleWrite() { public void simpleWrite() {
@ -72,9 +72,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java ```java
/** /**
* 文件下载 * 文件下载
* <li>1. 创建excel对应的实体对象 参照{@link DownloadData} * <p>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <li>2. 设置返回的 参数 * <p>2. 设置返回的 参数
* <li>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大 * <p>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
*/ */
@GetMapping("download") @GetMapping("download")
public void download(HttpServletResponse response) throws IOException { public void download(HttpServletResponse response) throws IOException {
@ -86,9 +86,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
/** /**
* 文件上传 * 文件上传
* <li>1. 创建excel对应的实体对象 参照{@link UploadData} * <p>1. 创建excel对应的实体对象 参照{@link UploadData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@PostMapping("upload") @PostMapping("upload")
@ResponseBody @ResponseBody

4
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
<version>2.0.0</version> <version>2.0.0-beta1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>easyexcel</name> <name>easyexcel</name>
@ -214,7 +214,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId> <artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version> <version>3.1.0</version>
<executions> <executions>
<execution> <execution>
<id>attach-javadocs</id> <id>attach-javadocs</id>

114
quickstart.md

@ -78,9 +78,9 @@ public class DemoDataListener extends AnalysisEventListener<DemoData> {
```java ```java
/** /**
* 最简单的读 * 最简单的读
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@Test @Test
public void simpleRead() { public void simpleRead() {
@ -127,9 +127,9 @@ public class IndexOrNameData {
/** /**
* 指定列的下标或者列名 * 指定列的下标或者列名
* *
* <li>1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData} * <p>1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link IndexOrNameDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link IndexOrNameDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@Test @Test
public void indexOrNameRead() { public void indexOrNameRead() {
@ -150,9 +150,9 @@ public class IndexOrNameData {
```java ```java
/** /**
* 读多个sheet,这里注意一个sheet不能读取多次,多次读取需要重新读取文件 * 读多个sheet,这里注意一个sheet不能读取多次,多次读取需要重新读取文件
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@Test @Test
public void repeatedRead() { public void repeatedRead() {
@ -248,9 +248,9 @@ public class CustomStringStringConverter implements Converter<String> {
* 日期、数字或者自定义格式转换 * 日期、数字或者自定义格式转换
* <p> * <p>
* 默认读的转换器{@link DefaultConverterLoader#loadDefaultReadConverter()} * 默认读的转换器{@link DefaultConverterLoader#loadDefaultReadConverter()}
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解 * <p>1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link ConverterDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link ConverterDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@Test @Test
public void converterRead() { public void converterRead() {
@ -277,9 +277,9 @@ public class CustomStringStringConverter implements Converter<String> {
/** /**
* 多行头 * 多行头
* *
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 设置headRowNumber参数,然后读。 这里要注意headRowNumber如果不指定, 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数, * <p>3. 设置headRowNumber参数,然后读。 这里要注意headRowNumber如果不指定, 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数,
* 如果不传入class则默认为1.当然你指定了headRowNumber不管是否传入class都是以你传入的为准。 * 如果不传入class则默认为1.当然你指定了headRowNumber不管是否传入class都是以你传入的为准。
*/ */
@Test @Test
@ -335,9 +335,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java ```java
/** /**
* 文件上传 * 文件上传
* <li>1. 创建excel对应的实体对象 参照{@link UploadData} * <p>1. 创建excel对应的实体对象 参照{@link UploadData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener} * <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
* <li>3. 直接读即可 * <p>3. 直接读即可
*/ */
@PostMapping("upload") @PostMapping("upload")
@ResponseBody @ResponseBody
@ -381,8 +381,8 @@ public class DemoData {
```java ```java
/** /**
* 最简单的写 * 最简单的写
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 直接写即可 * <p>2. 直接写即可
*/ */
@Test @Test
public void simpleWrite() { public void simpleWrite() {
@ -425,9 +425,9 @@ public class IndexData {
```java ```java
/** /**
* 指定写入的列 * 指定写入的列
* <li>1. 创建excel对应的实体对象 参照{@link IndexData} * <p>1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>2. 使用{@link ExcelProperty}注解指定写入的列 * <p>2. 使用{@link ExcelProperty}注解指定写入的列
* <li>3. 直接写即可 * <p>3. 直接写即可
*/ */
@Test @Test
public void indexWrite() { public void indexWrite() {
@ -456,9 +456,9 @@ public class ComplexHeadData {
```java ```java
/** /**
* 复杂头写入 * 复杂头写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData} * <p>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头 * <p>2. 使用{@link ExcelProperty}注解指定复杂的头
* <li>3. 直接写即可 * <p>3. 直接写即可
*/ */
@Test @Test
public void complexHeadWrite() { public void complexHeadWrite() {
@ -477,9 +477,9 @@ public class ComplexHeadData {
```java ```java
/** /**
* 重复多次写入 * 重复多次写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData} * <p>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头 * <p>2. 使用{@link ExcelProperty}注解指定复杂的头
* <li>3. 直接调用二次写入即可 * <p>3. 直接调用二次写入即可
*/ */
@Test @Test
public void repeatedWrite() { public void repeatedWrite() {
@ -526,9 +526,9 @@ public class ConverterData {
```java ```java
/** /**
* 日期、数字或者自定义格式转换 * 日期、数字或者自定义格式转换
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData} * <p>1. 创建excel对应的实体对象 参照{@link ConverterData}
* <li>2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解 * <p>2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解
* <li>3. 直接写即可 * <p>3. 直接写即可
*/ */
@Test @Test
public void converterWrite() { public void converterWrite() {
@ -561,8 +561,8 @@ public class ImageData {
```java ```java
/** /**
* 图片导出 * 图片导出
* <li>1. 创建excel对应的实体对象 参照{@link ImageData} * <p>1. 创建excel对应的实体对象 参照{@link ImageData}
* <li>2. 直接写即可 * <p>2. 直接写即可
*/ */
@Test @Test
public void imageWrite() throws Exception { public void imageWrite() throws Exception {
@ -601,10 +601,10 @@ public class ImageData {
```java ```java
/** /**
* 根据模板写入 * 根据模板写入
* <li>1. 创建excel对应的实体对象 参照{@link IndexData} * <p>1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>2. 使用{@link ExcelProperty}注解指定写入的列 * <p>2. 使用{@link ExcelProperty}注解指定写入的列
* <li>3. 使用withTemplate 读取模板 * <p>3. 使用withTemplate 读取模板
* <li>4. 直接写即可 * <p>4. 直接写即可
*/ */
@Test @Test
public void templateWrite() { public void templateWrite() {
@ -641,9 +641,9 @@ public class WidthAndHeightData {
```java ```java
/** /**
* 列宽、行高 * 列宽、行高
* <li>1. 创建excel对应的实体对象 参照{@link WidthAndHeightData} * <p>1. 创建excel对应的实体对象 参照{@link WidthAndHeightData}
* <li>2. 使用注解{@link ColumnWidth}、{@link HeadRowHeight}、{@link ContentRowHeight}指定宽度或高度 * <p>2. 使用注解{@link ColumnWidth}、{@link HeadRowHeight}、{@link ContentRowHeight}指定宽度或高度
* <li>3. 直接写即可 * <p>3. 直接写即可
*/ */
@Test @Test
public void widthAndHeightWrite() { public void widthAndHeightWrite() {
@ -662,9 +662,9 @@ public class WidthAndHeightData {
```java ```java
/** /**
* 自定义样式 * 自定义样式
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 创建一个style策略 并注册 * <p>2. 创建一个style策略 并注册
* <li>3. 直接写即可 * <p>3. 直接写即可
*/ */
@Test @Test
public void styleWrite() { public void styleWrite() {
@ -705,9 +705,9 @@ public class WidthAndHeightData {
```java ```java
/** /**
* 合并单元格 * 合并单元格
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 创建一个merge策略 并注册 * <p>2. 创建一个merge策略 并注册
* <li>3. 直接写即可 * <p>3. 直接写即可
*/ */
@Test @Test
public void mergeWrite() { public void mergeWrite() {
@ -729,8 +729,8 @@ public class WidthAndHeightData {
```java ```java
/** /**
* 使用table去写入 * 使用table去写入
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 然后写入table即可 * <p>2. 然后写入table即可
*/ */
@Test @Test
public void tableWrite() { public void tableWrite() {
@ -764,8 +764,8 @@ public class WidthAndHeightData {
* <p> * <p>
* 思路是这样子的,先创建List<String>头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据 * 思路是这样子的,先创建List<String>头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据
* *
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 然后写入table即可 * <p>2. 然后写入table即可
*/ */
@Test @Test
public void dynamicHeadWrite() { public void dynamicHeadWrite() {
@ -818,9 +818,9 @@ public class LongestMatchColumnWidthData {
* <p> * <p>
* poi 自带{@link SXSSFSheet#autoSizeColumn(int)} 对中文支持也不太好。目前没找到很好的算法。 有的话可以推荐下。 * poi 自带{@link SXSSFSheet#autoSizeColumn(int)} 对中文支持也不太好。目前没找到很好的算法。 有的话可以推荐下。
* *
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 注册策略{@link LongestMatchColumnWidthStyleStrategy} * <p>3. 注册策略{@link LongestMatchColumnWidthStyleStrategy}
* <li>2. 直接写即可 * <p>2. 直接写即可
*/ */
@Test @Test
public void longestMatchColumnWidthWrite() { public void longestMatchColumnWidthWrite() {
@ -852,9 +852,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java ```java
/** /**
* 文件下载 * 文件下载
* <li>1. 创建excel对应的实体对象 参照{@link DownloadData} * <p>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <li>2. 设置返回的 参数 * <p>2. 设置返回的 参数
* <li>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大 * <p>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
*/ */
@GetMapping("download") @GetMapping("download")
public void download(HttpServletResponse response) throws IOException { public void download(HttpServletResponse response) throws IOException {

97
src/main/java/com/alibaba/excel/EasyExcelFactory.java

@ -136,6 +136,8 @@ public class EasyExcelFactory {
* the java OutputStream you wish to write the value to * the java OutputStream you wish to write the value to
* @param typeEnum * @param typeEnum
* 03 or 07 * 03 or 07
* @param needHead
* Whether a write header is required
* @return new ExcelWriter * @return new ExcelWriter
* @deprecated please use {@link EasyExcel#write()} * @deprecated please use {@link EasyExcel#write()}
*/ */
@ -157,6 +159,7 @@ public class EasyExcelFactory {
* @param typeEnum * @param typeEnum
* 03 or 07 * 03 or 07
* @param needHead * @param needHead
* Whether a write header is required
* @param handler * @param handler
* User-defined callback * User-defined callback
* @return new ExcelWriter * @return new ExcelWriter
@ -182,7 +185,8 @@ public class EasyExcelFactory {
* Build excel the write * Build excel the write
* *
* @param file * @param file
* @return * File to write
* @return Excel writer builder
*/ */
public static ExcelWriterBuilder write(File file) { public static ExcelWriterBuilder write(File file) {
return write(file, null); return write(file, null);
@ -192,8 +196,10 @@ public class EasyExcelFactory {
* Build excel the write * Build excel the write
* *
* @param file * @param file
* File to write
* @param head * @param head
* @return * Annotate the class for configuration information
* @return Excel writer builder
*/ */
public static ExcelWriterBuilder write(File file, Class head) { public static ExcelWriterBuilder write(File file, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder(); ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
@ -208,7 +214,8 @@ public class EasyExcelFactory {
* Build excel the write * Build excel the write
* *
* @param pathName * @param pathName
* @return * File path to write
* @return Excel writer builder
*/ */
public static ExcelWriterBuilder write(String pathName) { public static ExcelWriterBuilder write(String pathName) {
return write(pathName, null); return write(pathName, null);
@ -218,8 +225,10 @@ public class EasyExcelFactory {
* Build excel the write * Build excel the write
* *
* @param pathName * @param pathName
* File path to write
* @param head * @param head
* @return * Annotate the class for configuration information
* @return Excel writer builder
*/ */
public static ExcelWriterBuilder write(String pathName, Class head) { public static ExcelWriterBuilder write(String pathName, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder(); ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
@ -234,7 +243,8 @@ public class EasyExcelFactory {
* Build excel the write * Build excel the write
* *
* @param outputStream * @param outputStream
* @return * Output stream to write
* @return Excel writer builder
*/ */
public static ExcelWriterBuilder write(OutputStream outputStream) { public static ExcelWriterBuilder write(OutputStream outputStream) {
return write(outputStream, null); return write(outputStream, null);
@ -244,8 +254,10 @@ public class EasyExcelFactory {
* Build excel the write * Build excel the write
* *
* @param outputStream * @param outputStream
* Output stream to write
* @param head * @param head
* @return * Annotate the class for configuration information.
* @return Excel writer builder
*/ */
public static ExcelWriterBuilder write(OutputStream outputStream, Class head) { public static ExcelWriterBuilder write(OutputStream outputStream, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder(); ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
@ -257,19 +269,20 @@ public class EasyExcelFactory {
} }
/** /**
* Build excel the 'writerSheet' * Build excel the <code>writerSheet</code>
* *
* @return * @return Excel sheet writer builder
*/ */
public static ExcelWriterSheetBuilder writerSheet() { public static ExcelWriterSheetBuilder writerSheet() {
return writerSheet(null, null); return writerSheet(null, null);
} }
/** /**
* Build excel the 'writerSheet' * Build excel the <code>writerSheet</code>
* *
* @param sheetNo * @param sheetNo
* @return * Index of sheet,0 base.
* @return Excel sheet writer builder.
*/ */
public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo) { public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo) {
return writerSheet(sheetNo, null); return writerSheet(sheetNo, null);
@ -279,7 +292,8 @@ public class EasyExcelFactory {
* Build excel the 'writerSheet' * Build excel the 'writerSheet'
* *
* @param sheetName * @param sheetName
* @return * The name of sheet.
* @return Excel sheet writer builder.
*/ */
public static ExcelWriterSheetBuilder writerSheet(String sheetName) { public static ExcelWriterSheetBuilder writerSheet(String sheetName) {
return writerSheet(null, sheetName); return writerSheet(null, sheetName);
@ -289,8 +303,10 @@ public class EasyExcelFactory {
* Build excel the 'writerSheet' * Build excel the 'writerSheet'
* *
* @param sheetNo * @param sheetNo
* Index of sheet,0 base.
* @param sheetName * @param sheetName
* @return * The name of sheet.
* @return Excel sheet writer builder.
*/ */
public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo, String sheetName) { public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo, String sheetName) {
ExcelWriterSheetBuilder excelWriterSheetBuilder = new ExcelWriterSheetBuilder(); ExcelWriterSheetBuilder excelWriterSheetBuilder = new ExcelWriterSheetBuilder();
@ -304,9 +320,9 @@ public class EasyExcelFactory {
} }
/** /**
* Build excel the 'writerTable' * Build excel the <code>writerTable</code>
* *
* @return * @return Excel table writer builder.
*/ */
public static ExcelWriterTableBuilder writerTable() { public static ExcelWriterTableBuilder writerTable() {
return writerTable(null); return writerTable(null);
@ -316,7 +332,8 @@ public class EasyExcelFactory {
* Build excel the 'writerTable' * Build excel the 'writerTable'
* *
* @param tableNo * @param tableNo
* @return * Index of table,0 base.
* @return Excel table writer builder.
*/ */
public static ExcelWriterTableBuilder writerTable(Integer tableNo) { public static ExcelWriterTableBuilder writerTable(Integer tableNo) {
ExcelWriterTableBuilder excelWriterTableBuilder = new ExcelWriterTableBuilder(); ExcelWriterTableBuilder excelWriterTableBuilder = new ExcelWriterTableBuilder();
@ -329,7 +346,7 @@ public class EasyExcelFactory {
/** /**
* Build excel the read * Build excel the read
* *
* @return * @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read() { public static ExcelReaderBuilder read() {
return new ExcelReaderBuilder(); return new ExcelReaderBuilder();
@ -339,7 +356,8 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param file * @param file
* @return * File to read.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(File file) { public static ExcelReaderBuilder read(File file) {
return read(file, null, null); return read(file, null, null);
@ -349,8 +367,10 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param file * @param file
* File to read.
* @param readListener * @param readListener
* @return * Read listener.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(File file, ReadListener readListener) { public static ExcelReaderBuilder read(File file, ReadListener readListener) {
return read(file, null, readListener); return read(file, null, readListener);
@ -360,9 +380,12 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param file * @param file
* File to read.
* @param head * @param head
* Annotate the class for configuration information.
* @param readListener * @param readListener
* @return * Read listener.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(File file, Class head, ReadListener readListener) { public static ExcelReaderBuilder read(File file, Class head, ReadListener readListener) {
ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
@ -380,7 +403,8 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param pathName * @param pathName
* @return * File path to read.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(String pathName) { public static ExcelReaderBuilder read(String pathName) {
return read(pathName, null, null); return read(pathName, null, null);
@ -390,8 +414,10 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param pathName * @param pathName
* File path to read.
* @param readListener * @param readListener
* @return * Read listener.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(String pathName, ReadListener readListener) { public static ExcelReaderBuilder read(String pathName, ReadListener readListener) {
return read(pathName, null, readListener); return read(pathName, null, readListener);
@ -401,9 +427,12 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param pathName * @param pathName
* File path to read.
* @param head * @param head
* Annotate the class for configuration information.
* @param readListener * @param readListener
* @return * Read listener.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) { public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) {
ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
@ -421,7 +450,8 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param inputStream * @param inputStream
* @return * Input stream to read.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(InputStream inputStream) { public static ExcelReaderBuilder read(InputStream inputStream) {
return read(inputStream, null, null); return read(inputStream, null, null);
@ -431,8 +461,10 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param inputStream * @param inputStream
* Input stream to read.
* @param readListener * @param readListener
* @return * Read listener.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(InputStream inputStream, ReadListener readListener) { public static ExcelReaderBuilder read(InputStream inputStream, ReadListener readListener) {
return read(inputStream, null, readListener); return read(inputStream, null, readListener);
@ -442,9 +474,12 @@ public class EasyExcelFactory {
* Build excel the read * Build excel the read
* *
* @param inputStream * @param inputStream
* Input stream to read.
* @param head * @param head
* Annotate the class for configuration information.
* @param readListener * @param readListener
* @return * Read listener.
* @return Excel reader builder.
*/ */
public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) { public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) {
ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder(); ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
@ -461,7 +496,7 @@ public class EasyExcelFactory {
/** /**
* Build excel the 'readSheet' * Build excel the 'readSheet'
* *
* @return * @return Excel sheet reader builder.
*/ */
public static ExcelReaderSheetBuilder readSheet() { public static ExcelReaderSheetBuilder readSheet() {
return readSheet(null, null); return readSheet(null, null);
@ -471,7 +506,8 @@ public class EasyExcelFactory {
* Build excel the 'readSheet' * Build excel the 'readSheet'
* *
* @param sheetNo * @param sheetNo
* @return * Index of sheet,0 base.
* @return Excel sheet reader builder.
*/ */
public static ExcelReaderSheetBuilder readSheet(Integer sheetNo) { public static ExcelReaderSheetBuilder readSheet(Integer sheetNo) {
return readSheet(sheetNo, null); return readSheet(sheetNo, null);
@ -481,7 +517,8 @@ public class EasyExcelFactory {
* Build excel the 'readSheet' * Build excel the 'readSheet'
* *
* @param sheetName * @param sheetName
* @return * The name of sheet.
* @return Excel sheet reader builder.
*/ */
public static ExcelReaderSheetBuilder readSheet(String sheetName) { public static ExcelReaderSheetBuilder readSheet(String sheetName) {
return readSheet(null, sheetName); return readSheet(null, sheetName);
@ -491,8 +528,10 @@ public class EasyExcelFactory {
* Build excel the 'readSheet' * Build excel the 'readSheet'
* *
* @param sheetNo * @param sheetNo
* Index of sheet,0 base.
* @param sheetName * @param sheetName
* @return * The name of sheet.
* @return Excel sheet reader builder.
*/ */
public static ExcelReaderSheetBuilder readSheet(Integer sheetNo, String sheetName) { public static ExcelReaderSheetBuilder readSheet(Integer sheetNo, String sheetName) {
ExcelReaderSheetBuilder excelReaderSheetBuilder = new ExcelReaderSheetBuilder(); ExcelReaderSheetBuilder excelReaderSheetBuilder = new ExcelReaderSheetBuilder();

1
src/main/java/com/alibaba/excel/ExcelReader.java

@ -276,7 +276,6 @@ public class ExcelReader {
/** /**
* Prevents calls to {@link #finish} from freeing the cache * Prevents calls to {@link #finish} from freeing the cache
* *
* @throws Throwable
*/ */
@Override @Override
protected void finalize() { protected void finalize() {

3
src/main/java/com/alibaba/excel/analysis/ExcelAnalyser.java

@ -13,6 +13,7 @@ public interface ExcelAnalyser {
* parse one sheet * parse one sheet
* *
* @param readSheet * @param readSheet
* sheet to read
*/ */
void analysis(ReadSheet readSheet); void analysis(ReadSheet readSheet);
@ -24,7 +25,7 @@ public interface ExcelAnalyser {
/** /**
* Acquisition excel executor * Acquisition excel executor
* *
* @return * @return Excel file Executor
*/ */
ExcelExecutor excelExecutor(); ExcelExecutor excelExecutor();

2
src/main/java/com/alibaba/excel/analysis/ExcelExecutor.java

@ -14,7 +14,7 @@ public interface ExcelExecutor {
/** /**
* Returns the actual sheet in excel * Returns the actual sheet in excel
* *
* @return * @return Actual sheet in excel
*/ */
List<ReadSheet> sheetList(); List<ReadSheet> sheetList();

11
src/main/java/com/alibaba/excel/analysis/v03/XlsRecordHandler.java

@ -14,7 +14,8 @@ public interface XlsRecordHandler extends Comparable<XlsRecordHandler> {
* Which tags are supported * Which tags are supported
* *
* @param record * @param record
* @return * Excel analysis record
* @return Which tags are supported
*/ */
boolean support(Record record); boolean support(Record record);
@ -33,28 +34,28 @@ public interface XlsRecordHandler extends Comparable<XlsRecordHandler> {
/** /**
* Get row * Get row
* *
* @return * @return Row index
*/ */
int getRow(); int getRow();
/** /**
* Get column * Get column
* *
* @return * @return Column index
*/ */
int getColumn(); int getColumn();
/** /**
* Get value * Get value
* *
* @return * @return Excel internal cell data
*/ */
CellData getCellData(); CellData getCellData();
/** /**
* Get order * Get order
* *
* @return * @return Order
*/ */
int getOrder(); int getOrder();
} }

6
src/main/java/com/alibaba/excel/analysis/v07/XlsxCellHandler.java

@ -12,7 +12,8 @@ public interface XlsxCellHandler {
* Which tags are supported * Which tags are supported
* *
* @param name * @param name
* @return * Tag name
* @return Support parsing or not
*/ */
boolean support(String name); boolean support(String name);
@ -20,7 +21,9 @@ public interface XlsxCellHandler {
* Start handle * Start handle
* *
* @param name * @param name
* Tag name
* @param attributes * @param attributes
* Tag attributes
*/ */
void startHandle(String name, Attributes attributes); void startHandle(String name, Attributes attributes);
@ -28,6 +31,7 @@ public interface XlsxCellHandler {
* End handle * End handle
* *
* @param name * @param name
* Tag name
*/ */
void endHandle(String name); void endHandle(String name);
} }

14
src/main/java/com/alibaba/excel/annotation/ExcelProperty.java

@ -20,10 +20,12 @@ public @interface ExcelProperty {
/** /**
* The name of the sheet header. * The name of the sheet header.
* *
* <li>write: It automatically merges when you have more than one head * <p>
* <li>read: When you have multiple heads, take the first one * write: It automatically merges when you have more than one head
* <p>
* read: When you have multiple heads, take the first one
* *
* @return * @return The name of the sheet header
*/ */
String[] value() default {""}; String[] value() default {""};
@ -32,14 +34,14 @@ public @interface ExcelProperty {
* *
* Read or write it on the index of column,If it's equal to -1, it's sorted by Java class * Read or write it on the index of column,If it's equal to -1, it's sorted by Java class
* *
* @return * @return Index of column
*/ */
int index() default -1; int index() default -1;
/** /**
* Force the current field to use this converter. * Force the current field to use this converter.
* *
* @return * @return Converter
*/ */
Class<? extends Converter> converter() default AutoConverter.class; Class<? extends Converter> converter() default AutoConverter.class;
@ -47,7 +49,7 @@ public @interface ExcelProperty {
* *
* default @see com.alibaba.excel.util.TypeUtil if default is not meet you can set format * default @see com.alibaba.excel.util.TypeUtil if default is not meet you can set format
* *
* @return * @return Format string
* @deprecated please use {@link com.alibaba.excel.annotation.format.DateTimeFormat} * @deprecated please use {@link com.alibaba.excel.annotation.format.DateTimeFormat}
*/ */
@Deprecated @Deprecated

12
src/main/java/com/alibaba/excel/annotation/format/DateTimeFormat.java

@ -9,8 +9,10 @@ import java.lang.annotation.Target;
/** /**
* Convert date format. * Convert date format.
* *
* <li>write: It can be used on classes {@link java.util.Date} * <p>
* <li>read: It can be used on classes {@link String} * write: It can be used on classes {@link java.util.Date}
* <p>
* read: It can be used on classes {@link String}
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -23,14 +25,14 @@ public @interface DateTimeFormat {
* *
* Specific format reference {@link java.text.SimpleDateFormat} * Specific format reference {@link java.text.SimpleDateFormat}
* *
* @return * @return Format pattern
*/ */
String value() default ""; String value() default "";
/** /**
* true if date uses 1904 windowing, or false if using 1900 date windowing. * True if date uses 1904 windowing, or false if using 1900 date windowing.
* *
* @return * @return True if date uses 1904 windowing, or false if using 1900 date windowing.
*/ */
boolean use1904windowing() default false; boolean use1904windowing() default false;
} }

10
src/main/java/com/alibaba/excel/annotation/format/NumberFormat.java

@ -10,8 +10,10 @@ import java.math.RoundingMode;
/** /**
* Convert number format. * Convert number format.
* *
* <li>write: It can be used on classes that inherit {@link Number} * <p>
* <li>read: It can be used on classes {@link String} * write: It can be used on classes that inherit {@link Number}
* <p>
* read: It can be used on classes {@link String}
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */
@ -24,14 +26,14 @@ public @interface NumberFormat {
* *
* Specific format reference {@link org.apache.commons.math3.fraction.BigFractionFormat} * Specific format reference {@link org.apache.commons.math3.fraction.BigFractionFormat}
* *
* @return * @return Format pattern
*/ */
String value() default ""; String value() default "";
/** /**
* Rounded by default * Rounded by default
* *
* @return * @return RoundingMode
*/ */
RoundingMode roundingMode() default RoundingMode.HALF_UP; RoundingMode roundingMode() default RoundingMode.HALF_UP;
} }

2
src/main/java/com/alibaba/excel/annotation/write/style/ColumnWidth.java

@ -20,6 +20,8 @@ public @interface ColumnWidth {
* Column width * Column width
* <p> * <p>
* -1 means the default column width is used * -1 means the default column width is used
*
* @return Column width
*/ */
int value() default -1; int value() default -1;
} }

2
src/main/java/com/alibaba/excel/annotation/write/style/ContentRowHeight.java

@ -21,7 +21,7 @@ public @interface ContentRowHeight {
* <p> * <p>
* -1 mean the auto set height * -1 mean the auto set height
* *
* @return * @return Content height
*/ */
short value() default -1; short value() default -1;
} }

2
src/main/java/com/alibaba/excel/annotation/write/style/HeadRowHeight.java

@ -20,7 +20,7 @@ public @interface HeadRowHeight {
* <p> * <p>
* -1 mean the auto set height * -1 mean the auto set height
* *
* @return * @return Header height
*/ */
short value() default -1; short value() default -1;
} }

5
src/main/java/com/alibaba/excel/cache/ReadCache.java vendored

@ -13,6 +13,7 @@ public interface ReadCache {
* Initialize cache * Initialize cache
* *
* @param analysisContext * @param analysisContext
* A context is the main anchorage point of a excel reader.
*/ */
void init(AnalysisContext analysisContext); void init(AnalysisContext analysisContext);
@ -20,6 +21,7 @@ public interface ReadCache {
* Automatically generate the key and put it in the cache.Key start from 0 * Automatically generate the key and put it in the cache.Key start from 0
* *
* @param value * @param value
* Cache value
*/ */
void put(String value); void put(String value);
@ -27,7 +29,8 @@ public interface ReadCache {
* Get value * Get value
* *
* @param key * @param key
* @return * Index
* @return Value
*/ */
String get(Integer key); String get(Integer key);

13
src/main/java/com/alibaba/excel/context/AnalysisContext.java

@ -23,21 +23,23 @@ public interface AnalysisContext {
* Select the current table * Select the current table
* *
* @param excelExecutor * @param excelExecutor
* Excel file Executor
* @param readSheet * @param readSheet
* sheet to read
*/ */
void currentSheet(ExcelExecutor excelExecutor, ReadSheet readSheet); void currentSheet(ExcelExecutor excelExecutor, ReadSheet readSheet);
/** /**
* All information about the workbook you are currently working on * All information about the workbook you are currently working on
* *
* @return * @return Current workbook holder
*/ */
ReadWorkbookHolder readWorkbookHolder(); ReadWorkbookHolder readWorkbookHolder();
/** /**
* All information about the sheet you are currently working on * All information about the sheet you are currently working on
* *
* @return * @return Current sheet holder
*/ */
ReadSheetHolder readSheetHolder(); ReadSheetHolder readSheetHolder();
@ -45,20 +47,21 @@ public interface AnalysisContext {
* Set row of currently operated cell * Set row of currently operated cell
* *
* @param readRowHolder * @param readRowHolder
* Current row holder
*/ */
void readRowHolder(ReadRowHolder readRowHolder); void readRowHolder(ReadRowHolder readRowHolder);
/** /**
* Row of currently operated cell * Row of currently operated cell
* *
* @return * @return Current row holder
*/ */
ReadRowHolder readRowHolder(); ReadRowHolder readRowHolder();
/** /**
* The current read operation corresponds to the 'readSheetHolder' or 'readWorkbookHolder' * The current read operation corresponds to the <code>readSheetHolder</code> or <code>readWorkbookHolder</code>
* *
* @return * @return Current holder
*/ */
ReadHolder currentReadHolder(); ReadHolder currentReadHolder();

22
src/main/java/com/alibaba/excel/converters/Converter.java

@ -16,14 +16,14 @@ public interface Converter<T> {
/** /**
* Back to object types in Java * Back to object types in Java
* *
* @return * @return Support for Java class
*/ */
Class supportJavaTypeKey(); Class supportJavaTypeKey();
/** /**
* Back to object enum in excel * Back to object enum in excel
* *
* @return * @return Support for {@link CellDataTypeEnum}
*/ */
CellDataTypeEnum supportExcelTypeKey(); CellDataTypeEnum supportExcelTypeKey();
@ -31,13 +31,14 @@ public interface Converter<T> {
* Convert excel objects to Java objects * Convert excel objects to Java objects
* *
* @param cellData * @param cellData
* NotNull * Excel cell data.NotNull.
* @param contentProperty * @param contentProperty
* Nullable * Content property.Nullable.
* @param globalConfiguration * @param globalConfiguration
* NotNull * Global configuration.NotNull.
* @return * @return Data to put into a Java object
* @throws Exception * @throws Exception
* Exception.
*/ */
T convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, T convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws Exception; GlobalConfiguration globalConfiguration) throws Exception;
@ -46,13 +47,14 @@ public interface Converter<T> {
* Convert Java objects to excel objects * Convert Java objects to excel objects
* *
* @param value * @param value
* NotNull * Java Data.NotNull.
* @param contentProperty * @param contentProperty
* Nullable * Content property.Nullable.
* @param globalConfiguration * @param globalConfiguration
* NotNull * Global configuration.NotNull.
* @return * @return Data to put into a Excel
* @throws Exception * @throws Exception
* Exception.
*/ */
CellData convertToExcelData(T value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) CellData convertToExcelData(T value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration)
throws Exception; throws Exception;

2
src/main/java/com/alibaba/excel/event/WriteHandler.java

@ -7,7 +7,7 @@ import org.apache.poi.ss.usermodel.Sheet;
/** /**
* *
* @author jipengfei * @author jipengfei
* @deprecated please use {@ com.alibaba.excel.write.handler.WriteHandler} * @deprecated please use {@link com.alibaba.excel.write.handler.WriteHandler}
*/ */
@Deprecated @Deprecated
public interface WriteHandler { public interface WriteHandler {

3
src/main/java/com/alibaba/excel/exception/ExcelAnalysisException.java

@ -6,8 +6,7 @@ package com.alibaba.excel.exception;
*/ */
public class ExcelAnalysisException extends RuntimeException { public class ExcelAnalysisException extends RuntimeException {
public ExcelAnalysisException() { public ExcelAnalysisException() {}
}
public ExcelAnalysisException(String message) { public ExcelAnalysisException(String message) {
super(message); super(message);

1
src/main/java/com/alibaba/excel/exception/ExcelGenerateException.java

@ -5,7 +5,6 @@ package com.alibaba.excel.exception;
*/ */
public class ExcelGenerateException extends RuntimeException { public class ExcelGenerateException extends RuntimeException {
public ExcelGenerateException(String message) { public ExcelGenerateException(String message) {
super(message); super(message);
} }

6
src/main/java/com/alibaba/excel/metadata/AbstractHolder.java

@ -29,8 +29,10 @@ public abstract class AbstractHolder implements ConfigurationHolder {
private GlobalConfiguration globalConfiguration; private GlobalConfiguration globalConfiguration;
/** /**
* <li>Read key: * <p>
* <li>Write key: * Read key:
* <p>
* Write key:
*/ */
private Map<String, Converter> converterMap; private Map<String, Converter> converterMap;

2
src/main/java/com/alibaba/excel/metadata/CellData.java

@ -3,7 +3,7 @@ package com.alibaba.excel.metadata;
import com.alibaba.excel.enums.CellDataTypeEnum; import com.alibaba.excel.enums.CellDataTypeEnum;
/** /**
* excel internal cell data * Excel internal cell data
* *
* @author Jiaju Zhuang * @author Jiaju Zhuang
*/ */

6
src/main/java/com/alibaba/excel/metadata/ConfigurationHolder.java

@ -16,21 +16,21 @@ public interface ConfigurationHolder extends Holder {
* *
* Record whether it's new or from cache * Record whether it's new or from cache
* *
* @return * @return Record whether it's new or from cache
*/ */
boolean isNew(); boolean isNew();
/** /**
* Some global variables * Some global variables
* *
* @return * @return Global configuration
*/ */
GlobalConfiguration globalConfiguration(); GlobalConfiguration globalConfiguration();
/** /**
* What converter does the currently operated cell need to execute * What converter does the currently operated cell need to execute
* *
* @return * @return Converter
*/ */
Map<String, Converter> converterMap(); Map<String, Converter> converterMap();
} }

2
src/main/java/com/alibaba/excel/metadata/Holder.java

@ -13,7 +13,7 @@ public interface Holder {
/** /**
* What holder is the return * What holder is the return
* *
* @return * @return Holder enum.
*/ */
HolderEnum holderType(); HolderEnum holderType();

13
src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java

@ -63,10 +63,10 @@ public class ExcelReaderBuilder {
return file(new File(pathName)); return file(new File(pathName));
} }
/** /**
* Mandatory use 'inputStream' .Default is false. * Mandatory use 'inputStream' .Default is false.
* <li>if false,Will transfer 'inputStream' to temporary files to improve efficiency * <p>
* if false,Will transfer 'inputStream' to temporary files to improve efficiency
*/ */
public ExcelReaderBuilder mandatoryUseInputStream(Boolean mandatoryUseInputStream) { public ExcelReaderBuilder mandatoryUseInputStream(Boolean mandatoryUseInputStream) {
readWorkbook.setMandatoryUseInputStream(mandatoryUseInputStream); readWorkbook.setMandatoryUseInputStream(mandatoryUseInputStream);
@ -110,9 +110,12 @@ public class ExcelReaderBuilder {
/** /**
* Count the number of added heads when read sheet. * Count the number of added heads when read sheet.
* *
* <li>0 - This Sheet has no head ,since the first row are the data * <p>
* <li>1 - This Sheet has one row head , this is the default * 0 - This Sheet has no head ,since the first row are the data
* <li>2 - This Sheet has two row head ,since the third row is the data * <p>
* 1 - This Sheet has one row head , this is the default
* <p>
* 2 - This Sheet has two row head ,since the third row is the data
* *
* @param headRowNumber * @param headRowNumber
* @return * @return

11
src/main/java/com/alibaba/excel/read/builder/ExcelReaderSheetBuilder.java

@ -57,9 +57,12 @@ public class ExcelReaderSheetBuilder {
/** /**
* Count the number of added heads when read sheet. * Count the number of added heads when read sheet.
* *
* <li>0 - This Sheet has no head ,since the first row are the data * <p>
* <li>1 - This Sheet has one row head , this is the default * 0 - This Sheet has no head ,since the first row are the data
* <li>2 - This Sheet has two row head ,since the third row is the data * <p>
* 1 - This Sheet has one row head , this is the default
* <p>
* 2 - This Sheet has two row head ,since the third row is the data
* *
* @param headRowNumber * @param headRowNumber
* @return * @return
@ -149,8 +152,6 @@ public class ExcelReaderSheetBuilder {
/** /**
* Sax read * Sax read
*
* @return
*/ */
public void doRead() { public void doRead() {
if (excelReader == null) { if (excelReader == null) {

3
src/main/java/com/alibaba/excel/read/listener/ReadListenerRegistryCenter.java

@ -15,6 +15,7 @@ public interface ReadListenerRegistryCenter {
* register * register
* *
* @param listener * @param listener
* Analysis listener
*/ */
void register(AnalysisEventListener listener); void register(AnalysisEventListener listener);
@ -24,6 +25,7 @@ public interface ReadListenerRegistryCenter {
* @param event * @param event
* parse event * parse event
* @param analysisContext * @param analysisContext
* Analysis context
*/ */
void notifyEndOneRow(AnalysisFinishEvent event, AnalysisContext analysisContext); void notifyEndOneRow(AnalysisFinishEvent event, AnalysisContext analysisContext);
@ -31,6 +33,7 @@ public interface ReadListenerRegistryCenter {
* Notify after all analysed * Notify after all analysed
* *
* @param analysisContext * @param analysisContext
* Analysis context
*/ */
void notifyAfterAllAnalysed(AnalysisContext analysisContext); void notifyAfterAllAnalysed(AnalysisContext analysisContext);
} }

9
src/main/java/com/alibaba/excel/read/metadata/ReadBasicParameter.java

@ -15,9 +15,12 @@ public class ReadBasicParameter extends BasicParameter {
/** /**
* Count the number of added heads when read sheet. * Count the number of added heads when read sheet.
* *
* <li>0 - This Sheet has no head ,since the first row are the data * <p>
* <li>1 - This Sheet has one row head , this is the default * 0 - This Sheet has no head ,since the first row are the data
* <li>2 - This Sheet has two row head ,since the third row is the data * <p>
* 1 - This Sheet has one row head , this is the default
* <p>
* 2 - This Sheet has two row head ,since the third row is the data
*/ */
private Integer headRowNumber; private Integer headRowNumber;
/** /**

9
src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java

@ -32,7 +32,8 @@ public class ReadWorkbook extends ReadBasicParameter {
private File file; private File file;
/** /**
* Mandatory use 'inputStream' .Default is false. * Mandatory use 'inputStream' .Default is false.
* <li>if false,Will transfer 'inputStream' to temporary files to improve efficiency * <p>
* if false,Will transfer 'inputStream' to temporary files to improve efficiency
*/ */
private Boolean mandatoryUseInputStream; private Boolean mandatoryUseInputStream;
/** /**
@ -51,8 +52,10 @@ public class ReadWorkbook extends ReadBasicParameter {
private ReadCache readCache; private ReadCache readCache;
/** /**
* The default is all excel objects.Default is true. * The default is all excel objects.Default is true.
* <li>if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field. * <p>
* <li>if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed. * if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field.
* <p>
* if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
* *
* @deprecated Just to be compatible with historical data, The default is always going to be convert all filed. * @deprecated Just to be compatible with historical data, The default is always going to be convert all filed.
*/ */

9
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java

@ -37,9 +37,12 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
/** /**
* Count the number of added heads when read sheet. * Count the number of added heads when read sheet.
* *
* <li>0 - This Sheet has no head ,since the first row are the data * <p>
* <li>1 - This Sheet has one row head , this is the default * 0 - This Sheet has no head ,since the first row are the data
* <li>2 - This Sheet has two row head ,since the third row is the data * <p>
* 1 - This Sheet has one row head , this is the default
* <p>
* 2 - This Sheet has two row head ,since the third row is the data
*/ */
private Integer headRowNumber; private Integer headRowNumber;
/** /**

6
src/main/java/com/alibaba/excel/read/metadata/holder/ReadHolder.java

@ -16,14 +16,14 @@ public interface ReadHolder extends ConfigurationHolder {
/** /**
* What handler does the currently operated cell need to execute * What handler does the currently operated cell need to execute
* *
* @return * @return Current {@link ReadListener}
*/ */
List<ReadListener> readListenerList(); List<ReadListener> readListenerList();
/** /**
* What 'ExcelReadHeadProperty' does the currently operated cell need to execute * What {@link ExcelReadHeadProperty} does the currently operated cell need to execute
* *
* @return * @return Current {@link ExcelReadHeadProperty}
*/ */
ExcelReadHeadProperty excelReadHeadProperty(); ExcelReadHeadProperty excelReadHeadProperty();

3
src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java

@ -43,7 +43,8 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
private File file; private File file;
/** /**
* Mandatory use 'inputStream' .Default is false. * Mandatory use 'inputStream' .Default is false.
* <li>if false,Will transfer 'inputStream' to temporary files to improve efficiency * <p>
* if false,Will transfer 'inputStream' to temporary files to improve efficiency
*/ */
private Boolean mandatoryUseInputStream; private Boolean mandatoryUseInputStream;
/** /**

2
src/main/java/com/alibaba/excel/util/BooleanUtils.java

@ -13,8 +13,6 @@ public class BooleanUtils {
/** /**
* String to boolean * String to boolean
* *
* <li>
*
* @param str * @param str
* @return * @return
*/ */

4
src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java

@ -23,8 +23,8 @@ public abstract class AbstractMergeStrategy implements CellWriteHandler {
} }
@Override @Override
public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData, Cell cell, public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, CellData cellData,
Head head, int relativeRowIndex, boolean isHead) { Cell cell, Head head, int relativeRowIndex, boolean isHead) {
if (isHead) { if (isHead) {
return; return;
} }

6
src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java

@ -52,8 +52,10 @@ public class WriteWorkbook extends WriteBasicParameter {
private Boolean mandatoryUseInputStream; private Boolean mandatoryUseInputStream;
/** /**
* The default is all excel objects.Default is true. * The default is all excel objects.Default is true.
* <li>if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field. * <p>
* <li>if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed. * if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field.
* <p>
* if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
* *
* @deprecated Just to be compatible with historical data, The default is always going to be convert all filed. * @deprecated Just to be compatible with historical data, The default is always going to be convert all filed.
*/ */

3
src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java

@ -25,7 +25,8 @@ public class HorizontalCellStyleStrategy extends AbstractCellStyleStrategy {
private CellStyle headCellStyle; private CellStyle headCellStyle;
private List<CellStyle> contentCellStyleList; private List<CellStyle> contentCellStyleList;
public HorizontalCellStyleStrategy(WriteCellStyle headWriteCellStyle, List<WriteCellStyle> contentWriteCellStyleList) { public HorizontalCellStyleStrategy(WriteCellStyle headWriteCellStyle,
List<WriteCellStyle> contentWriteCellStyleList) {
this.headWriteCellStyle = headWriteCellStyle; this.headWriteCellStyle = headWriteCellStyle;
this.contentWriteCellStyleList = contentWriteCellStyleList; this.contentWriteCellStyleList = contentWriteCellStyleList;
} }

3
src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java

@ -28,7 +28,8 @@ public abstract class AbstractHeadColumnWidthStyleStrategy extends AbstractColum
/** /**
* Returns the column width corresponding to each column head. * Returns the column width corresponding to each column head.
* *
* <li>if return null,ignore * <p>
* if return null,ignore
* *
* @param head * @param head
* Nullable * Nullable

3
src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataTest.java

@ -42,8 +42,7 @@ public class ExceptionDataTest {
private void readAndWrite(File file) throws Exception { private void readAndWrite(File file) throws Exception {
EasyExcel.write(new FileOutputStream(file), ExceptionData.class).sheet().doWrite(data()); EasyExcel.write(new FileOutputStream(file), ExceptionData.class).sheet().doWrite(data());
EasyExcel.read(new FileInputStream(file), ExceptionData.class, new ExceptionDataListener()).sheet() EasyExcel.read(new FileInputStream(file), ExceptionData.class, new ExceptionDataListener()).sheet().doRead();
.doRead();
} }
private List<ExceptionData> data() { private List<ExceptionData> data() {

27
src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java

@ -47,8 +47,8 @@ public class ParameterDataTest {
private void readAndWrite1() { private void readAndWrite1() {
EasyExcel.write(file.getPath()).head(ParameterData.class).sheet().doWrite(data()); EasyExcel.write(file.getPath()).head(ParameterData.class).sheet().doWrite(data());
EasyExcel.read(file.getPath()).head(ParameterData.class) EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener())
.registerReadListener(new ParameterDataListener()).sheet().doRead(); .sheet().doRead();
} }
private void readAndWrite2() { private void readAndWrite2() {
@ -58,8 +58,8 @@ public class ParameterDataTest {
private void readAndWrite3() throws Exception { private void readAndWrite3() throws Exception {
EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).sheet().doWrite(data()); EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).sheet().doWrite(data());
EasyExcel.read(file.getPath()).head(ParameterData.class) EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener())
.registerReadListener(new ParameterDataListener()).sheet().doRead(); .sheet().doRead();
} }
private void readAndWrite4() throws Exception { private void readAndWrite4() throws Exception {
@ -68,15 +68,14 @@ public class ParameterDataTest {
} }
private void readAndWrite5() throws Exception { private void readAndWrite5() throws Exception {
ExcelWriter excelWriter = EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class) ExcelWriter excelWriter =
.relativeHeadRowIndex(0).build(); EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).relativeHeadRowIndex(0).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build();
WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).needHead(Boolean.TRUE).build(); WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).needHead(Boolean.TRUE).build();
excelWriter.write(data(), writeSheet, writeTable); excelWriter.write(data(), writeSheet, writeTable);
excelWriter.finish(); excelWriter.finish();
ExcelReader excelReader = ExcelReader excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
.mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build(); .mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
ReadSheet readSheet = EasyExcel.readSheet().head(ParameterData.class).use1904windowing(Boolean.FALSE) ReadSheet readSheet = EasyExcel.readSheet().head(ParameterData.class).use1904windowing(Boolean.FALSE)
.headRowNumber(1).sheetNo(0).sheetName("0").build(); .headRowNumber(1).sheetNo(0).sheetName("0").build();
@ -90,16 +89,15 @@ public class ParameterDataTest {
} }
private void readAndWrite6() throws Exception { private void readAndWrite6() throws Exception {
ExcelWriter excelWriter = EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class) ExcelWriter excelWriter =
.relativeHeadRowIndex(0).build(); EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).relativeHeadRowIndex(0).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build();
WriteTable writeTable = EasyExcel.writerTable(0).registerConverter(new StringStringConverter()) WriteTable writeTable = EasyExcel.writerTable(0).registerConverter(new StringStringConverter())
.relativeHeadRowIndex(0).needHead(Boolean.TRUE).build(); .relativeHeadRowIndex(0).needHead(Boolean.TRUE).build();
excelWriter.write(data(), writeSheet, writeTable); excelWriter.write(data(), writeSheet, writeTable);
excelWriter.finish(); excelWriter.finish();
ExcelReader excelReader = ExcelReader excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
.mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build(); .mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
ReadSheet readSheet = EasyExcel.readSheet("0").head(ParameterData.class).use1904windowing(Boolean.FALSE) ReadSheet readSheet = EasyExcel.readSheet("0").head(ParameterData.class).use1904windowing(Boolean.FALSE)
.headRowNumber(1).sheetNo(0).build(); .headRowNumber(1).sheetNo(0).build();
@ -116,9 +114,8 @@ public class ParameterDataTest {
EasyExcel.write(file, ParameterData.class).registerConverter(new StringStringConverter()).sheet() EasyExcel.write(file, ParameterData.class).registerConverter(new StringStringConverter()).sheet()
.registerConverter(new StringStringConverter()).needHead(Boolean.FALSE).table(0).needHead(Boolean.TRUE) .registerConverter(new StringStringConverter()).needHead(Boolean.FALSE).table(0).needHead(Boolean.TRUE)
.doWrite(data()); .doWrite(data());
EasyExcel.read(file.getPath()).head(ParameterData.class) EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener())
.registerReadListener(new ParameterDataListener()).sheet().registerConverter(new StringStringConverter()) .sheet().registerConverter(new StringStringConverter()).doRead();
.doRead();
} }
private List<ParameterData> data() { private List<ParameterData> data() {

6
src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java

@ -51,8 +51,7 @@ public class RepetitionDataTest {
ExcelWriter excelWriter = EasyExcel.write(file, RepetitionData.class).build(); ExcelWriter excelWriter = EasyExcel.write(file, RepetitionData.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
excelWriter.write(data(), writeSheet).write(data(), writeSheet).finish(); excelWriter.write(data(), writeSheet).write(data(), writeSheet).finish();
ExcelReader excelReader = ExcelReader excelReader = EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
ReadSheet readSheet = EasyExcel.readSheet(0).build(); ReadSheet readSheet = EasyExcel.readSheet(0).build();
excelReader.read(readSheet).finish(); excelReader.read(readSheet).finish();
} }
@ -72,8 +71,7 @@ public class RepetitionDataTest {
WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).build(); WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).build();
excelWriter.write(data(), writeSheet, writeTable).write(data(), writeSheet, writeTable).finish(); excelWriter.write(data(), writeSheet, writeTable).write(data(), writeSheet, writeTable).finish();
ExcelReader excelReader = ExcelReader excelReader = EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
ReadSheet readSheet = EasyExcel.readSheet(0).headRowNumber(2).build(); ReadSheet readSheet = EasyExcel.readSheet(0).headRowNumber(2).build();
excelReader.read(readSheet).finish(); excelReader.read(readSheet).finish();
} }

45
src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java

@ -30,9 +30,12 @@ public class ReadTest {
/** /**
* 最简单的读 * 最简单的读
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener} * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 直接读即可 * <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <p>
* 3. 直接读即可
*/ */
@Test @Test
public void simpleRead() { public void simpleRead() {
@ -53,9 +56,12 @@ public class ReadTest {
/** /**
* 指定列的下标或者列名 * 指定列的下标或者列名
* *
* <li>1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData} * <p>
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link IndexOrNameDataListener} * 1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
* <li>3. 直接读即可 * <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link IndexOrNameDataListener}
* <p>
* 3. 直接读即可
*/ */
@Test @Test
public void indexOrNameRead() { public void indexOrNameRead() {
@ -66,9 +72,12 @@ public class ReadTest {
/** /**
* 读多个sheet,这里注意一个sheet不能读取多次多次读取需要重新读取文件 * 读多个sheet,这里注意一个sheet不能读取多次多次读取需要重新读取文件
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener} * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 直接读即可 * <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <p>
* 3. 直接读即可
*/ */
@Test @Test
public void repeatedRead() { public void repeatedRead() {
@ -86,9 +95,12 @@ public class ReadTest {
* 日期数字或者自定义格式转换 * 日期数字或者自定义格式转换
* <p> * <p>
* 默认读的转换器{@link DefaultConverterLoader#loadDefaultReadConverter()} * 默认读的转换器{@link DefaultConverterLoader#loadDefaultReadConverter()}
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解 * <p>
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link ConverterDataListener} * 1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解
* <li>3. 直接读即可 * <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link ConverterDataListener}
* <p>
* 3. 直接读即可
*/ */
@Test @Test
public void converterRead() { public void converterRead() {
@ -105,9 +117,12 @@ public class ReadTest {
/** /**
* 多行头 * 多行头
* *
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener} * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 设置headRowNumber参数然后读 这里要注意headRowNumber如果不指定 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数 * <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <p>
* 3. 设置headRowNumber参数然后读 这里要注意headRowNumber如果不指定 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数
* 如果不传入class则默认为1.当然你指定了headRowNumber不管是否传入class都是以你传入的为准 * 如果不传入class则默认为1.当然你指定了headRowNumber不管是否传入class都是以你传入的为准
*/ */
@Test @Test

18
src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java

@ -24,9 +24,12 @@ import com.alibaba.excel.EasyExcel;
public class WebTest { public class WebTest {
/** /**
* 文件下载 * 文件下载
* <li>1. 创建excel对应的实体对象 参照{@link DownloadData} * <p>
* <li>2. 设置返回的 参数 * 1. 创建excel对应的实体对象 参照{@link DownloadData}
* <li>3. 直接写这里注意finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大 * <p>
* 2. 设置返回的 参数
* <p>
* 3. 直接写这里注意finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
*/ */
@GetMapping("download") @GetMapping("download")
public void download(HttpServletResponse response) throws IOException { public void download(HttpServletResponse response) throws IOException {
@ -38,9 +41,12 @@ public class WebTest {
/** /**
* 文件上传 * 文件上传
* <li>1. 创建excel对应的实体对象 参照{@link UploadData} * <p>
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link UploadDataListener} * 1. 创建excel对应的实体对象 参照{@link UploadData}
* <li>3. 直接读即可 * <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link UploadDataListener}
* <p>
* 3. 直接读即可
*/ */
@PostMapping("upload") @PostMapping("upload")
@ResponseBody @ResponseBody

108
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -39,8 +39,10 @@ import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
public class WriteTest { public class WriteTest {
/** /**
* 最简单的写 * 最简单的写
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 直接写即可 * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 直接写即可
*/ */
@Test @Test
public void simpleWrite() { public void simpleWrite() {
@ -62,9 +64,12 @@ public class WriteTest {
/** /**
* 指定写入的列 * 指定写入的列
* <li>1. 创建excel对应的实体对象 参照{@link IndexData} * <p>
* <li>2. 使用{@link ExcelProperty}注解指定写入的列 * 1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>3. 直接写即可 * <p>
* 2. 使用{@link ExcelProperty}注解指定写入的列
* <p>
* 3. 直接写即可
*/ */
@Test @Test
public void indexWrite() { public void indexWrite() {
@ -75,9 +80,12 @@ public class WriteTest {
/** /**
* 复杂头写入 * 复杂头写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData} * <p>
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头 * 1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>3. 直接写即可 * <p>
* 2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>
* 3. 直接写即可
*/ */
@Test @Test
public void complexHeadWrite() { public void complexHeadWrite() {
@ -88,9 +96,12 @@ public class WriteTest {
/** /**
* 重复多次写入 * 重复多次写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData} * <p>
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头 * 1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>3. 直接调用二次写入即可 * <p>
* 2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>
* 3. 直接调用二次写入即可
*/ */
@Test @Test
public void repeatedWrite() { public void repeatedWrite() {
@ -108,9 +119,12 @@ public class WriteTest {
/** /**
* 日期数字或者自定义格式转换 * 日期数字或者自定义格式转换
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData} * <p>
* <li>2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解 * 1. 创建excel对应的实体对象 参照{@link ConverterData}
* <li>3. 直接写即可 * <p>
* 2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解
* <p>
* 3. 直接写即可
*/ */
@Test @Test
public void converterWrite() { public void converterWrite() {
@ -121,8 +135,10 @@ public class WriteTest {
/** /**
* 图片导出 * 图片导出
* <li>1. 创建excel对应的实体对象 参照{@link ImageData} * <p>
* <li>2. 直接写即可 * 1. 创建excel对应的实体对象 参照{@link ImageData}
* <p>
* 2. 直接写即可
*/ */
@Test @Test
public void imageWrite() throws Exception { public void imageWrite() throws Exception {
@ -150,10 +166,14 @@ public class WriteTest {
/** /**
* 根据模板写入 * 根据模板写入
* <li>1. 创建excel对应的实体对象 参照{@link IndexData} * <p>
* <li>2. 使用{@link ExcelProperty}注解指定写入的列 * 1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>3. 使用withTemplate 读取模板 * <p>
* <li>4. 直接写即可 * 2. 使用{@link ExcelProperty}注解指定写入的列
* <p>
* 3. 使用withTemplate 读取模板
* <p>
* 4. 直接写即可
*/ */
@Test @Test
public void templateWrite() { public void templateWrite() {
@ -165,9 +185,12 @@ public class WriteTest {
/** /**
* 列宽行高 * 列宽行高
* <li>1. 创建excel对应的实体对象 参照{@link WidthAndHeightData} * <p>
* <li>2. 使用注解{@link ColumnWidth}{@link HeadRowHeight}{@link ContentRowHeight}指定宽度或高度 * 1. 创建excel对应的实体对象 参照{@link WidthAndHeightData}
* <li>3. 直接写即可 * <p>
* 2. 使用注解{@link ColumnWidth}{@link HeadRowHeight}{@link ContentRowHeight}指定宽度或高度
* <p>
* 3. 直接写即可
*/ */
@Test @Test
public void widthAndHeightWrite() { public void widthAndHeightWrite() {
@ -178,9 +201,12 @@ public class WriteTest {
/** /**
* 自定义样式 * 自定义样式
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 创建一个style策略 并注册 * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 直接写即可 * <p>
* 2. 创建一个style策略 并注册
* <p>
* 3. 直接写即可
*/ */
@Test @Test
public void styleWrite() { public void styleWrite() {
@ -213,9 +239,12 @@ public class WriteTest {
/** /**
* 合并单元格 * 合并单元格
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 创建一个merge策略 并注册 * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 直接写即可 * <p>
* 2. 创建一个merge策略 并注册
* <p>
* 3. 直接写即可
*/ */
@Test @Test
public void mergeWrite() { public void mergeWrite() {
@ -228,8 +257,10 @@ public class WriteTest {
/** /**
* 使用table去写入 * 使用table去写入
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 然后写入table即可 * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 然后写入table即可
*/ */
@Test @Test
public void tableWrite() { public void tableWrite() {
@ -255,8 +286,10 @@ public class WriteTest {
* <p> * <p>
* 思路是这样子的先创建List<String>头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据 * 思路是这样子的先创建List<String>头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据
* *
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>2. 然后写入table即可 * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 然后写入table即可
*/ */
@Test @Test
public void dynamicHeadWrite() { public void dynamicHeadWrite() {
@ -277,9 +310,12 @@ public class WriteTest {
* <p> * <p>
* poi 自带{@link SXSSFSheet#autoSizeColumn(int)} 对中文支持也不太好目前没找到很好的算法 有的话可以推荐下 * poi 自带{@link SXSSFSheet#autoSizeColumn(int)} 对中文支持也不太好目前没找到很好的算法 有的话可以推荐下
* *
* <li>1. 创建excel对应的实体对象 参照{@link DemoData} * <p>
* <li>3. 注册策略{@link LongestMatchColumnWidthStyleStrategy} * 1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 直接写即可 * <p>
* 3. 注册策略{@link LongestMatchColumnWidthStyleStrategy}
* <p>
* 2. 直接写即可
*/ */
@Test @Test
public void longestMatchColumnWidthWrite() { public void longestMatchColumnWidthWrite() {

Loading…
Cancel
Save