easyexcel icon indicating copy to clipboard operation
easyexcel copied to clipboard

同一个Excel 不能追加Sheet

Open shanjungit opened this issue 7 years ago • 4 comments

我按照WriteTest里的方法, new Sheet(x,0), 我本来希望可以,通过ExcelReader读取到所有的Sheet页数量,然后在后面追加,可以每次我 new Sheet(x+1,0) 再使用ExcelWriiter 写入的时候,都把原来的覆盖掉了。 导致了,每次我的Excel都只有一个Sheet,就是最后写入的sheet. 这可能是什么情况?

shanjungit avatar Feb 19 '19 08:02 shanjungit

这样子写可以追加sheet @Test public void writeV2019() throws IOException { OutputStream out = new FileOutputStream("E:\2019.xlsx"); ExcelWriter writer = EasyExcelFactory.getWriter(out);

    for(int i = 0; i < 14;i++) {
        Sheet tempSheet = new Sheet(i, 0);
        tempSheet.setSheetNo(i);
        tempSheet.setSheetName("第"+i+"Sheet");
        writer.write1(createTestListObject(), tempSheet);
    }
    writer.finish();
    out.close();
}

下面的写法,就不能追加了 for(int i = 0; i < 14;i++) { OutputStream out = new FileOutputStream("E:\2019.xlsx"); ExcelWriter writer = EasyExcelFactory.getWriter(out); Sheet tempSheet = new Sheet(i, 0); tempSheet.setSheetNo(i); tempSheet.setSheetName("第"+i+"Sheet"); writer.write1(createTestListObject(), tempSheet); writer.finish(); out.close(); }

shanjungit avatar Feb 20 '19 03:02 shanjungit

建议 巩固一下 文件流的基础知识,循环中每次 新建一个流,又没有使用追加模式,肯定是覆盖

Bin-mario avatar Feb 25 '19 08:02 Bin-mario

请问一下 new Sheet(x,0),这个方法的第二个参数HeadLineMun是什么意思呢

LanceXuan avatar Mar 09 '19 06:03 LanceXuan

这个已经在最新版本修复,请使用最新版本。https://maven-badges.herokuapp.com/maven-central/com.alibaba/easyexcel。 并且参照:https://github.com/alibaba/easyexcel/blob/master/quickstart.md 去书写

zhuangjiaju avatar Aug 28 '19 11:08 zhuangjiaju