diff --git a/pom.xml b/pom.xml index 68fe674a..90838f33 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.alibaba easyexcel - 2.1.0-beta1 + 2.1.0-beta2 jar easyexcel diff --git a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java index 1fb19fb0..90030f4f 100644 --- a/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java +++ b/src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java @@ -156,6 +156,11 @@ public class WriteSheetHolder extends AbstractWriteHolder { int newRowIndex = 0; switch (writeLastRowTypeEnum) { case TEMPLATE_EMPTY: + newRowIndex = Math.max(sheet.getLastRowNum(), cachedSheet.getLastRowNum()); + if (newRowIndex != 0 || cachedSheet.getRow(0) != null) { + newRowIndex++; + } + break; case HAS_DATA: newRowIndex = Math.max(sheet.getLastRowNum(), cachedSheet.getLastRowNum()); newRowIndex++; diff --git a/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java b/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java index ee7be1e8..367ee583 100644 --- a/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java +++ b/src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java @@ -96,43 +96,23 @@ public class PoiTest { @Test public void cp() throws IOException, InvalidFormatException { String file = "d://test/tt.xlsx"; - XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file)); - XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); - XSSFRow row = xssfSheet.getRow(2); - xssfSheet.removeRow(row); -// Row r2= xssfSheet.createRow(2); -// r2.createCell(1); - SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); - - - SXSSFSheet sxssfSheet = sxssfWorkbook.getSheetAt(0); - sxssfSheet.createRow(2); - - - FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx"); - sxssfWorkbook.write(fileout); - sxssfWorkbook.dispose(); - sxssfWorkbook.close(); - - xssfWorkbook.close(); + SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file)); + SXSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); + LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum()); + SXSSFRow row = xssfSheet.getRow(0); + LOGGER.info("第一行数据:{}", row); + xssfSheet.createRow(20); + LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum()); } @Test public void lastRowNum233443() throws IOException, InvalidFormatException { - String file = "d://test/tt.xlsx"; + String file = "d://test/em0.xlsx"; XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file)); - SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); - XSSFRow row = xssfSheet.getRow(2); - xssfSheet.removeRow(row); - new CellCopyPolicy().createBuilder().build(); + System.out.println(xssfSheet.getLastRowNum()); + System.out.println(xssfSheet.getRow(0)); - FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx"); - sxssfWorkbook.write(fileout); - sxssfWorkbook.dispose(); - sxssfWorkbook.close(); - - xssfWorkbook.close(); } @Test diff --git a/update.md b/update.md index f1f5cf86..d2c0cbb0 100644 --- a/update.md +++ b/update.md @@ -1,6 +1,7 @@ # 2.1.0-beta2 * 修改模板通过流创建报错的bug * 修复空数据未替换掉的bug +* 修复空模板会空一行的bug # 2.1.0-beta1 * 新增支持导入、导出支持公式