]> source.dussan.org Git - poi.git/commitdiff
Fix bug #51061 - Correct target URI for new XSSF Tables
authorNick Burch <nick@apache.org>
Thu, 14 Apr 2011 14:29:04 +0000 (14:29 +0000)
committerNick Burch <nick@apache.org>
Thu, 14 Apr 2011 14:29:04 +0000 (14:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1092281 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java

index 93500e6625d792eb970f71656f399fa478765225..b01bf5e9832faacd1bff0d9931a15918ef22b9a6 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta3" date="2011-??-??">
+           <action dev="poi-developers" type="fix">51061 - Correct target URI for new XSSF Tables</action>
            <action dev="poi-developers" type="add">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.</action>
            <action dev="poi-developers" type="fix">50884 - XSSF and HSSF freeze panes now behave the same</action>
            <action dev="poi-developers" type="add">Support for adding a table to a XSSFSheet</action>
index cae8b5f80232251d453b9446d874c139758e8b08..b49d6c2d3b7ec733d95e8a33e8811c20185d6bea 100644 (file)
@@ -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<? extends POIXMLDocumentPart> cls) {
index 887ff0eab90108c6fdac04469349cdd4b1156d29..163da4d262ef155dc905147873501822c94a8485 100644 (file)
@@ -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);
index 84ec2a7ce0f8e823a3f8991f1872f6c3eb7d5c2f..d716cea47175f4e6a9e418b6b30cb260898170a8 100644 (file)
@@ -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()
+       );
     }
     
     /**