From 5cf593d1c7f80e07ff366c538bc21a770aa48a95 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 25 Feb 2011 21:44:09 +0000 Subject: [PATCH] Fix bug #50829 - Support for getting the tables associated with a XSSFSheet git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1074710 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../java/org/apache/poi/xssf/model/Table.java | 14 +++++++++ .../apache/poi/xssf/usermodel/XSSFSheet.java | 15 +++++++++ .../poi/xssf/usermodel/TestXSSFSheet.java | 29 ++++++++++++++++++ test-data/spreadsheet/WithTable.xlsx | Bin 0 -> 9400 bytes 5 files changed, 59 insertions(+) create mode 100644 test-data/spreadsheet/WithTable.xlsx diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index bf64050a3a..85e9519a1b 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 50829 - Support for getting the tables associated with a XSSFSheet 50299 - More XSSFColor updates for ARGB vs RGB 50581 - Use stax:stax-api instead of org.apache.geronimo.specs:geronimo-stax-api_1.0_spec 50786 - Fix XSSFColor to fetch the RGB values of old-style indexed colours diff --git a/src/ooxml/java/org/apache/poi/xssf/model/Table.java b/src/ooxml/java/org/apache/poi/xssf/model/Table.java index f69c85c46c..412a425cac 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/Table.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/Table.java @@ -185,6 +185,20 @@ public class Table extends POIXMLDocumentPart { } return xmlColumnPr; } + + /** + * @return the name of the Table, if set + */ + public String getName() { + return ctTable.getName(); + } + + /** + * @return the display name of the Table, if set + */ + public String getDisplayName() { + return ctTable.getDisplayName(); + } /** * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) 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 0fcd1d1103..73628516a6 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -55,6 +55,7 @@ import org.apache.poi.util.Internal; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; import org.apache.poi.xssf.model.CommentsTable; +import org.apache.poi.xssf.model.Table; import org.apache.poi.xssf.usermodel.helpers.ColumnHelper; import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter; import org.apache.xmlbeans.XmlException; @@ -2954,4 +2955,18 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { return new XSSFAutoFilter(this); } + + /** + * Returns any tables associated with this Sheet + */ + public List getTables() { + List
tables = new ArrayList
(); + for(POIXMLDocumentPart p : getRelations()) { + if (p.getPackageRelationship().getRelationshipType().equals(XSSFRelation.TABLE.getRelation())) { + Table table = (Table) p; + tables.add(table); + } + } + return tables; + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 56a7004d4a..410ab61eb9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -17,6 +17,8 @@ package org.apache.poi.xssf.usermodel; +import java.util.List; + import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.xssf.XSSFITestDataProvider; @@ -24,6 +26,7 @@ import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.model.CommentsTable; import org.apache.poi.xssf.model.StylesTable; import org.apache.poi.xssf.model.CalculationChain; +import org.apache.poi.xssf.model.Table; import org.apache.poi.xssf.usermodel.helpers.ColumnHelper; import org.apache.poi.util.HexDump; import org.apache.poi.hssf.record.PasswordRecord; @@ -1035,4 +1038,30 @@ public final class TestXSSFSheet extends BaseTestSheet { } + /** + * See bug #50829 + */ + public void testTables() { + XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithTable.xlsx"); + assertEquals(3, wb.getNumberOfSheets()); + + // Check the table sheet + XSSFSheet s1 = wb.getSheetAt(0); + assertEquals("a", s1.getRow(0).getCell(0).getRichStringCellValue().toString()); + assertEquals(1.0, s1.getRow(1).getCell(0).getNumericCellValue()); + + List
tables = s1.getTables(); + assertNotNull(tables); + assertEquals(1, tables.size()); + + Table table = tables.get(0); + assertEquals("Tabella1", table.getName()); + assertEquals("Tabella1", table.getDisplayName()); + + // And the others + XSSFSheet s2 = wb.getSheetAt(1); + assertEquals(0, s2.getTables().size()); + XSSFSheet s3 = wb.getSheetAt(2); + assertEquals(0, s3.getTables().size()); + } } diff --git a/test-data/spreadsheet/WithTable.xlsx b/test-data/spreadsheet/WithTable.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..5177e0abba36fd100da15f6ea224b60ef6e0cd93 GIT binary patch literal 9400 zcmeHNWmHvbx88J0NeM`IZj=rI3F(psr8_nq5(>zsrMtU31(9ytgrwjGBm||qxm(Wp zKF>kFJMOqY?>%dbwbxireeH+6c(?rv*CnLPo=mT*gQqB!qUPAHOF zNSa;+bLI#5N906jiWsb8Ig2+p&)mbgYWYYlAzv2lxHG0eaV~83eujQYL0iHa)go1) zn{q1@)n>J}Dpc)V%cDa($=A818UZztA#9n%5$qh%Q)MV&?hV~)%Mw?LvO|uH1U(S{ z6<#MISxGNa!m$#YB0|c*%d7CARJzLX9CY!pXq3bfb+OSUFvWK4P#D4JxOfqLpX~Nd?2&C~$&nxf|GUHC| zm=7}JYMKi&ke6JS_><=pG{%i6{^8g7uUoQlJ&kHTTQ0l-ku*YRkeuZ;z)=Y)iirUq1h4Cyknw*DNpHOr=KNM!Q8(7oI~adVKU6 z!B5tBcJ%1$u!t^nYt>SXg3O3Rv9pO$tm>hW=aiLuS%wC7rV+KdC4Mi-8!|)9&rlnE z_uSYNq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