Question

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

Was it helpful?

Solution

The following should do the trick:

workbook.setSheetName(workbook.getSheetIndex(sheet), "newName");

OTHER TIPS

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top