Browse Source

修复空模板会空一行的bug

pull/732/head
Jiaju Zhuang 5 years ago
parent
commit
13d546a713
  1. 2
      pom.xml
  2. 5
      src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java
  3. 40
      src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java
  4. 1
      update.md

2
pom.xml

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
<version>2.1.0-beta1</version> <version>2.1.0-beta2</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>easyexcel</name> <name>easyexcel</name>

5
src/main/java/com/alibaba/excel/write/metadata/holder/WriteSheetHolder.java

@ -156,6 +156,11 @@ public class WriteSheetHolder extends AbstractWriteHolder {
int newRowIndex = 0; int newRowIndex = 0;
switch (writeLastRowTypeEnum) { switch (writeLastRowTypeEnum) {
case TEMPLATE_EMPTY: case TEMPLATE_EMPTY:
newRowIndex = Math.max(sheet.getLastRowNum(), cachedSheet.getLastRowNum());
if (newRowIndex != 0 || cachedSheet.getRow(0) != null) {
newRowIndex++;
}
break;
case HAS_DATA: case HAS_DATA:
newRowIndex = Math.max(sheet.getLastRowNum(), cachedSheet.getLastRowNum()); newRowIndex = Math.max(sheet.getLastRowNum(), cachedSheet.getLastRowNum());
newRowIndex++; newRowIndex++;

40
src/test/java/com/alibaba/easyexcel/test/temp/poi/PoiTest.java

@ -96,43 +96,23 @@ public class PoiTest {
@Test @Test
public void cp() throws IOException, InvalidFormatException { public void cp() throws IOException, InvalidFormatException {
String file = "d://test/tt.xlsx"; String file = "d://test/tt.xlsx";
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file)); SXSSFWorkbook xssfWorkbook = new SXSSFWorkbook(new XSSFWorkbook(file));
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); SXSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
XSSFRow row = xssfSheet.getRow(2); LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
xssfSheet.removeRow(row); SXSSFRow row = xssfSheet.getRow(0);
// Row r2= xssfSheet.createRow(2); LOGGER.info("第一行数据:{}", row);
// r2.createCell(1); xssfSheet.createRow(20);
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook); LOGGER.info("一共行数:{}", xssfSheet.getLastRowNum());
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();
} }
@Test @Test
public void lastRowNum233443() throws IOException, InvalidFormatException { 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)); XSSFWorkbook xssfWorkbook = new XSSFWorkbook(new File(file));
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(xssfWorkbook);
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0); XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(0);
XSSFRow row = xssfSheet.getRow(2); System.out.println(xssfSheet.getLastRowNum());
xssfSheet.removeRow(row); System.out.println(xssfSheet.getRow(0));
new CellCopyPolicy().createBuilder().build();
FileOutputStream fileout = new FileOutputStream("d://test/r2" + System.currentTimeMillis() + ".xlsx");
sxssfWorkbook.write(fileout);
sxssfWorkbook.dispose();
sxssfWorkbook.close();
xssfWorkbook.close();
} }
@Test @Test

1
update.md

@ -1,6 +1,7 @@
# 2.1.0-beta2 # 2.1.0-beta2
* 修改模板通过流创建报错的bug * 修改模板通过流创建报错的bug
* 修复空数据未替换掉的bug * 修复空数据未替换掉的bug
* 修复空模板会空一行的bug
# 2.1.0-beta1 # 2.1.0-beta1
* 新增支持导入、导出支持公式 * 新增支持导入、导出支持公式

Loading…
Cancel
Save