diff --git a/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java b/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java index 14c6a207..a54d0681 100644 --- a/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java +++ b/src/main/java/com/alibaba/excel/metadata/csv/CsvSheet.java @@ -728,8 +728,12 @@ public class CsvSheet implements Sheet, Closeable { try { for (CsvRow row : rowCache) { Iterator cellIterator = row.cellIterator(); + int columnIndex = 0; while (cellIterator.hasNext()) { CsvCell csvCell = (CsvCell)cellIterator.next(); + while (csvCell.getColumnIndex() > columnIndex++) { + csvPrinter.print(null); + } csvPrinter.print(buildCellValue(csvCell)); } csvPrinter.println(); diff --git a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java index da6848a3..7a4dfe21 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationDataTest.java @@ -24,7 +24,7 @@ public class AnnotationDataTest { public static void init() { file07 = TestFileUtil.createNewFile("annotation07.xlsx"); file03 = TestFileUtil.createNewFile("annotation03.xls"); - fileCsv = TestFileUtil.createNewFile("annotation.csv"); + fileCsv = TestFileUtil.createNewFile("annotationCsv.csv"); } @Test @@ -38,8 +38,8 @@ public class AnnotationDataTest { } @Test - public void t02ReadAndWriteCsv() throws Exception { - //readAndWrite(fileCsv); + public void t03ReadAndWriteCsv() throws Exception { + readAndWrite(fileCsv); } private void readAndWrite(File file) throws Exception { diff --git a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java index cd069c81..5f12bb33 100644 --- a/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/core/annotation/AnnotationIndexAndNameDataTest.java @@ -4,12 +4,12 @@ import java.io.File; import java.util.ArrayList; import java.util.List; -import org.junit.BeforeClass; -import org.junit.Test; - import com.alibaba.easyexcel.test.util.TestFileUtil; import com.alibaba.excel.EasyExcel; +import org.junit.BeforeClass; +import org.junit.Test; + /** * Annotation data test * @@ -19,11 +19,13 @@ public class AnnotationIndexAndNameDataTest { private static File file07; private static File file03; + private static File fileCsv; @BeforeClass public static void init() { file07 = TestFileUtil.createNewFile("annotationIndexAndName07.xlsx"); file03 = TestFileUtil.createNewFile("annotationIndexAndName03.xls"); + fileCsv = TestFileUtil.createNewFile("annotationIndexAndNameCsv.csv"); } @Test @@ -36,6 +38,11 @@ public class AnnotationIndexAndNameDataTest { readAndWrite(file03); } + @Test + public void t03ReadAndWrite03() { + readAndWrite(fileCsv); + } + private void readAndWrite(File file) { EasyExcel.write(file, AnnotationIndexAndNameData.class).sheet().doWrite(data()); EasyExcel.read(file, AnnotationIndexAndNameData.class, new AnnotationIndexAndNameDataListener()).sheet()