Frage

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

War es hilfreich?

Lösung

The following should do the trick:

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

Andere Tipps

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top