https://issues.apache.org/bugzilla/show_bug.cgi?id=57163
Bug ID: 57163
Summary: Cannot delete a sheet in an XLS workbook
Product: POI
Version: 3.11-dev
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: HSSF
Assignee: [email protected]
Reporter: [email protected]
When I want to delete a sheet that's not the last one in a workbook with
several sheets, I get an exception.
Exception in thread "main" java.lang.NullPointerException
at
org.apache.poi.hssf.model.InternalWorkbook.removeSheet(InternalWorkbook.java:780)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.removeSheetAt(HSSFWorkbook.java:924)
I open the file with:
try (InputStream in = new BufferedInputStream(new FileInputStream(new
File(fileName))))
{
return WorkbookFactory.create(in);
}
then I call workbook.removeSheetAt(0);
Apparently, the linkTable field is null.
My use case is to load a template with several sheets, delete them all but one
to clone it to the number of sheets needed.
As a workaround, I move the wanted sheet at first position with:
workbook.setSheetOrder(workbook.getSheetName(sheetIndex), 0);
then I delete all the others in reverse order...
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]