문제

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

도움이 되었습니까?

해결책

The following should do the trick:

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

다른 팁

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top