diff --git a/src/main/java/com/alibaba/excel/util/WorkBookUtil.java b/src/main/java/com/alibaba/excel/util/WorkBookUtil.java index 3e9732a9..71e1fd54 100644 --- a/src/main/java/com/alibaba/excel/util/WorkBookUtil.java +++ b/src/main/java/com/alibaba/excel/util/WorkBookUtil.java @@ -2,6 +2,7 @@ package com.alibaba.excel.util; import java.io.IOException; import java.io.OutputStreamWriter; +import java.io.PrintWriter; import com.alibaba.excel.metadata.csv.CsvWorkbook; import com.alibaba.excel.metadata.data.DataFormatData; @@ -67,8 +68,8 @@ public class WorkBookUtil { } return; case CSV: - CsvWorkbook csvWorkbook = new CsvWorkbook( - new OutputStreamWriter(writeWorkbookHolder.getOutputStream(), writeWorkbookHolder.getCharset()), + CsvWorkbook csvWorkbook = new CsvWorkbook(new PrintWriter( + new OutputStreamWriter(writeWorkbookHolder.getOutputStream(), writeWorkbookHolder.getCharset())), writeWorkbookHolder.getGlobalConfiguration().getLocale(), writeWorkbookHolder.getGlobalConfiguration().getUse1904windowing(), writeWorkbookHolder.getGlobalConfiguration().getUseScientificFormat()); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java index 44e2f55b..c69e3ae4 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/multiplesheets/MultipleSheetsDataTest.java @@ -3,17 +3,17 @@ package com.alibaba.easyexcel.test.core.multiplesheets; import java.io.File; import java.util.List; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.read.metadata.ReadSheet; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.alibaba.easyexcel.test.util.TestFileUtil; -import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.ExcelReader; -import com.alibaba.excel.read.metadata.ReadSheet; - /** * * @author Jiaju Zhuang @@ -57,7 +57,7 @@ public class MultipleSheetsDataTest { int count = 1; for (ReadSheet readSheet : sheets) { excelReader.read(readSheet); - Assert.assertEquals((long)multipleSheetsListener.getList().size(), (long)count); + Assert.assertEquals(multipleSheetsListener.getList().size(), count); count++; } excelReader.finish(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java index 1a0cf088..262ae35d 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/nomodel/NoModelDataTest.java @@ -23,15 +23,20 @@ public class NoModelDataTest { private static File file07; private static File file03; + private static File fileCsv; private static File fileRepeat07; private static File fileRepeat03; + private static File fileRepeatCsv; + @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("noModel07.xlsx"); file03 = TestFileUtil.createNewFile("noModel03.xls"); + fileCsv = TestFileUtil.createNewFile("noModelCsv.csv"); fileRepeat07 = TestFileUtil.createNewFile("noModelRepeat07.xlsx"); fileRepeat03 = TestFileUtil.createNewFile("noModelRepeat03.xls"); + fileRepeatCsv = TestFileUtil.createNewFile("noModelRepeatCsv.csv"); } @Test @@ -44,6 +49,11 @@ public class NoModelDataTest { readAndWrite(file03, fileRepeat03); } + @Test + public void t03ReadAndWriteCsv() throws Exception { + readAndWrite(fileCsv, fileRepeatCsv); + } + private void readAndWrite(File file, File fileRepeat) throws Exception { EasyExcel.write(file).sheet().doWrite(data()); List> result = EasyExcel.read(file).headRowNumber(0).sheet().doReadSync(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataTest.java index 689c9f8a..e8696c5a 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/noncamel/UnCamelDataTest.java @@ -20,11 +20,14 @@ public class UnCamelDataTest { private static File file07; private static File file03; + private static File fileCsv; + @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("unCame07.xlsx"); file03 = TestFileUtil.createNewFile("unCame03.xls"); + fileCsv = TestFileUtil.createNewFile("unCameCsv.csv"); } @Test @@ -37,6 +40,11 @@ public class UnCamelDataTest { readAndWrite(file03); } + @Test + public void t03ReadAndWriteCsv() { + readAndWrite(fileCsv); + } + private void readAndWrite(File file) { EasyExcel.write(file, UnCamelData.class).sheet().doWrite(data()); EasyExcel.read(file, UnCamelData.class, new UnCamelDataListener()).sheet().doRead(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java index c7c305de..4e0f2a09 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/parameter/ParameterDataTest.java @@ -5,11 +5,6 @@ import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; @@ -17,59 +12,79 @@ import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.cache.MapCache; import com.alibaba.excel.converters.string.StringStringConverter; import com.alibaba.excel.read.metadata.ReadSheet; +import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteTable; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + /** - * * @author Jiaju Zhuang */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ParameterDataTest { - private static File file; + private static File file07; + private static File fileCsv; @BeforeClass public static void init() { - file = TestFileUtil.createNewFile("parameter07.xlsx"); + file07 = TestFileUtil.createNewFile("parameter07.xlsx"); + fileCsv = TestFileUtil.createNewFile("parameterCsv.csv"); } @Test public void t01ReadAndWrite() throws Exception { - readAndWrite1(); - readAndWrite2(); - readAndWrite3(); - readAndWrite4(); - readAndWrite5(); - readAndWrite6(); - readAndWrite7(); + readAndWrite1(file07, ExcelTypeEnum.XLSX); + readAndWrite2(file07, ExcelTypeEnum.XLSX); + readAndWrite3(file07, ExcelTypeEnum.XLSX); + readAndWrite4(file07, ExcelTypeEnum.XLSX); + readAndWrite5(file07, ExcelTypeEnum.XLSX); + readAndWrite6(file07, ExcelTypeEnum.XLSX); + readAndWrite7(file07, ExcelTypeEnum.XLSX); } - private void readAndWrite1() { + @Test + public void t02ReadAndWrite() throws Exception { + readAndWrite1(fileCsv, ExcelTypeEnum.CSV); + readAndWrite2(fileCsv, ExcelTypeEnum.CSV); + readAndWrite3(fileCsv, ExcelTypeEnum.CSV); + readAndWrite4(fileCsv, ExcelTypeEnum.CSV); + readAndWrite5(fileCsv, ExcelTypeEnum.CSV); + readAndWrite6(fileCsv, ExcelTypeEnum.CSV); + readAndWrite7(fileCsv, ExcelTypeEnum.CSV); + } + + private void readAndWrite1(File file, ExcelTypeEnum type) { EasyExcel.write(file.getPath()).head(ParameterData.class).sheet().doWrite(data()); EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener()) .sheet().doRead(); } - private void readAndWrite2() { + private void readAndWrite2(File file, ExcelTypeEnum type) { EasyExcel.write(file.getPath(), ParameterData.class).sheet().doWrite(data()); EasyExcel.read(file.getPath(), ParameterData.class, new ParameterDataListener()).sheet().doRead(); } - private void readAndWrite3() throws Exception { - EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).sheet().doWrite(data()); + private void readAndWrite3(File file, ExcelTypeEnum type) throws Exception { + EasyExcel.write(new FileOutputStream(file)).excelType(type).head(ParameterData.class).sheet() + .doWrite(data()); EasyExcel.read(file.getPath()).head(ParameterData.class).registerReadListener(new ParameterDataListener()) .sheet().doRead(); } - private void readAndWrite4() throws Exception { - EasyExcel.write(new FileOutputStream(file), ParameterData.class).sheet().doWrite(data()); + private void readAndWrite4(File file, ExcelTypeEnum type) throws Exception { + EasyExcel.write(new FileOutputStream(file), ParameterData.class).excelType(type).sheet().doWrite(data()); EasyExcel.read(file.getPath(), new ParameterDataListener()).head(ParameterData.class).sheet().doRead(); } - private void readAndWrite5() throws Exception { + private void readAndWrite5(File file, ExcelTypeEnum type) throws Exception { ExcelWriter excelWriter = - EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).relativeHeadRowIndex(0).build(); + EasyExcel.write(new FileOutputStream(file)).excelType(type).head(ParameterData.class).relativeHeadRowIndex( + 0).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build(); WriteTable writeTable = EasyExcel.writerTable(0).relativeHeadRowIndex(0).needHead(Boolean.TRUE).build(); excelWriter.write(data(), writeSheet, writeTable); @@ -88,9 +103,10 @@ public class ParameterDataTest { excelReader.finish(); } - private void readAndWrite6() throws Exception { + private void readAndWrite6(File file, ExcelTypeEnum type) throws Exception { ExcelWriter excelWriter = - EasyExcel.write(new FileOutputStream(file)).head(ParameterData.class).relativeHeadRowIndex(0).build(); + EasyExcel.write(new FileOutputStream(file)).excelType(type).head(ParameterData.class).relativeHeadRowIndex( + 0).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).relativeHeadRowIndex(0).needHead(Boolean.FALSE).build(); WriteTable writeTable = EasyExcel.writerTable(0).registerConverter(new StringStringConverter()) .relativeHeadRowIndex(0).needHead(Boolean.TRUE).build(); @@ -110,7 +126,7 @@ public class ParameterDataTest { excelReader.finish(); } - private void readAndWrite7() { + private void readAndWrite7(File file, ExcelTypeEnum type) { EasyExcel.write(file, ParameterData.class).registerConverter(new StringStringConverter()).sheet() .registerConverter(new StringStringConverter()).needHead(Boolean.FALSE).table(0).needHead(Boolean.TRUE) .doWrite(data()); @@ -119,7 +135,7 @@ public class ParameterDataTest { } private List data() { - List list = new ArrayList(); + List list = new ArrayList<>(); for (int i = 0; i < 10; i++) { ParameterData simpleData = new ParameterData(); simpleData.setName("姓名" + i); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java index 4c0d8aad..70acf19f 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/repetition/RepetitionDataTest.java @@ -4,11 +4,6 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; @@ -17,8 +12,12 @@ import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.WriteTable; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + /** - * * @author Jiaju Zhuang */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -26,15 +25,19 @@ public class RepetitionDataTest { private static File file07; private static File file03; + private static File fileCsv; private static File fileTable07; private static File fileTable03; + private static File fileTableCsv; @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("repetition07.xlsx"); file03 = TestFileUtil.createNewFile("repetition03.xls"); + fileCsv = TestFileUtil.createNewFile("repetitionCsv.csv"); fileTable07 = TestFileUtil.createNewFile("repetitionTable07.xlsx"); fileTable03 = TestFileUtil.createNewFile("repetitionTable03.xls"); + fileTableCsv = TestFileUtil.createNewFile("repetitionTableCsv.csv"); } @Test @@ -47,6 +50,11 @@ public class RepetitionDataTest { readAndWrite(file03); } + @Test + public void t03ReadAndWriteCsv() { + readAndWrite(fileCsv); + } + private void readAndWrite(File file) { ExcelWriter excelWriter = EasyExcel.write(file, RepetitionData.class).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); @@ -57,15 +65,20 @@ public class RepetitionDataTest { } @Test - public void t03ReadAndWriteTable07() { + public void t11ReadAndWriteTable07() { readAndWriteTable(fileTable07); } @Test - public void t04ReadAndWriteTable03() { + public void t12ReadAndWriteTable03() { readAndWriteTable(fileTable03); } + @Test + public void t13ReadAndWriteTableCsv() { + readAndWriteTable(fileTableCsv); + } + private void readAndWriteTable(File file) { ExcelWriter excelWriter = EasyExcel.write(file, RepetitionData.class).build(); WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java index 2d3c75b6..a381ec43 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/simple/SimpleDataTest.java @@ -4,17 +4,16 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.alibaba.easyexcel.test.util.TestFileUtil; -import com.alibaba.excel.EasyExcel; - /** - * * @author Jiaju Zhuang */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -22,11 +21,13 @@ public class SimpleDataTest { private static File file07; private static File file03; + private static File fileCsv; @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("simple07.xlsx"); file03 = TestFileUtil.createNewFile("simple03.xls"); + fileCsv = TestFileUtil.createNewFile("simpleCsv.csv"); } @Test @@ -39,21 +40,31 @@ public class SimpleDataTest { readAndWrite(file03); } + @Test + public void t03ReadAndWriteCsv() { + readAndWrite(fileCsv); + } + private void readAndWrite(File file) { EasyExcel.write(file, SimpleData.class).sheet().doWrite(data()); EasyExcel.read(file, SimpleData.class, new SimpleDataListener()).sheet().doRead(); } @Test - public void t03SynchronousRead07() { + public void t11SynchronousRead07() { synchronousRead(file07); } @Test - public void t04SynchronousRead03() { + public void t12SynchronousRead03() { synchronousRead(file03); } + @Test + public void t13SynchronousReadCsv() { + synchronousRead(fileCsv); + } + @Test public void t05SheetNameRead07() { EasyExcel.read(TestFileUtil.readFile("simple" + File.separator + "simple07.xlsx"), SimpleData.class, diff --git a/src/test/java/com/alibaba/easyexcel/test/core/skip/SkipDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/skip/SkipDataTest.java index 3f62994e..ed9e84df 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/skip/SkipDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/skip/SkipDataTest.java @@ -4,23 +4,22 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - import com.alibaba.easyexcel.test.core.simple.SimpleData; -import com.alibaba.easyexcel.test.core.simple.SimpleDataListener; -import com.alibaba.easyexcel.test.core.simple.SimpleDataSheetNameListener; import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelReader; import com.alibaba.excel.ExcelWriter; import com.alibaba.excel.event.SyncReadListener; +import com.alibaba.excel.exception.ExcelGenerateException; import com.alibaba.excel.read.metadata.ReadSheet; import com.alibaba.excel.write.metadata.WriteSheet; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + /** * @author Jiaju Zhuang */ @@ -29,11 +28,13 @@ public class SkipDataTest { private static File file07; private static File file03; + private static File fileCsv; @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("skip.xlsx"); file03 = TestFileUtil.createNewFile("skip.xls"); + fileCsv = TestFileUtil.createNewFile("skip.csv"); } @Test @@ -46,6 +47,11 @@ public class SkipDataTest { readAndWrite(file03); } + @Test + public void t03ReadAndWriteCsv() { + Assert.assertThrows(ExcelGenerateException.class, () -> readAndWrite(fileCsv)); + } + private void readAndWrite(File file) { ExcelWriter excelWriter = EasyExcel.write(file, SimpleData.class).build(); WriteSheet writeSheet0 = EasyExcel.writerSheet(0, "第一个").build(); @@ -70,12 +76,11 @@ public class SkipDataTest { excelReader.read(readSheet1, readSheet3); List syncList = syncReadListener.getList(); Assert.assertEquals(2, syncList.size()); - Assert.assertEquals("name2", ((SkipData) syncList.get(0)).getName()); - Assert.assertEquals("name4", ((SkipData) syncList.get(1)).getName()); + Assert.assertEquals("name2", ((SkipData)syncList.get(0)).getName()); + Assert.assertEquals("name4", ((SkipData)syncList.get(1)).getName()); excelReader.finish(); } - private List data(String name) { List list = new ArrayList(); SkipData data = new SkipData(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataTest.java index 698078a1..f1a2b618 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/sort/SortDataTest.java @@ -6,15 +6,15 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.alibaba.easyexcel.test.util.TestFileUtil; -import com.alibaba.excel.EasyExcel; - /** * @author Jiaju Zhuang */ @@ -23,15 +23,19 @@ public class SortDataTest { private static File file07; private static File file03; + private static File fileCsv; private static File sortNoHead07; private static File sortNoHead03; + private static File sortNoHeadCsv; @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("sort.xlsx"); file03 = TestFileUtil.createNewFile("sort.xls"); + fileCsv = TestFileUtil.createNewFile("sort.csv"); sortNoHead07 = TestFileUtil.createNewFile("sortNoHead.xlsx"); sortNoHead03 = TestFileUtil.createNewFile("sortNoHead.xls"); + sortNoHeadCsv = TestFileUtil.createNewFile("sortNoHead.csv"); } @Test @@ -45,15 +49,24 @@ public class SortDataTest { } @Test - public void t03ReadAndWriteNoHead07() { + public void t03ReadAndWriteCsv() { + readAndWrite(fileCsv); + } + + @Test + public void t11ReadAndWriteNoHead07() { readAndWriteNoHead(sortNoHead07); } @Test - public void t04ReadAndWriteNoHead03() { + public void t12ReadAndWriteNoHead03() { readAndWriteNoHead(sortNoHead03); } + @Test + public void t13ReadAndWriteNoHeadCsv() { + readAndWriteNoHead(sortNoHeadCsv); + } private void readAndWrite(File file) { EasyExcel.write(file, SortData.class).sheet().doWrite(data()); @@ -95,7 +108,6 @@ public class SortDataTest { return head; } - private List data() { List list = new ArrayList(); SortData sortData = new SortData(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java index 843ac964..fec79796 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/style/StyleDataTest.java @@ -40,7 +40,7 @@ public class StyleDataTest { @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("style07.xlsx"); - file03 = TestFileUtil.createNewFile("style03.xls"); + file03 = TestFileUtil.createNewFile("style03.csv"); } @Test diff --git a/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java index adf63137..d6ebd0aa 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/template/TemplateDataTest.java @@ -4,14 +4,14 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import com.alibaba.easyexcel.test.util.TestFileUtil; +import com.alibaba.excel.EasyExcel; + import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.alibaba.easyexcel.test.util.TestFileUtil; -import com.alibaba.excel.EasyExcel; - /** * * @author Jiaju Zhuang @@ -22,6 +22,7 @@ public class TemplateDataTest { private static File file07; private static File file03; + @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("template07.xlsx"); diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java index ebc910d1..91293019 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/csv/CsvReadTest.java @@ -2,7 +2,9 @@ package com.alibaba.easyexcel.test.temp.csv; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileReader; +import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; @@ -25,7 +27,8 @@ public class CsvReadTest { @Test public void write() throws Exception { - Appendable out = new PrintWriter(TestFileUtil.createNewFile("csvWrite1.csv")); + Appendable out = new PrintWriter( + new OutputStreamWriter(new FileOutputStream(TestFileUtil.createNewFile("csvWrite1.csv")))); CSVPrinter printer = CSVFormat.DEFAULT.withHeader("userId", "userName") .print(out); for (int i = 0; i < 10; i++) {