是否可以使用 apache poi MS excel java android 更改工作表名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21942056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
is it possible to change sheet name with apache poi MS excel java android
提问by funfordevelopping
is there any way to update existing sheet name of MS Excel file knowing that I am using apache poi in my android app
知道我在我的 android 应用程序中使用 apache poi 有什么方法可以更新 MS Excel 文件的现有工作表名称
I can create a sheet with my custom name
我可以用我的自定义名称创建一个工作表
HSSFSheet sheet = workbook.createSheet("my custom name");
but when I want to copy another sheet to this one , the name also is copied and my custom name is crashed
但是当我想将另一张工作表复制到这个工作表时,名称也被复制并且我的自定义名称崩溃了
采纳答案by nikis
The following should do the trick:
以下应该可以解决问题:
workbook.setSheetName(workbook.getSheetIndex(sheet), "newName");
回答by Jonathan L
If you already know the sheet index, simply call
如果您已经知道工作表索引,只需调用
workbook.setSheetName(sheet-index, "my sheet name");
where sheet-index is the sheet number (0 based)
其中 sheet-index 是工作表编号(基于 0)