JXLS设置工作表名称 [英] JXLS Set Sheet Name

查看:286
本文介绍了JXLS设置工作表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提供一种通过命令指定工作表名称的方法.工作表名称应根据工作表中的内容动态创建.

I would like to provide a way for a sheet name to be specified by a command. The sheet names should be dynamically created based on the content in the sheet.

我注意到,当使用每个命令的multisheet属性时,可以为动态工作表指定固定的工作表名称.

I note that it is possible to specify fixed sheet names for dynamic sheets when using the multisheet attribute of each-command.

  1. 版本1文档中有一个参考使用$ {workbook.setSheetName(0,department.name)}重命名工作表的功能.可以在v2中使用吗?应该如何运作?是需要将工作簿添加到上下文中还是以前可用?

  1. In the version 1 documentation there is a reference to the ability to rename a sheet using ${workbook.setSheetName(0, department.name)}. Can this be used in v2? How is it supposed to work? Would workbook need to be added to the context or was it previously available?

我尝试在自定义命令中重命名工作表,但是对于XlsArea.applyAt的一半更改名称,似乎对XlsArea中工作表名称的依赖性太大.模板表不会被删除,并且处理不会完成.

I tried renaming the sheet in a custom command but it seems that there is too much dependence on sheet names in XlsArea for the name to be changed halfway through XlsArea.applyAt. The template sheet is not deleted and processing is not completed.

我考虑过尝试获取自定义命令来添加区域侦听器以更改工作表名称.但是区域侦听器仅在父区域中调用,而我无法从命令中访问该区域.

I thought about trying to get the custom command to add an area listener to change the sheet name. But the area listeners are only called on the parent area which I cannot access from within the command.

谢谢

韦恩.

推荐答案

我怀疑这是正确的方法,但是直到现在,这是我设法做到的唯一方法:

I doubt this is the correct way to do it, but til now this is the only way I've managed to do it:

Context context = PoiTransformer.createInitialContext();
Workbook workbook = WorkbookFactory.create(templateInputStream);
workbook.setSheetName(0, "newName");//Changing name of the first sheet
PoiTransformer transformer = PoiTransformer.createTransformer(workbook);
transformer.setOutputStream(resultOutputstream);
JxlsHelper.getInstance().processTemplate(context, transformer);

这篇关于JXLS设置工作表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆