Browse Source

* csv支持设置读写编码 [Issue #2404](https://github.com/alibaba/easyexcel/issues/2404)

pull/2472/head
Jiaju Zhuang 3 years ago
parent
commit
95b387888c
  1. 11
      easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java
  2. 22
      easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java
  3. 8
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java
  4. 16
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java
  5. 5
      easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java
  6. 11
      easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
  7. 3
      easyexcel-core/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
  8. 3
      easyexcel-core/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
  9. 17
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/charset/CharsetData.java
  10. 119
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/charset/CharsetDataTest.java
  11. 8
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java
  12. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java
  13. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java
  14. 22
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java
  15. 6
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java
  16. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java
  17. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java
  18. 10
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java
  19. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java
  20. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java
  21. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java
  22. 12
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java
  23. 30
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java
  24. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
  25. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java
  26. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java
  27. 10
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java
  28. 4
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java
  29. 8
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java
  30. 2
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java
  31. 18
      easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java
  32. 1
      update.md

11
easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java

@ -1,8 +1,10 @@
package com.alibaba.excel.analysis.csv; package com.alibaba.excel.analysis.csv;
import java.io.FileInputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.file.Files;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -84,12 +86,15 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor {
CSVFormat csvFormat = csvReadWorkbookHolder.getCsvFormat(); CSVFormat csvFormat = csvReadWorkbookHolder.getCsvFormat();
if (csvReadWorkbookHolder.getMandatoryUseInputStream()) { if (csvReadWorkbookHolder.getMandatoryUseInputStream()) {
return csvFormat.parse(new InputStreamReader(csvReadWorkbookHolder.getInputStream(),csvReadWorkbookHolder.getEncoding())); return csvFormat.parse(
new InputStreamReader(csvReadWorkbookHolder.getInputStream(), csvReadWorkbookHolder.getCharset()));
} }
if (csvReadWorkbookHolder.getFile() != null) { if (csvReadWorkbookHolder.getFile() != null) {
return csvFormat.parse(new FileReader(csvReadWorkbookHolder.getFile())); return csvFormat.parse(new InputStreamReader(Files.newInputStream(csvReadWorkbookHolder.getFile().toPath()),
csvReadWorkbookHolder.getCharset()));
} }
return csvFormat.parse(new InputStreamReader(csvReadWorkbookHolder.getInputStream(),csvReadWorkbookHolder.getEncoding())); return csvFormat.parse(
new InputStreamReader(csvReadWorkbookHolder.getInputStream(), csvReadWorkbookHolder.getCharset()));
} }
private void dealRecord(CSVRecord record, int rowIndex) { private void dealRecord(CSVRecord record, int rowIndex) {

22
easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java

@ -2,6 +2,7 @@ package com.alibaba.excel.read.builder;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -38,11 +39,6 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder<Exce
return this; return this;
} }
public ExcelReaderBuilder encoding(String encoding){
readWorkbook.setEncoding(encoding);
return this;
}
/** /**
* Read InputStream * Read InputStream
* <p> * <p>
@ -72,6 +68,15 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder<Exce
return file(new File(pathName)); return file(new File(pathName));
} }
/**
* charset.
* Only work on the CSV file
*/
public ExcelReaderBuilder charset(Charset charset) {
readWorkbook.setCharset(charset);
return this;
}
/** /**
* Mandatory use 'inputStream' .Default is false. * Mandatory use 'inputStream' .Default is false.
* <p> * <p>
@ -156,10 +161,10 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder<Exce
* <p> * <p>
* Please pass in the name of a class ,like : "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl" * Please pass in the name of a class ,like : "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"
* *
* @see SAXParserFactory#newInstance()
* @see SAXParserFactory#newInstance(String, ClassLoader)
* @param xlsxSAXParserFactoryName * @param xlsxSAXParserFactoryName
* @return * @return
* @see SAXParserFactory#newInstance()
* @see SAXParserFactory#newInstance(String, ClassLoader)
*/ */
public ExcelReaderBuilder xlsxSAXParserFactoryName(String xlsxSAXParserFactoryName) { public ExcelReaderBuilder xlsxSAXParserFactoryName(String xlsxSAXParserFactoryName) {
readWorkbook.setXlsxSAXParserFactoryName(xlsxSAXParserFactoryName); readWorkbook.setXlsxSAXParserFactoryName(xlsxSAXParserFactoryName);
@ -169,8 +174,7 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder<Exce
/** /**
* Read some extra information, not by default * Read some extra information, not by default
* *
* @param extraType * @param extraType extra information type
* extra information type
* @return * @return
*/ */
public ExcelReaderBuilder extraRead(CellExtraTypeEnum extraType) { public ExcelReaderBuilder extraRead(CellExtraTypeEnum extraType) {

8
easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/ReadWorkbook.java

@ -2,6 +2,7 @@ package com.alibaba.excel.read.metadata;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Set; import java.util.Set;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
@ -43,6 +44,11 @@ public class ReadWorkbook extends ReadBasicParameter {
* If 'inputStream' and 'file' all not empty, file first * If 'inputStream' and 'file' all not empty, file first
*/ */
private File file; private File file;
/**
* charset.
* Only work on the CSV file
*/
private Charset charset;
/** /**
* Mandatory use 'inputStream' .Default is false. * Mandatory use 'inputStream' .Default is false.
* <p> * <p>
@ -98,6 +104,4 @@ public class ReadWorkbook extends ReadBasicParameter {
* @see CellExtraTypeEnum * @see CellExtraTypeEnum
*/ */
private Set<CellExtraTypeEnum> extraReadSet; private Set<CellExtraTypeEnum> extraReadSet;
private String encoding;
} }

16
easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java

@ -2,6 +2,7 @@ package com.alibaba.excel.read.metadata.holder;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -51,6 +52,12 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
* If 'inputStream' and 'file' all not empty, file first * If 'inputStream' and 'file' all not empty, file first
*/ */
private File file; private File file;
/**
* charset.
* Only work on the CSV file
*/
private Charset charset;
/** /**
* Mandatory use 'inputStream' .Default is false. * Mandatory use 'inputStream' .Default is false.
* <p> * <p>
@ -68,7 +75,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
/** /**
* This object can be read in the Listener {@link AnalysisEventListener#invoke(Object, AnalysisContext)} * This object can be read in the Listener {@link AnalysisEventListener#invoke(Object, AnalysisContext)}
* {@link AnalysisContext#getCustom()} * {@link AnalysisContext#getCustom()}
*
*/ */
private Object customObject; private Object customObject;
/** /**
@ -122,6 +128,13 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.inputStream = readWorkbook.getInputStream(); this.inputStream = readWorkbook.getInputStream();
} }
this.file = readWorkbook.getFile(); this.file = readWorkbook.getFile();
if (readWorkbook.getCharset() == null) {
this.charset = Charset.defaultCharset();
} else {
this.charset = readWorkbook.getCharset();
}
if (readWorkbook.getMandatoryUseInputStream() == null) { if (readWorkbook.getMandatoryUseInputStream() == null) {
this.mandatoryUseInputStream = Boolean.FALSE; this.mandatoryUseInputStream = Boolean.FALSE;
} else { } else {
@ -160,7 +173,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder {
this.password = readWorkbook.getPassword(); this.password = readWorkbook.getPassword();
} }
@Override @Override
public HolderEnum holderType() { public HolderEnum holderType() {
return HolderEnum.WORKBOOK; return HolderEnum.WORKBOOK;

5
easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java

@ -5,6 +5,7 @@ import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.util.StringUtils; import com.alibaba.excel.util.StringUtils;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -25,13 +26,9 @@ public class CsvReadWorkbookHolder extends ReadWorkbookHolder {
private CSVFormat csvFormat; private CSVFormat csvFormat;
private CSVParser csvParser; private CSVParser csvParser;
private String encoding;
public CsvReadWorkbookHolder(ReadWorkbook readWorkbook) { public CsvReadWorkbookHolder(ReadWorkbook readWorkbook) {
super(readWorkbook); super(readWorkbook);
setExcelType(ExcelTypeEnum.CSV); setExcelType(ExcelTypeEnum.CSV);
this.csvFormat = CSVFormat.DEFAULT; this.csvFormat = CSVFormat.DEFAULT;
this.encoding = StringUtils.isEmpty(readWorkbook.getEncoding())? CharsetNames.UTF_8:readWorkbook.getEncoding();
} }
} }

11
easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java

@ -3,8 +3,10 @@ package com.alibaba.excel.write.builder;
import java.io.File; import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.Charset;
import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteWorkbook; import com.alibaba.excel.write.metadata.WriteWorkbook;
@ -85,6 +87,15 @@ public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder<Exce
return file(new File(outputPathName)); return file(new File(outputPathName));
} }
/**
* charset.
* Only work on the CSV file
*/
public ExcelWriterBuilder charset(Charset charset) {
writeWorkbook.setCharset(charset);
return this;
}
public ExcelWriterBuilder withTemplate(InputStream templateInputStream) { public ExcelWriterBuilder withTemplate(InputStream templateInputStream) {
writeWorkbook.setTemplateInputStream(templateInputStream); writeWorkbook.setTemplateInputStream(templateInputStream);
return this; return this;

3
easyexcel-core/src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java

@ -37,7 +37,8 @@ public class WriteWorkbook extends WriteBasicParameter {
*/ */
private OutputStream outputStream; private OutputStream outputStream;
/** /**
* output charset * charset.
* Only work on the CSV file
*/ */
private Charset charset; private Charset charset;
/** /**

3
easyexcel-core/src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java

@ -80,7 +80,8 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
*/ */
private OutputStream outputStream; private OutputStream outputStream;
/** /**
* output charset * charset.
* Only work on the CSV file
*/ */
private Charset charset; private Charset charset;
/** /**

17
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/charset/CharsetData.java

@ -0,0 +1,17 @@
package com.alibaba.easyexcel.test.core.charset;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@EqualsAndHashCode
public class CharsetData {
@ExcelProperty("姓名")
private String name;
@ExcelProperty("年纪")
private Integer age;
}

119
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/charset/CharsetDataTest.java

@ -0,0 +1,119 @@
package com.alibaba.easyexcel.test.core.charset;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.alibaba.easyexcel.test.core.simple.SimpleData;
import com.alibaba.easyexcel.test.core.simple.SimpleDataListener;
import com.alibaba.easyexcel.test.demo.read.DemoData;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.read.listener.PageReadListener;
import com.alibaba.excel.read.listener.ReadListener;
import com.alibaba.excel.util.ConverterUtils;
import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Charsets;
import org.apache.commons.compress.utils.Lists;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
/**
* charset
*
* @author Jiaju Zhuang
*/
@Slf4j
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class CharsetDataTest {
private static final Charset GBK = Charset.forName("GBK");
private static File fileCsvGbk;
private static File fileCsvUtf8;
private static File fileCsvError;
@BeforeClass
public static void init() {
fileCsvGbk = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvGbk.csv");
fileCsvUtf8 = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvUtf8.csv");
fileCsvError = TestFileUtil.createNewFile("charset" + File.separator + "fileCsvError.csv");
}
@Test
public void t01ReadAndWriteCsv() {
readAndWrite(fileCsvGbk, GBK);
readAndWrite(fileCsvUtf8, StandardCharsets.UTF_8);
}
@Test
public void t02ReadAndWriteCsvError() {
EasyExcel.write(fileCsvError, CharsetData.class).charset(GBK).sheet().doWrite(data());
EasyExcel.read(fileCsvError, CharsetData.class, new ReadListener<CharsetData>() {
private final List<CharsetData> dataList = Lists.newArrayList();
@Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
String head = headMap.get(0).getStringValue();
Assert.assertNotEquals("姓名", head);
}
@Override
public void invoke(CharsetData data, AnalysisContext context) {
dataList.add(data);
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
}
}).charset(StandardCharsets.UTF_8).sheet().doRead();
}
private void readAndWrite(File file, Charset charset) {
EasyExcel.write(file, CharsetData.class).charset(charset).sheet().doWrite(data());
EasyExcel.read(file, CharsetData.class, new ReadListener<CharsetData>() {
private final List<CharsetData> dataList = Lists.newArrayList();
@Override
public void invokeHead(Map<Integer, ReadCellData<?>> headMap, AnalysisContext context) {
String head = headMap.get(0).getStringValue();
Assert.assertEquals("姓名", head);
}
@Override
public void invoke(CharsetData data, AnalysisContext context) {
dataList.add(data);
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
Assert.assertEquals(dataList.size(), 10);
CharsetData charsetData = dataList.get(0);
Assert.assertEquals("姓名0", charsetData.getName());
Assert.assertEquals(0, (long)charsetData.getAge());
}
}).charset(charset).sheet().doRead();
}
private List<CharsetData> data() {
List<CharsetData> list = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
CharsetData data = new CharsetData();
data.setName("姓名" + i);
data.setAge(i);
list.add(data);
}
return list;
}
}

8
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java

@ -61,17 +61,17 @@ public class ConverterDataTest {
@Test @Test
public void t11ReadAllConverter07() { public void t11ReadAllConverter07() {
readAllConverter("easyexcel-test/test/resources/converter" + File.separator + "converter07.xlsx"); readAllConverter("converter" + File.separator + "converter07.xlsx");
} }
@Test @Test
public void t12ReadAllConverter03() { public void t12ReadAllConverter03() {
readAllConverter("easyexcel-test/test/resources/converter" + File.separator + "converter03.xls"); readAllConverter("converter" + File.separator + "converter03.xls");
} }
@Test @Test
public void t13ReadAllConverterCsv() { public void t13ReadAllConverterCsv() {
readAllConverter("easyexcel-test/test/resources/converter" + File.separator + "converterCsv.csv"); readAllConverter("converter" + File.separator + "converterCsv.csv");
} }
@Test @Test
@ -90,7 +90,7 @@ public class ConverterDataTest {
List<ImageData> list = new ArrayList<>(); List<ImageData> list = new ArrayList<>();
ImageData imageData = new ImageData(); ImageData imageData = new ImageData();
list.add(imageData); list.add(imageData);
String imagePath = TestFileUtil.getPath() + "easyexcel-test/test/resources/converter" + File.separator + "img.jpg"; String imagePath = TestFileUtil.getPath() + "converter" + File.separator + "img.jpg";
imageData.setByteArray(FileUtils.readFileToByteArray(new File(imagePath))); imageData.setByteArray(FileUtils.readFileToByteArray(new File(imagePath)));
imageData.setFile(new File(imagePath)); imageData.setFile(new File(imagePath));
imageData.setString(imagePath); imageData.setString(imagePath);

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java

@ -26,8 +26,8 @@ public class DateFormatTest {
@BeforeClass @BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.readFile("easyexcel-test/test/resources/dataformat" + File.separator + "dataformat.xlsx"); file07 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xlsx");
file03 = TestFileUtil.readFile("easyexcel-test/test/resources/dataformat" + File.separator + "dataformat.xls"); file03 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xls");
} }
@Test @Test

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java

@ -22,8 +22,8 @@ public class ExtraDataTest {
@BeforeClass @BeforeClass
public static void init() { public static void init() {
file03 = TestFileUtil.readFile("easyexcel-test/test/resources/extra" + File.separator + "extra.xls"); file03 = TestFileUtil.readFile("extra" + File.separator + "extra.xls");
file07 = TestFileUtil.readFile("easyexcel-test/test/resources/extra" + File.separator + "extra.xlsx"); file07 = TestFileUtil.readFile("extra" + File.separator + "extra.xlsx");
} }
@Test @Test

22
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java

@ -56,25 +56,25 @@ public class FillDataTest {
file07 = TestFileUtil.createNewFile("fill07.xlsx"); file07 = TestFileUtil.createNewFile("fill07.xlsx");
file03 = TestFileUtil.createNewFile("fill03.xls"); file03 = TestFileUtil.createNewFile("fill03.xls");
fileCsv = TestFileUtil.createNewFile("fill.csv"); fileCsv = TestFileUtil.createNewFile("fill.csv");
simpleTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"); simpleTemplate07 = TestFileUtil.readFile("fill" + File.separator + "simple.xlsx");
simpleTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "simple.xls"); simpleTemplate03 = TestFileUtil.readFile("fill" + File.separator + "simple.xls");
simpleTemplateCsv = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "simple.csv"); simpleTemplateCsv = TestFileUtil.readFile("fill" + File.separator + "simple.csv");
fileComplex07 = TestFileUtil.createNewFile("fillComplex07.xlsx"); fileComplex07 = TestFileUtil.createNewFile("fillComplex07.xlsx");
complexFillTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "complex.xlsx"); complexFillTemplate07 = TestFileUtil.readFile("fill" + File.separator + "complex.xlsx");
fileComplex03 = TestFileUtil.createNewFile("fillComplex03.xls"); fileComplex03 = TestFileUtil.createNewFile("fillComplex03.xls");
complexFillTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "complex.xls"); complexFillTemplate03 = TestFileUtil.readFile("fill" + File.separator + "complex.xls");
fileHorizontal07 = TestFileUtil.createNewFile("fillHorizontal07.xlsx"); fileHorizontal07 = TestFileUtil.createNewFile("fillHorizontal07.xlsx");
horizontalFillTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "horizontal.xlsx"); horizontalFillTemplate07 = TestFileUtil.readFile("fill" + File.separator + "horizontal.xlsx");
fileHorizontal03 = TestFileUtil.createNewFile("fillHorizontal03.xls"); fileHorizontal03 = TestFileUtil.createNewFile("fillHorizontal03.xls");
horizontalFillTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "horizontal.xls"); horizontalFillTemplate03 = TestFileUtil.readFile("fill" + File.separator + "horizontal.xls");
byName07 = TestFileUtil.createNewFile("byName07.xlsx"); byName07 = TestFileUtil.createNewFile("byName07.xlsx");
byNameTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "byName.xlsx"); byNameTemplate07 = TestFileUtil.readFile("fill" + File.separator + "byName.xlsx");
byName03 = TestFileUtil.createNewFile("byName03.xls"); byName03 = TestFileUtil.createNewFile("byName03.xls");
byNameTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "byName.xls"); byNameTemplate03 = TestFileUtil.readFile("fill" + File.separator + "byName.xls");
fileComposite07 = TestFileUtil.createNewFile("fileComposite07.xlsx"); fileComposite07 = TestFileUtil.createNewFile("fileComposite07.xlsx");
compositeFillTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "composite.xlsx"); compositeFillTemplate07 = TestFileUtil.readFile("fill" + File.separator + "composite.xlsx");
fileComposite03 = TestFileUtil.createNewFile("fileComposite03.xls"); fileComposite03 = TestFileUtil.createNewFile("fileComposite03.xls");
compositeFillTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "composite.xls"); compositeFillTemplate03 = TestFileUtil.readFile("fill" + File.separator + "composite.xls");
} }
@Test @Test

6
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java

@ -44,8 +44,8 @@ public class FillAnnotationDataTest {
public static void init() { public static void init() {
file07 = TestFileUtil.createNewFile("fillAnnotation07.xlsx"); file07 = TestFileUtil.createNewFile("fillAnnotation07.xlsx");
file03 = TestFileUtil.createNewFile("fillAnnotation03.xls"); file03 = TestFileUtil.createNewFile("fillAnnotation03.xls");
fileTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "annotation.xlsx"); fileTemplate07 = TestFileUtil.readFile("fill" + File.separator + "annotation.xlsx");
fileTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "annotation.xls"); fileTemplate03 = TestFileUtil.readFile("fill" + File.separator + "annotation.xls");
} }
@Test @Test
@ -110,7 +110,7 @@ public class FillAnnotationDataTest {
data.setNumber(99.99); data.setNumber(99.99);
data.setString1("string1"); data.setString1("string1");
data.setString2("string2"); data.setString2("string2");
data.setImage(TestFileUtil.getPath() + "easyexcel-test/test/resources/converter" + File.separator + "img.jpg"); data.setImage(TestFileUtil.getPath() + "converter" + File.separator + "img.jpg");
list.add(data); list.add(data);
list.add(data); list.add(data);
list.add(data); list.add(data);

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java

@ -46,8 +46,8 @@ public class FillStyleAnnotatedTest {
public static void init() { public static void init() {
FillStyleAnnotated07 = TestFileUtil.createNewFile("FillStyleAnnotated07.xlsx"); FillStyleAnnotated07 = TestFileUtil.createNewFile("FillStyleAnnotated07.xlsx");
FillStyleAnnotated03 = TestFileUtil.createNewFile("FillStyleAnnotated03.xls"); FillStyleAnnotated03 = TestFileUtil.createNewFile("FillStyleAnnotated03.xls");
fileStyleTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xlsx"); fileStyleTemplate07 = TestFileUtil.readFile("fill" + File.separator + "style.xlsx");
fileStyleTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xls"); fileStyleTemplate03 = TestFileUtil.readFile("fill" + File.separator + "style.xls");
} }
@Test @Test

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java

@ -49,8 +49,8 @@ public class FillStyleDataTest {
fileStyle03 = TestFileUtil.createNewFile("fileStyle03.xls"); fileStyle03 = TestFileUtil.createNewFile("fileStyle03.xls");
fileStyleHandler07 = TestFileUtil.createNewFile("fileStyleHandler07.xlsx"); fileStyleHandler07 = TestFileUtil.createNewFile("fileStyleHandler07.xlsx");
fileStyleHandler03 = TestFileUtil.createNewFile("fileStyleHandler03.xls"); fileStyleHandler03 = TestFileUtil.createNewFile("fileStyleHandler03.xls");
fileStyleTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xlsx"); fileStyleTemplate07 = TestFileUtil.readFile("fill" + File.separator + "style.xlsx");
fileStyleTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xls"); fileStyleTemplate03 = TestFileUtil.readFile("fill" + File.separator + "style.xls");
} }
@Test @Test

10
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java

@ -40,17 +40,17 @@ public class LargeDataTest {
@BeforeClass @BeforeClass
public static void init() { public static void init() {
fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx"); fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx");
fileWrite07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWrite07.xlsx"); fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx");
fileWriteTemp07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWriteTemp07.xlsx"); fileWriteTemp07 = TestFileUtil.createNewFile("large" + File.separator + "fileWriteTemp07.xlsx");
fileWritePoi07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWritePoi07.xlsx"); fileWritePoi07 = TestFileUtil.createNewFile("large" + File.separator + "fileWritePoi07.xlsx");
template07 = TestFileUtil.readFile("easyexcel-test/test/resources/large" + File.separator + "fill.xlsx"); template07 = TestFileUtil.readFile("large" + File.separator + "fill.xlsx");
fileCsv = TestFileUtil.createNewFile("largefileCsv.csv"); fileCsv = TestFileUtil.createNewFile("largefileCsv.csv");
} }
@Test @Test
public void t01Read() throws Exception { public void t01Read() throws Exception {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
EasyExcel.read(TestFileUtil.getPath() + "easyexcel-test/test/resources/large" + File.separator + "large07.xlsx", LargeData.class, EasyExcel.read(TestFileUtil.getPath() + "large" + File.separator + "large07.xlsx", LargeData.class,
new LargeDataListener()).headRowNumber(2).sheet().doRead(); new LargeDataListener()).headRowNumber(2).sheet().doRead();
LOGGER.info("Large data total time spent:{}", System.currentTimeMillis() - start); LOGGER.info("Large data total time spent:{}", System.currentTimeMillis() - start);
} }

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java

@ -26,8 +26,8 @@ public class MultipleSheetsDataTest {
@BeforeClass @BeforeClass
public static void init() { public static void init() {
file07 = TestFileUtil.readFile("easyexcel-test/test/resources/multiplesheets" + File.separator + "multiplesheets.xlsx"); file07 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xlsx");
file03 = TestFileUtil.readFile("easyexcel-test/test/resources/multiplesheets" + File.separator + "multiplesheets.xls"); file03 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xls");
} }
@Test @Test

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java

@ -90,8 +90,8 @@ public class SimpleDataTest {
@Test @Test
public void t21SheetNameRead07() { public void t21SheetNameRead07() {
EasyExcel.read(TestFileUtil.readFile("easyexcel-test/test/resources/simple" + File.separator + "simple07.xlsx"), SimpleData.class, EasyExcel.read(TestFileUtil.readFile("simple" + File.separator + "simple07.xlsx"), SimpleData.class,
new SimpleDataSheetNameListener()).sheet("easyexcel-test/test/resources/simple").doRead(); new SimpleDataSheetNameListener()).sheet("simple").doRead();
} }
private void synchronousRead(File file) { private void synchronousRead(File file) {

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java

@ -41,14 +41,14 @@ public class TemplateDataTest {
private void readAndWrite07(File file) { private void readAndWrite07(File file) {
EasyExcel.write(file, TemplateData.class) EasyExcel.write(file, TemplateData.class)
.withTemplate(TestFileUtil.readFile("easyexcel-test/test/resources/template" + File.separator + "template07.xlsx")).sheet() .withTemplate(TestFileUtil.readFile("template" + File.separator + "template07.xlsx")).sheet()
.doWrite(data()); .doWrite(data());
EasyExcel.read(file, TemplateData.class, new TemplateDataListener()).headRowNumber(3).sheet().doRead(); EasyExcel.read(file, TemplateData.class, new TemplateDataListener()).headRowNumber(3).sheet().doRead();
} }
private void readAndWrite03(File file) { private void readAndWrite03(File file) {
EasyExcel.write(file, TemplateData.class) EasyExcel.write(file, TemplateData.class)
.withTemplate(TestFileUtil.readFile("easyexcel-test/test/resources/template" + File.separator + "template03.xls")).sheet() .withTemplate(TestFileUtil.readFile("template" + File.separator + "template03.xls")).sheet()
.doWrite(data()); .doWrite(data());
EasyExcel.read(file, TemplateData.class, new TemplateDataListener()).headRowNumber(3).sheet().doRead(); EasyExcel.read(file, TemplateData.class, new TemplateDataListener()).headRowNumber(3).sheet().doRead();
} }

12
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java

@ -36,7 +36,7 @@ public class FillTest {
public void simpleFill() { public void simpleFill() {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "simple.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "simple.xlsx";
// 方案1 根据对象填充 // 方案1 根据对象填充
String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx";
@ -65,7 +65,7 @@ public class FillTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// 填充list 的时候还要注意 模板中{.} 多了个点 表示list // 填充list 的时候还要注意 模板中{.} 多了个点 表示list
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "list.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "list.xlsx";
// 方案1 一下子全部放到内存里面 并填充 // 方案1 一下子全部放到内存里面 并填充
String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx";
@ -103,7 +103,7 @@ public class FillTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量 // {} 代表普通变量 {.} 代表是list的变量
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "complex.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complex.xlsx";
String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
@ -135,7 +135,7 @@ public class FillTest {
// {} 代表普通变量 {.} 代表是list的变量 // {} 代表普通变量 {.} 代表是list的变量
// 这里模板 删除了list以后的数据,也就是统计的这一行 // 这里模板 删除了list以后的数据,也就是统计的这一行
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "complexFillWithTable.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complexFillWithTable.xlsx";
String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
@ -176,7 +176,7 @@ public class FillTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量 // {} 代表普通变量 {.} 代表是list的变量
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "horizontal.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "horizontal.xlsx";
String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
@ -203,7 +203,7 @@ public class FillTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "composite.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "composite.xlsx";
String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();

30
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java

@ -45,7 +45,7 @@ public class ReadTest {
public void simpleRead() { public void simpleRead() {
// 写法1:JDK8+ ,不用额外写一个DemoDataListener // 写法1:JDK8+ ,不用额外写一个DemoDataListener
// since: 3.0.0-beta1 // since: 3.0.0-beta1
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
// 这里每次会读取3000条数据 然后返回过来 直接调用使用数据就行 // 这里每次会读取3000条数据 然后返回过来 直接调用使用数据就行
EasyExcel.read(fileName, DemoData.class, new PageReadListener<DemoData>(dataList -> { EasyExcel.read(fileName, DemoData.class, new PageReadListener<DemoData>(dataList -> {
@ -56,7 +56,7 @@ public class ReadTest {
// 写法2: // 写法2:
// 匿名内部类 不用额外写一个DemoDataListener // 匿名内部类 不用额外写一个DemoDataListener
fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
EasyExcel.read(fileName, DemoData.class, new ReadListener<DemoData>() { EasyExcel.read(fileName, DemoData.class, new ReadListener<DemoData>() {
/** /**
@ -94,12 +94,12 @@ public class ReadTest {
// 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去 // 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去
// 写法3: // 写法3:
fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭
EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead(); EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead();
// 写法4: // 写法4:
fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 一个文件一个reader // 一个文件一个reader
ExcelReader excelReader = null; ExcelReader excelReader = null;
try { try {
@ -128,7 +128,7 @@ public class ReadTest {
*/ */
@Test @Test
public void indexOrNameRead() { public void indexOrNameRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里默认读取第一个sheet // 这里默认读取第一个sheet
EasyExcel.read(fileName, IndexOrNameData.class, new IndexOrNameDataListener()).sheet().doRead(); EasyExcel.read(fileName, IndexOrNameData.class, new IndexOrNameDataListener()).sheet().doRead();
} }
@ -144,13 +144,13 @@ public class ReadTest {
*/ */
@Test @Test
public void repeatedRead() { public void repeatedRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 读取全部sheet // 读取全部sheet
// 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写 // 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写
EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).doReadAll(); EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).doReadAll();
// 读取部分sheet // 读取部分sheet
fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
ExcelReader excelReader = null; ExcelReader excelReader = null;
try { try {
excelReader = EasyExcel.read(fileName).build(); excelReader = EasyExcel.read(fileName).build();
@ -183,7 +183,7 @@ public class ReadTest {
*/ */
@Test @Test
public void converterRead() { public void converterRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet // 这里 需要指定读用哪个class去读,然后读取第一个sheet
EasyExcel.read(fileName, ConverterData.class, new ConverterDataListener()) EasyExcel.read(fileName, ConverterData.class, new ConverterDataListener())
// 这里注意 我们也可以registerConverter来指定自定义转换器, 但是这个转换变成全局了, 所有java为string,excel为string的都会用这个转换器。 // 这里注意 我们也可以registerConverter来指定自定义转换器, 但是这个转换变成全局了, 所有java为string,excel为string的都会用这个转换器。
@ -206,7 +206,7 @@ public class ReadTest {
*/ */
@Test @Test
public void complexHeaderRead() { public void complexHeaderRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet // 这里 需要指定读用哪个class去读,然后读取第一个sheet
EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet() EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet()
// 这里可以设置1,因为头就是一行。如果多行头,可以设置其他值。不传入也可以,因为默认会根据DemoData 来解析,他没有指定头,也就是默认1行 // 这里可以设置1,因为头就是一行。如果多行头,可以设置其他值。不传入也可以,因为默认会根据DemoData 来解析,他没有指定头,也就是默认1行
@ -225,7 +225,7 @@ public class ReadTest {
*/ */
@Test @Test
public void headerRead() { public void headerRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet // 这里 需要指定读用哪个class去读,然后读取第一个sheet
EasyExcel.read(fileName, DemoData.class, new DemoHeadDataListener()).sheet().doRead(); EasyExcel.read(fileName, DemoData.class, new DemoHeadDataListener()).sheet().doRead();
} }
@ -246,7 +246,7 @@ public class ReadTest {
*/ */
@Test @Test
public void extraRead() { public void extraRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "extra.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "extra.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet // 这里 需要指定读用哪个class去读,然后读取第一个sheet
EasyExcel.read(fileName, DemoExtraData.class, new DemoExtraListener()) EasyExcel.read(fileName, DemoExtraData.class, new DemoExtraListener())
// 需要读取批注 默认不读取 // 需要读取批注 默认不读取
@ -271,7 +271,7 @@ public class ReadTest {
*/ */
@Test @Test
public void cellDataRead() { public void cellDataRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "cellDataDemo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "cellDataDemo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet // 这里 需要指定读用哪个class去读,然后读取第一个sheet
EasyExcel.read(fileName, CellDataReadDemoData.class, new CellDataDemoHeadDataListener()).sheet().doRead(); EasyExcel.read(fileName, CellDataReadDemoData.class, new CellDataDemoHeadDataListener()).sheet().doRead();
} }
@ -288,7 +288,7 @@ public class ReadTest {
*/ */
@Test @Test
public void exceptionRead() { public void exceptionRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet // 这里 需要指定读用哪个class去读,然后读取第一个sheet
EasyExcel.read(fileName, ExceptionDemoData.class, new DemoExceptionListener()).sheet().doRead(); EasyExcel.read(fileName, ExceptionDemoData.class, new DemoExceptionListener()).sheet().doRead();
} }
@ -298,7 +298,7 @@ public class ReadTest {
*/ */
@Test @Test
public void synchronousRead() { public void synchronousRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 需要指定读用哪个class去读,然后读取第一个sheet 同步读取会自动finish // 这里 需要指定读用哪个class去读,然后读取第一个sheet 同步读取会自动finish
List<DemoData> list = EasyExcel.read(fileName).head(DemoData.class).sheet().doReadSync(); List<DemoData> list = EasyExcel.read(fileName).head(DemoData.class).sheet().doReadSync();
for (DemoData data : list) { for (DemoData data : list) {
@ -318,7 +318,7 @@ public class ReadTest {
*/ */
@Test @Test
public void noModelRead() { public void noModelRead() {
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
// 这里 只要,然后读取第一个sheet 同步读取会自动finish // 这里 只要,然后读取第一个sheet 同步读取会自动finish
EasyExcel.read(fileName, new NoModelDataListener()).sheet().doRead(); EasyExcel.read(fileName, new NoModelDataListener()).sheet().doRead();
} }

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java

@ -267,7 +267,7 @@ public class WriteTest {
public void imageWrite() throws Exception { public void imageWrite() throws Exception {
String fileName = TestFileUtil.getPath() + "imageWrite" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "imageWrite" + System.currentTimeMillis() + ".xlsx";
String imagePath = TestFileUtil.getPath() + "easyexcel-test/test/resources/converter" + File.separator + "img.jpg"; String imagePath = TestFileUtil.getPath() + "converter" + File.separator + "img.jpg";
try (InputStream inputStream = FileUtils.openInputStream(new File(imagePath))) { try (InputStream inputStream = FileUtils.openInputStream(new File(imagePath))) {
List<ImageDemoData> list = ListUtils.newArrayList(); List<ImageDemoData> list = ListUtils.newArrayList();
ImageDemoData imageDemoData = new ImageDemoData(); ImageDemoData imageDemoData = new ImageDemoData();
@ -419,7 +419,7 @@ public class WriteTest {
*/ */
@Test @Test
public void templateWrite() { public void templateWrite() {
String templateFileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; String templateFileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx";
String fileName = TestFileUtil.getPath() + "templateWrite" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "templateWrite" + System.currentTimeMillis() + ".xlsx";
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel.write(fileName, DemoData.class).withTemplate(templateFileName).sheet().doWrite(data()); EasyExcel.write(fileName, DemoData.class).withTemplate(templateFileName).sheet().doWrite(data());

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java

@ -33,7 +33,7 @@ public class WriteLargeTest {
@Test @Test
public void test() throws Exception { public void test() throws Exception {
// 方法2 如果写到不同的sheet 同一个对象 // 方法2 如果写到不同的sheet 同一个对象
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/large" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "large" + System.currentTimeMillis() + ".xlsx";
// 头的策略 // 头的策略
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// 背景设置为红色 // 背景设置为红色
@ -69,7 +69,7 @@ public class WriteLargeTest {
@Test @Test
public void test2() throws Exception { public void test2() throws Exception {
// 方法2 如果写到不同的sheet 同一个对象 // 方法2 如果写到不同的sheet 同一个对象
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/large" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "large" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName, LargeData.class).build(); ExcelWriter excelWriter = EasyExcel.write(fileName, LargeData.class).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build(); WriteSheet writeSheet = EasyExcel.writerSheet().build();

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java

@ -132,7 +132,7 @@ public class DataFormatTest {
@Test @Test
public void test355() throws IOException, InvalidFormatException { public void test355() throws IOException, InvalidFormatException {
File file = TestFileUtil.readFile("easyexcel-test/test/resources/dataformat" + File.separator + "dataformat.xlsx"); File file = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xlsx");
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file);
Sheet xssfSheet = xssfWorkbook.getSheetAt(0); Sheet xssfSheet = xssfWorkbook.getSheetAt(0);
DataFormatter d = new DataFormatter(Locale.CHINA); DataFormatter d = new DataFormatter(Locale.CHINA);

10
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java

@ -64,7 +64,7 @@ public class FillTempTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// 填充list 的时候还要注意 模板中{.} 多了个点 表示list // 填充list 的时候还要注意 模板中{.} 多了个点 表示list
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "list.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "list.xlsx";
// 方案1 一下子全部放到内存里面 并填充 // 方案1 一下子全部放到内存里面 并填充
String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx";
@ -91,7 +91,7 @@ public class FillTempTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量 // {} 代表普通变量 {.} 代表是list的变量
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "complex.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complex.xlsx";
String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "complexFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
@ -123,7 +123,7 @@ public class FillTempTest {
// {} 代表普通变量 {.} 代表是list的变量 // {} 代表普通变量 {.} 代表是list的变量
// 这里模板 删除了list以后的数据,也就是统计的这一行 // 这里模板 删除了list以后的数据,也就是统计的这一行
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "complexFillWithTable.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "complexFillWithTable.xlsx";
String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "complexFillWithTable" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
@ -164,7 +164,7 @@ public class FillTempTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量 // {} 代表普通变量 {.} 代表是list的变量
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "horizontal.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "horizontal.xlsx";
String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "horizontalFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
@ -191,7 +191,7 @@ public class FillTempTest {
// 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
// {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "fill" + File.separator + "composite.xlsx"; TestFileUtil.getPath() + "demo" + File.separator + "fill" + File.separator + "composite.xlsx";
String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx"; String fileName = TestFileUtil.getPath() + "compositeFill" + System.currentTimeMillis() + ".xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();

4
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java

@ -23,9 +23,9 @@ public class FillTest {
@Test @Test
public void TestFillNullPoint(){ public void TestFillNullPoint(){
String templateFileName = String templateFileName =
TestFileUtil.getPath() + "easyexcel-test/test/resources/temp/issue1663" + File.separator + "template.xlsx"; TestFileUtil.getPath() + "temp/issue1663" + File.separator + "template.xlsx";
String fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/temp/issue1663" + File.separator + "issue1663.xlsx"; String fileName = TestFileUtil.getPath() + "temp/issue1663" + File.separator + "issue1663.xlsx";
ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build(); WriteSheet writeSheet = EasyExcel.writerSheet().build();
FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build();

8
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java

@ -45,10 +45,10 @@ public class TempLargeDataTest {
@BeforeClass @BeforeClass
public static void init() { public static void init() {
fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx"); fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx");
fileWrite07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWrite07.xlsx"); fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx");
fileWriteTemp07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWriteTemp07.xlsx"); fileWriteTemp07 = TestFileUtil.createNewFile("large" + File.separator + "fileWriteTemp07.xlsx");
fileWritePoi07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWritePoi07.xlsx"); fileWritePoi07 = TestFileUtil.createNewFile("large" + File.separator + "fileWritePoi07.xlsx");
template07 = TestFileUtil.readFile("easyexcel-test/test/resources/large" + File.separator + "fill.xlsx"); template07 = TestFileUtil.readFile("large" + File.separator + "fill.xlsx");
fileCsv = TestFileUtil.createNewFile("largefileCsv.csv"); fileCsv = TestFileUtil.createNewFile("largefileCsv.csv");
} }

2
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java

@ -30,7 +30,7 @@ public class Poi3Test {
@Test @Test
public void Encryption() throws Exception { public void Encryption() throws Exception {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/large" + File.separator + "large07.xlsx"; String file = TestFileUtil.getPath() + "large" + File.separator + "large07.xlsx";
POIFSFileSystem fs = new POIFSFileSystem(); POIFSFileSystem fs = new POIFSFileSystem();
EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile);
Encryptor enc = info.getEncryptor(); Encryptor enc = info.getEncryptor();

18
easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java

@ -176,7 +176,7 @@ public class PoiTest {
@Test @Test
public void lastRowNum233() throws IOException { public void lastRowNum233() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
Workbook xx = new XSSFWorkbook(file); Workbook xx = new XSSFWorkbook(file);
System.out.println(new File(file).exists()); System.out.println(new File(file).exists());
@ -231,7 +231,7 @@ public class PoiTest {
@Test @Test
public void lastRowNum2333() throws IOException, InvalidFormatException { public void lastRowNum2333() throws IOException, InvalidFormatException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file)); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file));
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook);
Sheet xssfSheet = xssfWorkbook.getSheetAt(0); Sheet xssfSheet = xssfWorkbook.getSheetAt(0);
@ -248,14 +248,14 @@ public class PoiTest {
@Test @Test
public void testread() throws IOException { public void testread() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file));
Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0);
// //
// Cell cell = xssfSheet.getRow(0).createCell(9); // Cell cell = xssfSheet.getRow(0).createCell(9);
String file1 = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file1 = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
SXSSFWorkbook xssfWorkbook1 = new SXSSFWorkbook(new XSSFWorkbook(file1)); SXSSFWorkbook xssfWorkbook1 = new SXSSFWorkbook(new XSSFWorkbook(file1));
Sheet xssfSheet1 = xssfWorkbook1.getXSSFWorkbook().getSheetAt(0); Sheet xssfSheet1 = xssfWorkbook1.getXSSFWorkbook().getSheetAt(0);
@ -268,13 +268,13 @@ public class PoiTest {
@Test @Test
public void testreadRead() throws IOException { public void testreadRead() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
FileUtils.readFileToByteArray(new File(file)); FileUtils.readFileToByteArray(new File(file));
} }
@Test @Test
public void lastRowNum2332222() throws IOException { public void lastRowNum2332222() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file));
Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0);
@ -287,7 +287,7 @@ public class PoiTest {
@Test @Test
public void lastRowNum23443() throws IOException { public void lastRowNum23443() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file));
Sheet xssfSheet = xssfWorkbook.getSheetAt(0); Sheet xssfSheet = xssfWorkbook.getSheetAt(0);
@ -298,7 +298,7 @@ public class PoiTest {
@Test @Test
public void lastRowNum2() throws IOException { public void lastRowNum2() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file));
Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0);
LOGGER.info("一共行数:{}", xssfSheet.getPhysicalNumberOfRows()); LOGGER.info("一共行数:{}", xssfSheet.getPhysicalNumberOfRows());
@ -309,7 +309,7 @@ public class PoiTest {
@Test @Test
public void lastRowNumXSSF2() throws IOException { public void lastRowNumXSSF2() throws IOException {
String file = TestFileUtil.getPath() + "easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"; String file = TestFileUtil.getPath() + "fill" + File.separator + "simple.xlsx";
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(file);
LOGGER.info("一共:{}个sheet", xssfWorkbook.getNumberOfSheets()); LOGGER.info("一共:{}个sheet", xssfWorkbook.getNumberOfSheets());
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);

1
update.md

@ -10,6 +10,7 @@
* 捕获`setFeature`异常不影响主流程 [Issue #2054](https://github.com/alibaba/easyexcel/issues/2054) * 捕获`setFeature`异常不影响主流程 [Issue #2054](https://github.com/alibaba/easyexcel/issues/2054)
* 增加部分`xls`容错 [Issue #2236](https://github.com/alibaba/easyexcel/issues/2236) * 增加部分`xls`容错 [Issue #2236](https://github.com/alibaba/easyexcel/issues/2236)
* 修复读取csv文件时`autoTrim`配置失效 [Issue #2227](https://github.com/alibaba/easyexcel/issues/2227) * 修复读取csv文件时`autoTrim`配置失效 [Issue #2227](https://github.com/alibaba/easyexcel/issues/2227)
* csv支持设置读写编码 [Issue #2404](https://github.com/alibaba/easyexcel/issues/2404)
# 3.0.5 # 3.0.5

Loading…
Cancel
Save