diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java index d77ab768..0f7f707a 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java +++ b/easyexcel-core/src/main/java/com/alibaba/excel/analysis/csv/CsvExcelReadExecutor.java @@ -1,8 +1,10 @@ package com.alibaba.excel.analysis.csv; +import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; @@ -84,12 +86,15 @@ public class CsvExcelReadExecutor implements ExcelReadExecutor { CSVFormat csvFormat = csvReadWorkbookHolder.getCsvFormat(); 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) { - 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) { diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java b/easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java index 0cb11009..d3bf472b 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/read/builder/ExcelReaderBuilder.java +++ b/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.InputStream; +import java.nio.charset.Charset; import java.util.HashSet; import java.util.List; @@ -38,11 +39,6 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder @@ -72,6 +68,15 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder @@ -156,10 +161,10 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder * 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 * @return + * @see SAXParserFactory#newInstance() + * @see SAXParserFactory#newInstance(String, ClassLoader) */ public ExcelReaderBuilder xlsxSAXParserFactoryName(String xlsxSAXParserFactoryName) { readWorkbook.setXlsxSAXParserFactoryName(xlsxSAXParserFactoryName); @@ -169,8 +174,7 @@ public class ExcelReaderBuilder extends AbstractExcelReaderParameterBuilder @@ -98,6 +104,4 @@ public class ReadWorkbook extends ReadBasicParameter { * @see CellExtraTypeEnum */ private Set extraReadSet; - - private String encoding; } diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java b/easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java index 7de30aa5..a84cc315 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/ReadWorkbookHolder.java +++ b/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.InputStream; +import java.nio.charset.Charset; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -51,6 +52,12 @@ public class ReadWorkbookHolder extends AbstractReadHolder { * If 'inputStream' and 'file' all not empty, file first */ private File file; + + /** + * charset. + * Only work on the CSV file + */ + private Charset charset; /** * Mandatory use 'inputStream' .Default is false. *

@@ -68,7 +75,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder { /** * This object can be read in the Listener {@link AnalysisEventListener#invoke(Object, AnalysisContext)} * {@link AnalysisContext#getCustom()} - * */ private Object customObject; /** @@ -122,6 +128,13 @@ public class ReadWorkbookHolder extends AbstractReadHolder { this.inputStream = readWorkbook.getInputStream(); } this.file = readWorkbook.getFile(); + + if (readWorkbook.getCharset() == null) { + this.charset = Charset.defaultCharset(); + } else { + this.charset = readWorkbook.getCharset(); + } + if (readWorkbook.getMandatoryUseInputStream() == null) { this.mandatoryUseInputStream = Boolean.FALSE; } else { @@ -160,7 +173,6 @@ public class ReadWorkbookHolder extends AbstractReadHolder { this.password = readWorkbook.getPassword(); } - @Override public HolderEnum holderType() { return HolderEnum.WORKBOOK; diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java b/easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java index 629ca81e..5923403b 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/read/metadata/holder/csv/CsvReadWorkbookHolder.java +++ b/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.util.StringUtils; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; @@ -25,13 +26,9 @@ public class CsvReadWorkbookHolder extends ReadWorkbookHolder { private CSVFormat csvFormat; private CSVParser csvParser; - - private String encoding; - public CsvReadWorkbookHolder(ReadWorkbook readWorkbook) { super(readWorkbook); setExcelType(ExcelTypeEnum.CSV); this.csvFormat = CSVFormat.DEFAULT; - this.encoding = StringUtils.isEmpty(readWorkbook.getEncoding())? CharsetNames.UTF_8:readWorkbook.getEncoding(); } } diff --git a/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java b/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java index dcd0a80d..f90e6cd7 100644 --- a/easyexcel-core/src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java +++ b/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.InputStream; import java.io.OutputStream; +import java.nio.charset.Charset; import com.alibaba.excel.ExcelWriter; +import com.alibaba.excel.read.builder.ExcelReaderBuilder; import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.write.metadata.WriteWorkbook; @@ -85,6 +87,15 @@ public class ExcelWriterBuilder extends AbstractExcelWriterParameterBuilder() { + + private final List dataList = Lists.newArrayList(); + + @Override + public void invokeHead(Map> 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() { + + private final List dataList = Lists.newArrayList(); + + @Override + public void invokeHead(Map> 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 data() { + List 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; + } +} diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java index e7418601..b2943522 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/converter/ConverterDataTest.java @@ -61,17 +61,17 @@ public class ConverterDataTest { @Test public void t11ReadAllConverter07() { - readAllConverter("easyexcel-test/test/resources/converter" + File.separator + "converter07.xlsx"); + readAllConverter("converter" + File.separator + "converter07.xlsx"); } @Test public void t12ReadAllConverter03() { - readAllConverter("easyexcel-test/test/resources/converter" + File.separator + "converter03.xls"); + readAllConverter("converter" + File.separator + "converter03.xls"); } @Test public void t13ReadAllConverterCsv() { - readAllConverter("easyexcel-test/test/resources/converter" + File.separator + "converterCsv.csv"); + readAllConverter("converter" + File.separator + "converterCsv.csv"); } @Test @@ -90,7 +90,7 @@ public class ConverterDataTest { List list = new ArrayList<>(); ImageData imageData = new 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.setFile(new File(imagePath)); imageData.setString(imagePath); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java index 7bd7bf8c..27494f29 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/dataformat/DateFormatTest.java @@ -26,8 +26,8 @@ public class DateFormatTest { @BeforeClass public static void init() { - file07 = TestFileUtil.readFile("easyexcel-test/test/resources/dataformat" + File.separator + "dataformat.xlsx"); - file03 = TestFileUtil.readFile("easyexcel-test/test/resources/dataformat" + File.separator + "dataformat.xls"); + file07 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xlsx"); + file03 = TestFileUtil.readFile("dataformat" + File.separator + "dataformat.xls"); } @Test diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java index 5f80abc1..cf7418d5 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/extra/ExtraDataTest.java @@ -22,8 +22,8 @@ public class ExtraDataTest { @BeforeClass public static void init() { - file03 = TestFileUtil.readFile("easyexcel-test/test/resources/extra" + File.separator + "extra.xls"); - file07 = TestFileUtil.readFile("easyexcel-test/test/resources/extra" + File.separator + "extra.xlsx"); + file03 = TestFileUtil.readFile("extra" + File.separator + "extra.xls"); + file07 = TestFileUtil.readFile("extra" + File.separator + "extra.xlsx"); } @Test diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java index e43dea10..e85d63a6 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/FillDataTest.java +++ b/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"); file03 = TestFileUtil.createNewFile("fill03.xls"); fileCsv = TestFileUtil.createNewFile("fill.csv"); - simpleTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "simple.xlsx"); - simpleTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "simple.xls"); - simpleTemplateCsv = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "simple.csv"); + simpleTemplate07 = TestFileUtil.readFile("fill" + File.separator + "simple.xlsx"); + simpleTemplate03 = TestFileUtil.readFile("fill" + File.separator + "simple.xls"); + simpleTemplateCsv = TestFileUtil.readFile("fill" + File.separator + "simple.csv"); 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"); - 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"); - 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"); - 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"); - 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"); - 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"); - 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"); - compositeFillTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "composite.xls"); + compositeFillTemplate03 = TestFileUtil.readFile("fill" + File.separator + "composite.xls"); } @Test diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java index 4be041f5..2106c0ef 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/annotation/FillAnnotationDataTest.java +++ b/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() { file07 = TestFileUtil.createNewFile("fillAnnotation07.xlsx"); file03 = TestFileUtil.createNewFile("fillAnnotation03.xls"); - fileTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "annotation.xlsx"); - fileTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "annotation.xls"); + fileTemplate07 = TestFileUtil.readFile("fill" + File.separator + "annotation.xlsx"); + fileTemplate03 = TestFileUtil.readFile("fill" + File.separator + "annotation.xls"); } @Test @@ -110,7 +110,7 @@ public class FillAnnotationDataTest { data.setNumber(99.99); data.setString1("string1"); 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); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java index 596dd33a..13367904 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleAnnotatedTest.java +++ b/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() { FillStyleAnnotated07 = TestFileUtil.createNewFile("FillStyleAnnotated07.xlsx"); FillStyleAnnotated03 = TestFileUtil.createNewFile("FillStyleAnnotated03.xls"); - fileStyleTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xlsx"); - fileStyleTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xls"); + fileStyleTemplate07 = TestFileUtil.readFile("fill" + File.separator + "style.xlsx"); + fileStyleTemplate03 = TestFileUtil.readFile("fill" + File.separator + "style.xls"); } @Test diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java index 149d9963..210a5b9f 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/fill/style/FillStyleDataTest.java +++ b/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"); fileStyleHandler07 = TestFileUtil.createNewFile("fileStyleHandler07.xlsx"); fileStyleHandler03 = TestFileUtil.createNewFile("fileStyleHandler03.xls"); - fileStyleTemplate07 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xlsx"); - fileStyleTemplate03 = TestFileUtil.readFile("easyexcel-test/test/resources/fill" + File.separator + "style.xls"); + fileStyleTemplate07 = TestFileUtil.readFile("fill" + File.separator + "style.xlsx"); + fileStyleTemplate03 = TestFileUtil.readFile("fill" + File.separator + "style.xls"); } @Test diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java index 24ab53b5..c7f202e5 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java @@ -40,17 +40,17 @@ public class LargeDataTest { @BeforeClass public static void init() { fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx"); - fileWrite07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWrite07.xlsx"); - fileWriteTemp07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWriteTemp07.xlsx"); - fileWritePoi07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWritePoi07.xlsx"); - template07 = TestFileUtil.readFile("easyexcel-test/test/resources/large" + File.separator + "fill.xlsx"); + fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx"); + fileWriteTemp07 = TestFileUtil.createNewFile("large" + File.separator + "fileWriteTemp07.xlsx"); + fileWritePoi07 = TestFileUtil.createNewFile("large" + File.separator + "fileWritePoi07.xlsx"); + template07 = TestFileUtil.readFile("large" + File.separator + "fill.xlsx"); fileCsv = TestFileUtil.createNewFile("largefileCsv.csv"); } @Test public void t01Read() throws Exception { 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(); LOGGER.info("Large data total time spent:{}", System.currentTimeMillis() - start); } diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java index 1ff9ce94..c69e3ae4 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java @@ -26,8 +26,8 @@ public class MultipleSheetsDataTest { @BeforeClass public static void init() { - file07 = TestFileUtil.readFile("easyexcel-test/test/resources/multiplesheets" + File.separator + "multiplesheets.xlsx"); - file03 = TestFileUtil.readFile("easyexcel-test/test/resources/multiplesheets" + File.separator + "multiplesheets.xls"); + file07 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xlsx"); + file03 = TestFileUtil.readFile("multiplesheets" + File.separator + "multiplesheets.xls"); } @Test diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java index e6b56380..80277545 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java @@ -90,8 +90,8 @@ public class SimpleDataTest { @Test public void t21SheetNameRead07() { - EasyExcel.read(TestFileUtil.readFile("easyexcel-test/test/resources/simple" + File.separator + "simple07.xlsx"), SimpleData.class, - new SimpleDataSheetNameListener()).sheet("easyexcel-test/test/resources/simple").doRead(); + EasyExcel.read(TestFileUtil.readFile("simple" + File.separator + "simple07.xlsx"), SimpleData.class, + new SimpleDataSheetNameListener()).sheet("simple").doRead(); } private void synchronousRead(File file) { diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java index 3cc041b8..d6ebd0aa 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java +++ b/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) { 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()); EasyExcel.read(file, TemplateData.class, new TemplateDataListener()).headRowNumber(3).sheet().doRead(); } private void readAndWrite03(File file) { 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()); EasyExcel.read(file, TemplateData.class, new TemplateDataListener()).headRowNumber(3).sheet().doRead(); } diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java index c16a2725..d0f90fe9 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/fill/FillTest.java @@ -36,7 +36,7 @@ public class FillTest { public void simpleFill() { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 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 根据对象填充 String fileName = TestFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx"; @@ -65,7 +65,7 @@ public class FillTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 填充list 的时候还要注意 模板中{.} 多了个点 表示list 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 一下子全部放到内存里面 并填充 String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; @@ -103,7 +103,7 @@ public class FillTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // {} 代表普通变量 {.} 代表是list的变量 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); @@ -135,7 +135,7 @@ public class FillTest { // {} 代表普通变量 {.} 代表是list的变量 // 这里模板 删除了list以后的数据,也就是统计的这一行 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); @@ -176,7 +176,7 @@ public class FillTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // {} 代表普通变量 {.} 代表是list的变量 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); @@ -203,7 +203,7 @@ public class FillTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java index bf56f274..a97d2c1e 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/read/ReadTest.java @@ -45,7 +45,7 @@ public class ReadTest { public void simpleRead() { // 写法1:JDK8+ ,不用额外写一个DemoDataListener // 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 文件流会自动关闭 // 这里每次会读取3000条数据 然后返回过来 直接调用使用数据就行 EasyExcel.read(fileName, DemoData.class, new PageReadListener(dataList -> { @@ -56,7 +56,7 @@ public class ReadTest { // 写法2: // 匿名内部类 不用额外写一个DemoDataListener - fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; + fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx"; // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 EasyExcel.read(fileName, DemoData.class, new ReadListener() { /** @@ -94,12 +94,12 @@ public class ReadTest { // 有个很重要的点 DemoDataListener 不能被spring管理,要每次读取excel都要new,然后里面用到spring可以构造方法传进去 // 写法3: - fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; + fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx"; // 这里 需要指定读用哪个class去读,然后读取第一个sheet 文件流会自动关闭 EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet().doRead(); // 写法4: - fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; + fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx"; // 一个文件一个reader ExcelReader excelReader = null; try { @@ -128,7 +128,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, IndexOrNameData.class, new IndexOrNameDataListener()).sheet().doRead(); } @@ -144,13 +144,13 @@ public class ReadTest { */ @Test 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 // 这里需要注意 DemoDataListener的doAfterAllAnalysed 会在每个sheet读取完毕后调用一次。然后所有sheet都会往同一个DemoDataListener里面写 EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).doReadAll(); // 读取部分sheet - fileName = TestFileUtil.getPath() + "easyexcel-test/test/resources/demo" + File.separator + "demo.xlsx"; + fileName = TestFileUtil.getPath() + "demo" + File.separator + "demo.xlsx"; ExcelReader excelReader = null; try { excelReader = EasyExcel.read(fileName).build(); @@ -183,7 +183,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, ConverterData.class, new ConverterDataListener()) // 这里注意 我们也可以registerConverter来指定自定义转换器, 但是这个转换变成全局了, 所有java为string,excel为string的都会用这个转换器。 @@ -206,7 +206,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, DemoData.class, new DemoDataListener()).sheet() // 这里可以设置1,因为头就是一行。如果多行头,可以设置其他值。不传入也可以,因为默认会根据DemoData 来解析,他没有指定头,也就是默认1行 @@ -225,7 +225,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, DemoData.class, new DemoHeadDataListener()).sheet().doRead(); } @@ -246,7 +246,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, DemoExtraData.class, new DemoExtraListener()) // 需要读取批注 默认不读取 @@ -271,7 +271,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, CellDataReadDemoData.class, new CellDataDemoHeadDataListener()).sheet().doRead(); } @@ -288,7 +288,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, ExceptionDemoData.class, new DemoExceptionListener()).sheet().doRead(); } @@ -298,7 +298,7 @@ public class ReadTest { */ @Test 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 List list = EasyExcel.read(fileName).head(DemoData.class).sheet().doReadSync(); for (DemoData data : list) { @@ -318,7 +318,7 @@ public class ReadTest { */ @Test 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 EasyExcel.read(fileName, new NoModelDataListener()).sheet().doRead(); } diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java index 462511c3..41372f6a 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java +++ b/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 { 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))) { List list = ListUtils.newArrayList(); ImageDemoData imageDemoData = new ImageDemoData(); @@ -419,7 +419,7 @@ public class WriteTest { */ @Test 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"; // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭 EasyExcel.write(fileName, DemoData.class).withTemplate(templateFileName).sheet().doWrite(data()); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java index 34ff7a3a..23f623b6 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/WriteLargeTest.java @@ -33,7 +33,7 @@ public class WriteLargeTest { @Test public void test() throws Exception { // 方法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(); // 背景设置为红色 @@ -69,7 +69,7 @@ public class WriteLargeTest { @Test public void test2() throws Exception { // 方法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(); WriteSheet writeSheet = EasyExcel.writerSheet().build(); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java index 01046ce4..4440f350 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatTest.java @@ -132,7 +132,7 @@ public class DataFormatTest { @Test 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); Sheet xssfSheet = xssfWorkbook.getSheetAt(0); DataFormatter d = new DataFormatter(Locale.CHINA); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java index a538ab88..2c201863 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/fill/FillTempTest.java @@ -64,7 +64,7 @@ public class FillTempTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // 填充list 的时候还要注意 模板中{.} 多了个点 表示list 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 一下子全部放到内存里面 并填充 String fileName = TestFileUtil.getPath() + "listFill" + System.currentTimeMillis() + ".xlsx"; @@ -91,7 +91,7 @@ public class FillTempTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // {} 代表普通变量 {.} 代表是list的变量 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); @@ -123,7 +123,7 @@ public class FillTempTest { // {} 代表普通变量 {.} 代表是list的变量 // 这里模板 删除了list以后的数据,也就是统计的这一行 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); @@ -164,7 +164,7 @@ public class FillTempTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // {} 代表普通变量 {.} 代表是list的变量 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); @@ -191,7 +191,7 @@ public class FillTempTest { // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list 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"; ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java index aa4de2b9..7f89621c 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/issue1663/FillTest.java @@ -23,9 +23,9 @@ public class FillTest { @Test public void TestFillNullPoint(){ 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(); WriteSheet writeSheet = EasyExcel.writerSheet().build(); FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java index 8a6b8625..934b62f5 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/large/TempLargeDataTest.java @@ -45,10 +45,10 @@ public class TempLargeDataTest { @BeforeClass public static void init() { fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx"); - fileWrite07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWrite07.xlsx"); - fileWriteTemp07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWriteTemp07.xlsx"); - fileWritePoi07 = TestFileUtil.createNewFile("easyexcel-test/test/resources/large" + File.separator + "fileWritePoi07.xlsx"); - template07 = TestFileUtil.readFile("easyexcel-test/test/resources/large" + File.separator + "fill.xlsx"); + fileWrite07 = TestFileUtil.createNewFile("large" + File.separator + "fileWrite07.xlsx"); + fileWriteTemp07 = TestFileUtil.createNewFile("large" + File.separator + "fileWriteTemp07.xlsx"); + fileWritePoi07 = TestFileUtil.createNewFile("large" + File.separator + "fileWritePoi07.xlsx"); + template07 = TestFileUtil.readFile("large" + File.separator + "fill.xlsx"); fileCsv = TestFileUtil.createNewFile("largefileCsv.csv"); } diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java index 4f7a3431..4eb7714c 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/Poi3Test.java @@ -30,7 +30,7 @@ public class Poi3Test { @Test 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(); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); Encryptor enc = info.getEncryptor(); diff --git a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java index e83f7a7d..e27136d4 100644 --- a/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java +++ b/easyexcel-test/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java @@ -176,7 +176,7 @@ public class PoiTest { @Test 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); System.out.println(new File(file).exists()); @@ -231,7 +231,7 @@ public class PoiTest { @Test 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)); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); Sheet xssfSheet = xssfWorkbook.getSheetAt(0); @@ -248,14 +248,14 @@ public class PoiTest { @Test 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)); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); // // 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)); Sheet xssfSheet1 = xssfWorkbook1.getXSSFWorkbook().getSheetAt(0); @@ -268,13 +268,13 @@ public class PoiTest { @Test 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)); } @Test 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)); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); @@ -287,7 +287,7 @@ public class PoiTest { @Test 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)); Sheet xssfSheet = xssfWorkbook.getSheetAt(0); @@ -298,7 +298,7 @@ public class PoiTest { @Test 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)); Sheet xssfSheet = xssfWorkbook.getXSSFWorkbook().getSheetAt(0); LOGGER.info("一共行数:{}", xssfSheet.getPhysicalNumberOfRows()); @@ -309,7 +309,7 @@ public class PoiTest { @Test 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); LOGGER.info("一共:{}个sheet", xssfWorkbook.getNumberOfSheets()); XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); diff --git a/update.md b/update.md index 0ee6b28e..5ff096f3 100644 --- a/update.md +++ b/update.md @@ -10,6 +10,7 @@ * 捕获`setFeature`异常不影响主流程 [Issue #2054](https://github.com/alibaba/easyexcel/issues/2054) * 增加部分`xls`容错 [Issue #2236](https://github.com/alibaba/easyexcel/issues/2236) * 修复读取csv文件时`autoTrim`配置失效 [Issue #2227](https://github.com/alibaba/easyexcel/issues/2227) +* csv支持设置读写编码 [Issue #2404](https://github.com/alibaba/easyexcel/issues/2404) # 3.0.5