[英]JXLS + SXSSF - How to generate Excel file without including the template along with the actual generated report?
我正在嘗試使用JXLS的PoiTransformer
來生成非常大的報告。 問題是,到目前為止,我發現的所有示例都生成一個具有兩張工作表的excel文件,其中一張包含原始的,未修改的模板,另一張包含實際結果。 有什么辦法可以省略第一張紙,只保留結果嗎?
這是我當前的代碼:
PoiContext context = new PoiContext();
context.putVar("params", this.montaParametros(rel, filtro, opcoes, dados));
context.putVar("dados", this.converteDados(rel, dados));
Workbook template = WorkbookFactory.create(resource.getInputStream());
PoiTransformer transformer = PoiTransformer.createSxssfTransformer(template, 5, false);
AreaBuilder areaBuilder = new XlsCommentAreaBuilder(transformer);
List<Area> xlsAreaList = areaBuilder.build();
Area xlsArea = xlsAreaList.get(0);
// xlsArea.applyAt(new CellRef("Template!A1"), context); // Tried forcing it to use the original sheet as the output sheet, but it does not overwrite things properly
xlsArea.applyAt(new CellRef("Result!A1"), context); // Writes into a new sheet, but that's not what is desired
Workbook processado = transformer.getWorkbook();
processado.write(out);
好吧,愚蠢的我,看來我可以在寫入磁盤之前先刪除不需要的表。 我以為SXSSF會在某種程度上阻礙這一點,但是它似乎可以正常工作:
Workbook processado = transformer.getWorkbook();
processado.removeSheetAt(0);
processado.write(out);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.