Summary: | Exception received after using shiftRows and cloneSheet | ||
---|---|---|---|
Product: | POI | Reporter: | bob Stox <bstox> |
Component: | XSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED WORKSFORME | ||
Severity: | normal | CC: | muckomspam |
Priority: | P2 | ||
Version: | 3.6-FINAL | ||
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | All | ||
Attachments: | Test spreadsheet |
I could not reproduce this any more with the latest version of POI, please try with that version and reopen the bug with an updated testcase which reproduces the problem. |
Created attachment 24805 [details] Test spreadsheet I have an excel spreadsheet with one worksheet which I use as a template for multiple worksheets. Prior to cloning the worksheet sometimes I need to insert a row into the worksheet. When the program is trying to save the spreadsheet I receive the following exception: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1213) at org.openxmlformats.schemas.spreadsheetml.x2006.main.impl.CTRowImpl.setCArray(Unknown Source) at org.apache.poi.xssf.usermodel.XSSFRow.onDocumentWrite(XSSFRow.java:392) at org.apache.poi.xssf.usermodel.XSSFSheet.write(XSSFSheet.java:2362) at org.apache.poi.xssf.usermodel.XSSFSheet.commit(XSSFSheet.java:2328) at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:177) at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:181) at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:214) at test.AATest.main(AATest.java:21) I found this bug when converting from HSSF. This is the test program that shows the error: package test; import java.io.*; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; public class AATest { /** * @param args */ public static void main(String[] args) { try { Workbook wb = new XSSFWorkbook("AATest.xlsx"); Sheet sheet = wb.getSheetAt(0); sheet.shiftRows(2, sheet.getLastRowNum(), 1, true, false); Row newRow = sheet.getRow(2); if (newRow == null) newRow = sheet.createRow(2); newRow.createCell(0).setCellValue(" Another Header"); wb.cloneSheet(0); FileOutputStream fileOut = new FileOutputStream("newWorkbook.xlsx"); wb.write(fileOut); fileOut.close(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Done"); } } It only happens when the worksheet is cloned. I'll attach the spreadsheet.