The following should do the trick:
workbook.setSheetName(workbook.getSheetIndex(sheet), "newName");
Pregunta
is there any way to update existing sheet name of MS Excel file knowing that I am using apache poi in my android app
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
Solución
The following should do the trick:
workbook.setSheetName(workbook.getSheetIndex(sheet), "newName");
Otros consejos
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)
Sometimes, while using setSheetName, I get IllegalArgumentException that : Sheet index (-1) is out of range (0..0) even when I have just 1 sheet. So, I just did this and it worked.
workbook.getCTWorkbook().getSheets().getSheetArray(indexOfSheet).setName(sheetName);