From b3fee7f7e6473346a62460fef0f050e709700143 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Thu, 14 Apr 2011 14:29:04 +0000 Subject: [PATCH] Fix bug #51061 - Correct target URI for new XSSF Tables git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1092281 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/xssf/usermodel/XSSFRelation.java | 10 +++++-- .../apache/poi/xssf/usermodel/XSSFSheet.java | 5 +++- .../poi/xssf/usermodel/TestXSSFBugs.java | 27 +++++++++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 93500e662..b01bf5e98 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51061 - Correct target URI for new XSSF Tables Initial support for XSSF Charts. Provides easy access to the underlying CTChart object via the Sheet Drawing, but no high level interface onto the chart contents as yet. 50884 - XSSF and HSSF freeze panes now behave the same Support for adding a table to a XSSFSheet diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java index cae8b5f80..b49d6c2d3 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java @@ -138,14 +138,14 @@ public final class XSSFRelation extends POIXMLRelation { public static final XSSFRelation SINGLE_XML_CELLS = new XSSFRelation( "application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/tableSingleCells", - "/tables/tableSingleCells#.xml", + "/xl/tables/tableSingleCells#.xml", SingleXmlCells.class ); public static final XSSFRelation TABLE = new XSSFRelation( "application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/table", - "/tables/table#.xml", + "/xl/tables/table#.xml", Table.class ); @@ -247,6 +247,12 @@ public final class XSSFRelation extends POIXMLRelation { "/xl/calcChain.xml", CalculationChain.class ); + public static final XSSFRelation PRINTER_SETTINGS = new XSSFRelation( + "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings", + "/xl/printerSettings/printerSettings#.bin", + null + ); private XSSFRelation(String type, String rel, String defaultName, Class cls) { diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 887ff0eab..163da4d26 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -3030,7 +3030,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { CTTableParts tblParts = worksheet.getTableParts(); CTTablePart tbl = tblParts.addNewTablePart(); - Table table = (Table)createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tblParts.sizeOfTablePartArray()); + // Table numbers need to be unique in the file, not just + // unique within the sheet. Find the next one + int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size() + 1; + Table table = (Table)createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tableNumber); tbl.setId(table.getPackageRelationship().getId()); tables.put(tbl.getId(), table); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 84ec2a7ce..d716cea47 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -924,6 +924,33 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { t = s3.getTables().get(0); assertEquals("New 3", t.getName()); assertEquals("New 3", t.getDisplayName()); + + // Check the relationships + assertEquals(0, s1.getRelations().size()); + assertEquals(3, s2.getRelations().size()); + assertEquals(1, s3.getRelations().size()); + assertEquals(0, s4.getRelations().size()); + + assertEquals( + XSSFRelation.PRINTER_SETTINGS.getContentType(), + s2.getRelations().get(0).getPackagePart().getContentType() + ); + assertEquals( + XSSFRelation.TABLE.getContentType(), + s2.getRelations().get(1).getPackagePart().getContentType() + ); + assertEquals( + XSSFRelation.TABLE.getContentType(), + s2.getRelations().get(2).getPackagePart().getContentType() + ); + assertEquals( + XSSFRelation.TABLE.getContentType(), + s3.getRelations().get(0).getPackagePart().getContentType() + ); + assertEquals( + "/xl/tables/table3.xml", + s3.getRelations().get(0).getPackagePart().getPartName().toString() + ); } /**