I can set a name of sheet, but the set name cannot be replaced to another. For example, // create sheet this.sheet = this.workbook.createSheet(); // set sheetname this.workbook.setSheetName( 0, "SheetX", HSSFWorkbook.ENCODING_UTF_16 ); Then, I get the sheetname, which is is "SheetX". Everything is neat so far, but once I change the name to other one, say, "SheetY", the sheet name becomes ".xls]SheetY". The new name is unable to be changed anymore because it has "." and "]" which are unpermitted characters in the sheetname. Is anything wrong with the codes?
I found out a new fact. The problem occurred only when I try to change a sheet name which is downloaded, opened and NOT SAVED. Once the sheet is saved, its name can be changed safelly.
Can you please submit some code that reproduces the error. It would be beneficial to have a before and after save in excel file attached to the bug. A simple diff of the biff records of the before and after would probably pinpoint the problem. Jason
Created attachment 10433 [details] Java Source Code
Created attachment 10434 [details] The Excel WorkBook Before the sheet name is changed
Created attachment 10435 [details] The Excel WorkBook After the sheet name is changed
Hi, Jason. I attached a simple Jave file which is simple, but still causes the error. Also, I attached two Excel workbooks; one is the one whose sheet name is not changed and the other is the one whose sheet name is changed to "a" and finally has the new sheet name ".xls]a". NOTE: Both sheet names ARE able to be changed now because they have been SAVED. However, if you check out the latter's biff using org.apache.poi.hssf.dev.BiffViewer, you will find a bunch of UNKNOWN codes. Thanks Ted
Still has problems with version 2.5-final. No clue??
It's not a bug in POI, it's a bug in Excel! The same problem was bugging me. And like the reporter of the bug said, the problem only occurred before the file was saved. I am generating XLS files from a struts action, and the problem with renaming sheets in Excel only occurred if I opened the action's output directly in excel, not if I saved it first. After a while this pattern became appearant: any XLS file with square brackets in the name (like any temporary file from MSIE, but also "my file [really].xls") has the problem that Excel will behave strange if you change the name of a sheet within it. The workaround is to give the file a name without brackets. Unfortunately, you don't have a choice which name MSIE picks for a temporary file when you open a downloaded file instead of saving it first.
Thanks for debugging this.. very helpful!