Browse Source

优化读写逻辑

bugfix
罗成 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/util/PositionUtils.java
  37. 4
      src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java
  38. 6
      src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
  39. 3
      src/main/java/com/alibaba/excel/write/style/HorizontalCellStyleStrategy.java
  40. 3
      src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java
  41. 3
      src/test/java/com/alibaba/easyexcel/test/core/exception/ExceptionDataTest.java
  42. 27
      src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java
  43. 6
      src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java
  44. 45
      src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java
  45. 18
      src/test/java/com/alibaba/easyexcel/test/demo/web/WebTest.java
  46. 108
      src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

1
.travis.yml

@ -7,3 +7,4 @@ before_install:
- chmod +x mvnw
install:
- ./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>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.0.0</version>
<version>2.0.0-beta1</version>
</dependency>
```
## 最新版本:2.0.0
## 最新版本:2.0.0-beta1
## 维护者
姬朋飞(玉霄)
## 快速开始
@ -38,9 +38,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java
/**
* 最简单的读
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <p>3. 直接读即可
*/
@Test
public void simpleRead() {
@ -55,8 +55,8 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java
/**
* 最简单的写
* <li>1. 创建excel对应的实体对象 参照{@link com.alibaba.easyexcel.test.demo.write.DemoData}
* <li>2. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link com.alibaba.easyexcel.test.demo.write.DemoData}
* <p>2. 直接写即可
*/
@Test
public void simpleWrite() {
@ -72,9 +72,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java
/**
* 文件下载
* <li>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <li>2. 设置返回的 参数
* <li>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
* <p>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <p>2. 设置返回的 参数
* <p>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
*/
@GetMapping("download")
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}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象 参照{@link UploadData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
* <p>3. 直接读即可
*/
@PostMapping("upload")
@ResponseBody

4
pom.xml

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

114
quickstart.md

@ -78,9 +78,9 @@ public class DemoDataListener extends AnalysisEventListener<DemoData> {
```java
/**
* 最简单的读
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <p>3. 直接读即可
*/
@Test
public void simpleRead() {
@ -127,9 +127,9 @@ public class IndexOrNameData {
/**
* 指定列的下标或者列名
*
* <li>1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link IndexOrNameDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link IndexOrNameDataListener}
* <p>3. 直接读即可
*/
@Test
public void indexOrNameRead() {
@ -150,9 +150,9 @@ public class IndexOrNameData {
```java
/**
* 读多个sheet,这里注意一个sheet不能读取多次,多次读取需要重新读取文件
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <p>3. 直接读即可
*/
@Test
public void repeatedRead() {
@ -248,9 +248,9 @@ public class CustomStringStringConverter implements Converter<String> {
* 日期、数字或者自定义格式转换
* <p>
* 默认读的转换器{@link DefaultConverterLoader#loadDefaultReadConverter()}
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link ConverterDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link ConverterDataListener}
* <p>3. 直接读即可
*/
@Test
public void converterRead() {
@ -277,9 +277,9 @@ public class CustomStringStringConverter implements Converter<String> {
/**
* 多行头
*
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <li>3. 设置headRowNumber参数,然后读。 这里要注意headRowNumber如果不指定, 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数,
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link DemoDataListener}
* <p>3. 设置headRowNumber参数,然后读。 这里要注意headRowNumber如果不指定, 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数,
* 如果不传入class则默认为1.当然你指定了headRowNumber不管是否传入class都是以你传入的为准。
*/
@Test
@ -335,9 +335,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java
/**
* 文件上传
* <li>1. 创建excel对应的实体对象 参照{@link UploadData}
* <li>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
* <li>3. 直接读即可
* <p>1. 创建excel对应的实体对象 参照{@link UploadData}
* <p>2. 由于默认异步读取excel,所以需要创建excel一行一行的回调监听器,参照{@link UploadDataListener}
* <p>3. 直接读即可
*/
@PostMapping("upload")
@ResponseBody
@ -381,8 +381,8 @@ public class DemoData {
```java
/**
* 最简单的写
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 直接写即可
*/
@Test
public void simpleWrite() {
@ -425,9 +425,9 @@ public class IndexData {
```java
/**
* 指定写入的列
* <li>1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>2. 使用{@link ExcelProperty}注解指定写入的列
* <li>3. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link IndexData}
* <p>2. 使用{@link ExcelProperty}注解指定写入的列
* <p>3. 直接写即可
*/
@Test
public void indexWrite() {
@ -456,9 +456,9 @@ public class ComplexHeadData {
```java
/**
* 复杂头写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头
* <li>3. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <p>2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>3. 直接写即可
*/
@Test
public void complexHeadWrite() {
@ -477,9 +477,9 @@ public class ComplexHeadData {
```java
/**
* 重复多次写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头
* <li>3. 直接调用二次写入即可
* <p>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <p>2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>3. 直接调用二次写入即可
*/
@Test
public void repeatedWrite() {
@ -526,9 +526,9 @@ public class ConverterData {
```java
/**
* 日期、数字或者自定义格式转换
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData}
* <li>2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解
* <li>3. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link ConverterData}
* <p>2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}、{@link NumberFormat}或者自定义注解
* <p>3. 直接写即可
*/
@Test
public void converterWrite() {
@ -561,8 +561,8 @@ public class ImageData {
```java
/**
* 图片导出
* <li>1. 创建excel对应的实体对象 参照{@link ImageData}
* <li>2. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link ImageData}
* <p>2. 直接写即可
*/
@Test
public void imageWrite() throws Exception {
@ -601,10 +601,10 @@ public class ImageData {
```java
/**
* 根据模板写入
* <li>1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>2. 使用{@link ExcelProperty}注解指定写入的列
* <li>3. 使用withTemplate 读取模板
* <li>4. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link IndexData}
* <p>2. 使用{@link ExcelProperty}注解指定写入的列
* <p>3. 使用withTemplate 读取模板
* <p>4. 直接写即可
*/
@Test
public void templateWrite() {
@ -641,9 +641,9 @@ public class WidthAndHeightData {
```java
/**
* 列宽、行高
* <li>1. 创建excel对应的实体对象 参照{@link WidthAndHeightData}
* <li>2. 使用注解{@link ColumnWidth}、{@link HeadRowHeight}、{@link ContentRowHeight}指定宽度或高度
* <li>3. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link WidthAndHeightData}
* <p>2. 使用注解{@link ColumnWidth}、{@link HeadRowHeight}、{@link ContentRowHeight}指定宽度或高度
* <p>3. 直接写即可
*/
@Test
public void widthAndHeightWrite() {
@ -662,9 +662,9 @@ public class WidthAndHeightData {
```java
/**
* 自定义样式
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 创建一个style策略 并注册
* <li>3. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 创建一个style策略 并注册
* <p>3. 直接写即可
*/
@Test
public void styleWrite() {
@ -705,9 +705,9 @@ public class WidthAndHeightData {
```java
/**
* 合并单元格
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 创建一个merge策略 并注册
* <li>3. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 创建一个merge策略 并注册
* <p>3. 直接写即可
*/
@Test
public void mergeWrite() {
@ -729,8 +729,8 @@ public class WidthAndHeightData {
```java
/**
* 使用table去写入
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 然后写入table即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 然后写入table即可
*/
@Test
public void tableWrite() {
@ -764,8 +764,8 @@ public class WidthAndHeightData {
* <p>
* 思路是这样子的,先创建List<String>头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据
*
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 然后写入table即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>2. 然后写入table即可
*/
@Test
public void dynamicHeadWrite() {
@ -818,9 +818,9 @@ public class LongestMatchColumnWidthData {
* <p>
* poi 自带{@link SXSSFSheet#autoSizeColumn(int)} 对中文支持也不太好。目前没找到很好的算法。 有的话可以推荐下。
*
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 注册策略{@link LongestMatchColumnWidthStyleStrategy}
* <li>2. 直接写即可
* <p>1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>3. 注册策略{@link LongestMatchColumnWidthStyleStrategy}
* <p>2. 直接写即可
*/
@Test
public void longestMatchColumnWidthWrite() {
@ -852,9 +852,9 @@ DEMO代码地址:[https://github.com/alibaba/easyexcel/blob/master/src/test/ja
```java
/**
* 文件下载
* <li>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <li>2. 设置返回的 参数
* <li>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
* <p>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <p>2. 设置返回的 参数
* <p>3. 直接写,这里注意,finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
*/
@GetMapping("download")
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
* @param typeEnum
* 03 or 07
* @param needHead
* Whether a write header is required
* @return new ExcelWriter
* @deprecated please use {@link EasyExcel#write()}
*/
@ -157,6 +159,7 @@ public class EasyExcelFactory {
* @param typeEnum
* 03 or 07
* @param needHead
* Whether a write header is required
* @param handler
* User-defined callback
* @return new ExcelWriter
@ -182,7 +185,8 @@ public class EasyExcelFactory {
* Build excel the write
*
* @param file
* @return
* File to write
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(File file) {
return write(file, null);
@ -192,8 +196,10 @@ public class EasyExcelFactory {
* Build excel the write
*
* @param file
* File to write
* @param head
* @return
* Annotate the class for configuration information
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(File file, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
@ -208,7 +214,8 @@ public class EasyExcelFactory {
* Build excel the write
*
* @param pathName
* @return
* File path to write
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(String pathName) {
return write(pathName, null);
@ -218,8 +225,10 @@ public class EasyExcelFactory {
* Build excel the write
*
* @param pathName
* File path to write
* @param head
* @return
* Annotate the class for configuration information
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(String pathName, Class head) {
ExcelWriterBuilder excelWriterBuilder = new ExcelWriterBuilder();
@ -234,7 +243,8 @@ public class EasyExcelFactory {
* Build excel the write
*
* @param outputStream
* @return
* Output stream to write
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(OutputStream outputStream) {
return write(outputStream, null);
@ -244,8 +254,10 @@ public class EasyExcelFactory {
* Build excel the write
*
* @param outputStream
* Output stream to write
* @param head
* @return
* Annotate the class for configuration information.
* @return Excel writer builder
*/
public static ExcelWriterBuilder write(OutputStream outputStream, Class head) {
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() {
return writerSheet(null, null);
}
/**
* Build excel the 'writerSheet'
* Build excel the <code>writerSheet</code>
*
* @param sheetNo
* @return
* Index of sheet,0 base.
* @return Excel sheet writer builder.
*/
public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo) {
return writerSheet(sheetNo, null);
@ -279,7 +292,8 @@ public class EasyExcelFactory {
* Build excel the 'writerSheet'
*
* @param sheetName
* @return
* The name of sheet.
* @return Excel sheet writer builder.
*/
public static ExcelWriterSheetBuilder writerSheet(String sheetName) {
return writerSheet(null, sheetName);
@ -289,8 +303,10 @@ public class EasyExcelFactory {
* Build excel the 'writerSheet'
*
* @param sheetNo
* Index of sheet,0 base.
* @param sheetName
* @return
* The name of sheet.
* @return Excel sheet writer builder.
*/
public static ExcelWriterSheetBuilder writerSheet(Integer sheetNo, String sheetName) {
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() {
return writerTable(null);
@ -316,7 +332,8 @@ public class EasyExcelFactory {
* Build excel the 'writerTable'
*
* @param tableNo
* @return
* Index of table,0 base.
* @return Excel table writer builder.
*/
public static ExcelWriterTableBuilder writerTable(Integer tableNo) {
ExcelWriterTableBuilder excelWriterTableBuilder = new ExcelWriterTableBuilder();
@ -329,7 +346,7 @@ public class EasyExcelFactory {
/**
* Build excel the read
*
* @return
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read() {
return new ExcelReaderBuilder();
@ -339,7 +356,8 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param file
* @return
* File to read.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(File file) {
return read(file, null, null);
@ -349,8 +367,10 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param file
* File to read.
* @param readListener
* @return
* Read listener.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(File file, ReadListener readListener) {
return read(file, null, readListener);
@ -360,9 +380,12 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param file
* File to read.
* @param head
* Annotate the class for configuration information.
* @param readListener
* @return
* Read listener.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(File file, Class head, ReadListener readListener) {
ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
@ -380,7 +403,8 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param pathName
* @return
* File path to read.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(String pathName) {
return read(pathName, null, null);
@ -390,8 +414,10 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param pathName
* File path to read.
* @param readListener
* @return
* Read listener.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(String pathName, ReadListener readListener) {
return read(pathName, null, readListener);
@ -401,9 +427,12 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param pathName
* File path to read.
* @param head
* Annotate the class for configuration information.
* @param readListener
* @return
* Read listener.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(String pathName, Class head, ReadListener readListener) {
ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
@ -421,7 +450,8 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param inputStream
* @return
* Input stream to read.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(InputStream inputStream) {
return read(inputStream, null, null);
@ -431,8 +461,10 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param inputStream
* Input stream to read.
* @param readListener
* @return
* Read listener.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(InputStream inputStream, ReadListener readListener) {
return read(inputStream, null, readListener);
@ -442,9 +474,12 @@ public class EasyExcelFactory {
* Build excel the read
*
* @param inputStream
* Input stream to read.
* @param head
* Annotate the class for configuration information.
* @param readListener
* @return
* Read listener.
* @return Excel reader builder.
*/
public static ExcelReaderBuilder read(InputStream inputStream, Class head, ReadListener readListener) {
ExcelReaderBuilder excelReaderBuilder = new ExcelReaderBuilder();
@ -461,7 +496,7 @@ public class EasyExcelFactory {
/**
* Build excel the 'readSheet'
*
* @return
* @return Excel sheet reader builder.
*/
public static ExcelReaderSheetBuilder readSheet() {
return readSheet(null, null);
@ -471,7 +506,8 @@ public class EasyExcelFactory {
* Build excel the 'readSheet'
*
* @param sheetNo
* @return
* Index of sheet,0 base.
* @return Excel sheet reader builder.
*/
public static ExcelReaderSheetBuilder readSheet(Integer sheetNo) {
return readSheet(sheetNo, null);
@ -481,7 +517,8 @@ public class EasyExcelFactory {
* Build excel the 'readSheet'
*
* @param sheetName
* @return
* The name of sheet.
* @return Excel sheet reader builder.
*/
public static ExcelReaderSheetBuilder readSheet(String sheetName) {
return readSheet(null, sheetName);
@ -491,8 +528,10 @@ public class EasyExcelFactory {
* Build excel the 'readSheet'
*
* @param sheetNo
* Index of sheet,0 base.
* @param sheetName
* @return
* The name of sheet.
* @return Excel sheet reader builder.
*/
public static ExcelReaderSheetBuilder readSheet(Integer sheetNo, String sheetName) {
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
*
* @throws Throwable
*/
@Override
protected void finalize() {

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

@ -13,6 +13,7 @@ public interface ExcelAnalyser {
* parse one sheet
*
* @param readSheet
* sheet to read
*/
void analysis(ReadSheet readSheet);
@ -24,7 +25,7 @@ public interface ExcelAnalyser {
/**
* Acquisition excel executor
*
* @return
* @return Excel file Executor
*/
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
*
* @return
* @return Actual sheet in excel
*/
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
*
* @param record
* @return
* Excel analysis record
* @return Which tags are supported
*/
boolean support(Record record);
@ -33,28 +34,28 @@ public interface XlsRecordHandler extends Comparable<XlsRecordHandler> {
/**
* Get row
*
* @return
* @return Row index
*/
int getRow();
/**
* Get column
*
* @return
* @return Column index
*/
int getColumn();
/**
* Get value
*
* @return
* @return Excel internal cell data
*/
CellData getCellData();
/**
* Get order
*
* @return
* @return Order
*/
int getOrder();
}

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

@ -12,7 +12,8 @@ public interface XlsxCellHandler {
* Which tags are supported
*
* @param name
* @return
* Tag name
* @return Support parsing or not
*/
boolean support(String name);
@ -20,7 +21,9 @@ public interface XlsxCellHandler {
* Start handle
*
* @param name
* Tag name
* @param attributes
* Tag attributes
*/
void startHandle(String name, Attributes attributes);
@ -28,6 +31,7 @@ public interface XlsxCellHandler {
* End handle
*
* @param name
* Tag 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.
*
* <li>write: It automatically merges when you have more than one head
* <li>read: When you have multiple heads, take the first one
* <p>
* 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 {""};
@ -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
*
* @return
* @return Index of column
*/
int index() default -1;
/**
* Force the current field to use this converter.
*
* @return
* @return Converter
*/
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
*
* @return
* @return Format string
* @deprecated please use {@link com.alibaba.excel.annotation.format.DateTimeFormat}
*/
@Deprecated

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

@ -9,8 +9,10 @@ import java.lang.annotation.Target;
/**
* Convert date format.
*
* <li>write: It can be used on classes {@link java.util.Date}
* <li>read: It can be used on classes {@link String}
* <p>
* write: It can be used on classes {@link java.util.Date}
* <p>
* read: It can be used on classes {@link String}
*
* @author Jiaju Zhuang
*/
@ -23,14 +25,14 @@ public @interface DateTimeFormat {
*
* Specific format reference {@link java.text.SimpleDateFormat}
*
* @return
* @return Format pattern
*/
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;
}

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

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

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

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

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

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

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

@ -13,6 +13,7 @@ public interface ReadCache {
* Initialize cache
*
* @param analysisContext
* A context is the main anchorage point of a excel reader.
*/
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
*
* @param value
* Cache value
*/
void put(String value);
@ -27,7 +29,8 @@ public interface ReadCache {
* Get value
*
* @param key
* @return
* Index
* @return Value
*/
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
*
* @param excelExecutor
* Excel file Executor
* @param readSheet
* sheet to read
*/
void currentSheet(ExcelExecutor excelExecutor, ReadSheet readSheet);
/**
* All information about the workbook you are currently working on
*
* @return
* @return Current workbook holder
*/
ReadWorkbookHolder readWorkbookHolder();
/**
* All information about the sheet you are currently working on
*
* @return
* @return Current sheet holder
*/
ReadSheetHolder readSheetHolder();
@ -45,20 +47,21 @@ public interface AnalysisContext {
* Set row of currently operated cell
*
* @param readRowHolder
* Current row holder
*/
void readRowHolder(ReadRowHolder readRowHolder);
/**
* Row of currently operated cell
*
* @return
* @return Current row holder
*/
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();

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

@ -16,14 +16,14 @@ public interface Converter<T> {
/**
* Back to object types in Java
*
* @return
* @return Support for Java class
*/
Class supportJavaTypeKey();
/**
* Back to object enum in excel
*
* @return
* @return Support for {@link CellDataTypeEnum}
*/
CellDataTypeEnum supportExcelTypeKey();
@ -31,13 +31,14 @@ public interface Converter<T> {
* Convert excel objects to Java objects
*
* @param cellData
* NotNull
* Excel cell data.NotNull.
* @param contentProperty
* Nullable
* Content property.Nullable.
* @param globalConfiguration
* NotNull
* @return
* Global configuration.NotNull.
* @return Data to put into a Java object
* @throws Exception
* Exception.
*/
T convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) throws Exception;
@ -46,13 +47,14 @@ public interface Converter<T> {
* Convert Java objects to excel objects
*
* @param value
* NotNull
* Java Data.NotNull.
* @param contentProperty
* Nullable
* Content property.Nullable.
* @param globalConfiguration
* NotNull
* @return
* Global configuration.NotNull.
* @return Data to put into a Excel
* @throws Exception
* Exception.
*/
CellData convertToExcelData(T value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration)
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
* @deprecated please use {@ com.alibaba.excel.write.handler.WriteHandler}
* @deprecated please use {@link com.alibaba.excel.write.handler.WriteHandler}
*/
@Deprecated
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 ExcelAnalysisException() {
}
public ExcelAnalysisException() {}
public ExcelAnalysisException(String 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 ExcelGenerateException(String 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;
/**
* <li>Read key:
* <li>Write key:
* <p>
* Read key:
* <p>
* Write key:
*/
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;
/**
* excel internal cell data
* Excel internal cell data
*
* @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
*
* @return
* @return Record whether it's new or from cache
*/
boolean isNew();
/**
* Some global variables
*
* @return
* @return Global configuration
*/
GlobalConfiguration globalConfiguration();
/**
* What converter does the currently operated cell need to execute
*
* @return
* @return Converter
*/
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
*
* @return
* @return Holder enum.
*/
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));
}
/**
* 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) {
readWorkbook.setMandatoryUseInputStream(mandatoryUseInputStream);
@ -110,9 +110,12 @@ public class ExcelReaderBuilder {
/**
* Count the number of added heads when read sheet.
*
* <li>0 - This Sheet has no head ,since the first row are the data
* <li>1 - This Sheet has one row head , this is the default
* <li>2 - This Sheet has two row head ,since the third row is the data
* <p>
* 0 - This Sheet has no head ,since the first row are 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
* @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.
*
* <li>0 - This Sheet has no head ,since the first row are the data
* <li>1 - This Sheet has one row head , this is the default
* <li>2 - This Sheet has two row head ,since the third row is the data
* <p>
* 0 - This Sheet has no head ,since the first row are 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
* @return
@ -149,8 +152,6 @@ public class ExcelReaderSheetBuilder {
/**
* Sax read
*
* @return
*/
public void doRead() {
if (excelReader == null) {

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

@ -15,6 +15,7 @@ public interface ReadListenerRegistryCenter {
* register
*
* @param listener
* Analysis listener
*/
void register(AnalysisEventListener listener);
@ -24,6 +25,7 @@ public interface ReadListenerRegistryCenter {
* @param event
* parse event
* @param analysisContext
* Analysis context
*/
void notifyEndOneRow(AnalysisFinishEvent event, AnalysisContext analysisContext);
@ -31,6 +33,7 @@ public interface ReadListenerRegistryCenter {
* Notify after all analysed
*
* @param analysisContext
* Analysis context
*/
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.
*
* <li>0 - This Sheet has no head ,since the first row are the data
* <li>1 - This Sheet has one row head , this is the default
* <li>2 - This Sheet has two row head ,since the third row is the data
* <p>
* 0 - This Sheet has no head ,since the first row are 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;
/**

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

@ -32,7 +32,8 @@ public class ReadWorkbook extends ReadBasicParameter {
private File file;
/**
* 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;
/**
@ -51,8 +52,10 @@ public class ReadWorkbook extends ReadBasicParameter {
private ReadCache readCache;
/**
* The default is all excel objects.Default is true.
* <li>if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field.
* <li>if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
* <p>
* 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.
*/

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.
*
* <li>0 - This Sheet has no head ,since the first row are the data
* <li>1 - This Sheet has one row head , this is the default
* <li>2 - This Sheet has two row head ,since the third row is the data
* <p>
* 0 - This Sheet has no head ,since the first row are 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;
/**

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
*
* @return
* @return Current {@link ReadListener}
*/
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();

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

@ -43,7 +43,8 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
private File file;
/**
* 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;
/**

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

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

4
src/main/java/com/alibaba/excel/util/PositionUtils.java

@ -9,7 +9,7 @@ public class PositionUtils {
int row = 0;
if (currentCellIndex != null) {
String rowStr = currentCellIndex.replaceAll("[A-Z]", "").replaceAll("[a-z]", "");
row = Integer.parseInt(rowStr)-1;
row = Integer.parseInt(rowStr) - 1;
}
return row;
}
@ -23,6 +23,6 @@ public class PositionUtils {
col += (currentIndex[i] - '@') * Math.pow(26, (currentIndex.length - i - 1));
}
}
return col-1;
return col - 1;
}
}

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

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

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

@ -52,8 +52,10 @@ public class WriteWorkbook extends WriteBasicParameter {
private Boolean mandatoryUseInputStream;
/**
* The default is all excel objects.Default is true.
* <li>if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a field.
* <li>if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
* <p>
* 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.
*/

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

@ -25,7 +25,8 @@ public class HorizontalCellStyleStrategy extends AbstractCellStyleStrategy {
private CellStyle headCellStyle;
private List<CellStyle> contentCellStyleList;
public HorizontalCellStyleStrategy(WriteCellStyle headWriteCellStyle, List<WriteCellStyle> contentWriteCellStyleList) {
public HorizontalCellStyleStrategy(WriteCellStyle headWriteCellStyle,
List<WriteCellStyle> contentWriteCellStyleList) {
this.headWriteCellStyle = headWriteCellStyle;
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.
*
* <li>if return null,ignore
* <p>
* if return null,ignore
*
* @param head
* 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 {
EasyExcel.write(new FileOutputStream(file), ExceptionData.class).sheet().doWrite(data());
EasyExcel.read(new FileInputStream(file), ExceptionData.class, new ExceptionDataListener()).sheet()
.doRead();
EasyExcel.read(new FileInputStream(file), ExceptionData.class, new ExceptionDataListener()).sheet().doRead();
}
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() {
EasyExcel.write(file.getPath()).head(ParameterData.class).sheet().doWrite(data());
EasyExcel.read(file.getPath()).head(ParameterData.class)
.registerReadListener(new ParameterDataListener()).sheet().doRead();
EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener())
.sheet().doRead();
}
private void readAndWrite2() {
@ -58,8 +58,8 @@ public class ParameterDataTest {
private void readAndWrite3() throws Exception {
EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).sheet().doWrite(data());
EasyExcel.read(file.getPath()).head(ParameterData.class)
.registerReadListener(new ParameterDataListener()).sheet().doRead();
EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener())
.sheet().doRead();
}
private void readAndWrite4() throws Exception {
@ -68,15 +68,14 @@ public class ParameterDataTest {
}
private void readAndWrite5() throws Exception {
ExcelWriter excelWriter = EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class)
.relativeHeadRowIndex(0).build();
ExcelWriter excelWriter =
EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).relativeHeadRowIndex(0).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build();
WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).needHead(Boolean.TRUE).build();
excelWriter.write(data(), writeSheet, writeTable);
excelWriter.finish();
ExcelReader excelReader =
EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
ExcelReader excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
.mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
ReadSheet readSheet = EasyExcel.readSheet().head(ParameterData.class).use1904windowing(Boolean.FALSE)
.headRowNumber(1).sheetNo(0).sheetName("0").build();
@ -90,16 +89,15 @@ public class ParameterDataTest {
}
private void readAndWrite6() throws Exception {
ExcelWriter excelWriter = EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class)
.relativeHeadRowIndex(0).build();
ExcelWriter excelWriter =
EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).relativeHeadRowIndex(0).build();
WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build();
WriteTable writeTable = EasyExcel.writerTable(0).registerConverter(new StringStringConverter())
.relativeHeadRowIndex(0).needHead(Boolean.TRUE).build();
excelWriter.write(data(), writeSheet, writeTable);
excelWriter.finish();
ExcelReader excelReader =
EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
ExcelReader excelReader = EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class)
.mandatoryUseInputStream(Boolean.FALSE).autoCloseStream(Boolean.TRUE).readCache(new MapCache()).build();
ReadSheet readSheet = EasyExcel.readSheet("0").head(ParameterData.class).use1904windowing(Boolean.FALSE)
.headRowNumber(1).sheetNo(0).build();
@ -116,9 +114,8 @@ public class ParameterDataTest {
EasyExcel.write(file, ParameterData.class).registerConverter(new StringStringConverter()).sheet()
.registerConverter(new StringStringConverter()).needHead(Boolean.FALSE).table(0).needHead(Boolean.TRUE)
.doWrite(data());
EasyExcel.read(file.getPath()).head(ParameterData.class)
.registerReadListener(new ParameterDataListener()).sheet().registerConverter(new StringStringConverter())
.doRead();
EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener())
.sheet().registerConverter(new StringStringConverter()).doRead();
}
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();
WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
excelWriter.write(data(), writeSheet).write(data(), writeSheet).finish();
ExcelReader excelReader =
EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
ExcelReader excelReader = EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
ReadSheet readSheet = EasyExcel.readSheet(0).build();
excelReader.read(readSheet).finish();
}
@ -72,8 +71,7 @@ public class RepetitionDataTest {
WriteSheet writeSheet = EasyExcel.writerSheet(0).build();
WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).build();
excelWriter.write(data(), writeSheet, writeTable).write(data(), writeSheet, writeTable).finish();
ExcelReader excelReader =
EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
ExcelReader excelReader = EasyExcel.read(file, RepetitionData.class, new RepetitionDataListener()).build();
ReadSheet readSheet = EasyExcel.readSheet(0).headRowNumber(2).build();
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}
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <li>3. 直接读即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <p>
* 3. 直接读即可
*/
@Test
public void simpleRead() {
@ -53,9 +56,12 @@ public class ReadTest {
/**
* 指定列的下标或者列名
*
* <li>1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link IndexOrNameDataListener}
* <li>3. 直接读即可
* <p>
* 1. 创建excel对应的实体对象,并使用{@link ExcelProperty}注解. 参照{@link IndexOrNameData}
* <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link IndexOrNameDataListener}
* <p>
* 3. 直接读即可
*/
@Test
public void indexOrNameRead() {
@ -66,9 +72,12 @@ public class ReadTest {
/**
* 读多个sheet,这里注意一个sheet不能读取多次多次读取需要重新读取文件
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <li>3. 直接读即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <p>
* 3. 直接读即可
*/
@Test
public void repeatedRead() {
@ -86,9 +95,12 @@ public class ReadTest {
* 日期数字或者自定义格式转换
* <p>
* 默认读的转换器{@link DefaultConverterLoader#loadDefaultReadConverter()}
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link ConverterDataListener}
* <li>3. 直接读即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link ConverterData}.里面可以使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解
* <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link ConverterDataListener}
* <p>
* 3. 直接读即可
*/
@Test
public void converterRead() {
@ -105,9 +117,12 @@ public class ReadTest {
/**
* 多行头
*
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <li>3. 设置headRowNumber参数然后读 这里要注意headRowNumber如果不指定 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link DemoDataListener}
* <p>
* 3. 设置headRowNumber参数然后读 这里要注意headRowNumber如果不指定 会根据你传入的class的{@link ExcelProperty#value()}里面的表头的数量来决定行数
* 如果不传入class则默认为1.当然你指定了headRowNumber不管是否传入class都是以你传入的为准
*/
@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 {
/**
* 文件下载
* <li>1. 创建excel对应的实体对象 参照{@link DownloadData}
* <li>2. 设置返回的 参数
* <li>3. 直接写这里注意finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
* <p>
* 1. 创建excel对应的实体对象 参照{@link DownloadData}
* <p>
* 2. 设置返回的 参数
* <p>
* 3. 直接写这里注意finish的时候会自动关闭OutputStream,当然你外面再关闭流问题不大
*/
@GetMapping("download")
public void download(HttpServletResponse response) throws IOException {
@ -38,9 +41,12 @@ public class WebTest {
/**
* 文件上传
* <li>1. 创建excel对应的实体对象 参照{@link UploadData}
* <li>2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link UploadDataListener}
* <li>3. 直接读即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link UploadData}
* <p>
* 2. 由于默认异步读取excel所以需要创建excel一行一行的回调监听器参照{@link UploadDataListener}
* <p>
* 3. 直接读即可
*/
@PostMapping("upload")
@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 {
/**
* 最简单的写
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 直接写即可
*/
@Test
public void simpleWrite() {
@ -62,9 +64,12 @@ public class WriteTest {
/**
* 指定写入的列
* <li>1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>2. 使用{@link ExcelProperty}注解指定写入的列
* <li>3. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link IndexData}
* <p>
* 2. 使用{@link ExcelProperty}注解指定写入的列
* <p>
* 3. 直接写即可
*/
@Test
public void indexWrite() {
@ -75,9 +80,12 @@ public class WriteTest {
/**
* 复杂头写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头
* <li>3. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <p>
* 2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>
* 3. 直接写即可
*/
@Test
public void complexHeadWrite() {
@ -88,9 +96,12 @@ public class WriteTest {
/**
* 重复多次写入
* <li>1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <li>2. 使用{@link ExcelProperty}注解指定复杂的头
* <li>3. 直接调用二次写入即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link ComplexHeadData}
* <p>
* 2. 使用{@link ExcelProperty}注解指定复杂的头
* <p>
* 3. 直接调用二次写入即可
*/
@Test
public void repeatedWrite() {
@ -108,9 +119,12 @@ public class WriteTest {
/**
* 日期数字或者自定义格式转换
* <li>1. 创建excel对应的实体对象 参照{@link ConverterData}
* <li>2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解
* <li>3. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link ConverterData}
* <p>
* 2. 使用{@link ExcelProperty}配合使用注解{@link DateTimeFormat}{@link NumberFormat}或者自定义注解
* <p>
* 3. 直接写即可
*/
@Test
public void converterWrite() {
@ -121,8 +135,10 @@ public class WriteTest {
/**
* 图片导出
* <li>1. 创建excel对应的实体对象 参照{@link ImageData}
* <li>2. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link ImageData}
* <p>
* 2. 直接写即可
*/
@Test
public void imageWrite() throws Exception {
@ -150,10 +166,14 @@ public class WriteTest {
/**
* 根据模板写入
* <li>1. 创建excel对应的实体对象 参照{@link IndexData}
* <li>2. 使用{@link ExcelProperty}注解指定写入的列
* <li>3. 使用withTemplate 读取模板
* <li>4. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link IndexData}
* <p>
* 2. 使用{@link ExcelProperty}注解指定写入的列
* <p>
* 3. 使用withTemplate 读取模板
* <p>
* 4. 直接写即可
*/
@Test
public void templateWrite() {
@ -165,9 +185,12 @@ public class WriteTest {
/**
* 列宽行高
* <li>1. 创建excel对应的实体对象 参照{@link WidthAndHeightData}
* <li>2. 使用注解{@link ColumnWidth}{@link HeadRowHeight}{@link ContentRowHeight}指定宽度或高度
* <li>3. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link WidthAndHeightData}
* <p>
* 2. 使用注解{@link ColumnWidth}{@link HeadRowHeight}{@link ContentRowHeight}指定宽度或高度
* <p>
* 3. 直接写即可
*/
@Test
public void widthAndHeightWrite() {
@ -178,9 +201,12 @@ public class WriteTest {
/**
* 自定义样式
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 创建一个style策略 并注册
* <li>3. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 创建一个style策略 并注册
* <p>
* 3. 直接写即可
*/
@Test
public void styleWrite() {
@ -213,9 +239,12 @@ public class WriteTest {
/**
* 合并单元格
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 创建一个merge策略 并注册
* <li>3. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 创建一个merge策略 并注册
* <p>
* 3. 直接写即可
*/
@Test
public void mergeWrite() {
@ -228,8 +257,10 @@ public class WriteTest {
/**
* 使用table去写入
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 然后写入table即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 然后写入table即可
*/
@Test
public void tableWrite() {
@ -255,8 +286,10 @@ public class WriteTest {
* <p>
* 思路是这样子的先创建List<String>头格式的sheet仅仅写入头,然后通过table 不写入头的方式 去写入数据
*
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>2. 然后写入table即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 然后写入table即可
*/
@Test
public void dynamicHeadWrite() {
@ -277,9 +310,12 @@ public class WriteTest {
* <p>
* poi 自带{@link SXSSFSheet#autoSizeColumn(int)} 对中文支持也不太好目前没找到很好的算法 有的话可以推荐下
*
* <li>1. 创建excel对应的实体对象 参照{@link DemoData}
* <li>3. 注册策略{@link LongestMatchColumnWidthStyleStrategy}
* <li>2. 直接写即可
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 3. 注册策略{@link LongestMatchColumnWidthStyleStrategy}
* <p>
* 2. 直接写即可
*/
@Test
public void longestMatchColumnWidthWrite() {

Loading…
Cancel
Save