Excel中的工作表名称

时间:2019-07-26 06:21:58

标签: jxls

是否可以使用JxlsHelper设置工作表名称来填充Excel模板?

Context context = new Context();
context.putVar("data", hereIsListOfData());
InputStream templateStream = getClass().getResourceAsStream(EXCEL_TEMPLATE);
ByteArrayOutputStream output = new ByteArrayOutputStream());
JxlsHelper.getInstance().processTemplate(templateStream, output, context);

1 个答案:

答案 0 :(得分:1)

感谢https://stackoverflow.com/a/40789235/7913021

Context context = new Context();
context.putVar("data", hereIsListOfData());

InputStream templateStream = getClass().getResourceAsStream(EXCEL_TEMPLATE);
ByteArrayOutputStream output = new ByteArrayOutputStream());

Workbook workbook = WorkbookFactory.create(templateStream);
workbook.setSheetName(0, sheetName);

PoiTransformer transformer = PoiTransformer.createTransformer(workbook);
transformer.setOutputStream(output);

JxlsHelper.getInstance().processTemplate(context, transformer);