<changes>
<release version="3.8-beta1" date="2010-??-??">
+ <action dev="poi-developers" type="add">50829 - Support for getting the tables associated with a XSSFSheet</action>
<action dev="poi-developers" type="fix">50299 - More XSSFColor updates for ARGB vs RGB</action>
<action dev="poi-developers" type="fix">50581 - Use stax:stax-api instead of org.apache.geronimo.specs:geronimo-stax-api_1.0_spec</action>
<action dev="poi-developers" type="fix">50786 - Fix XSSFColor to fetch the RGB values of old-style indexed colours</action>
}
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)
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;
return new XSSFAutoFilter(this);
}
+
+ /**
+ * Returns any tables associated with this Sheet
+ */
+ public List<Table> getTables() {
+ List<Table> tables = new ArrayList<Table>();
+ for(POIXMLDocumentPart p : getRelations()) {
+ if (p.getPackageRelationship().getRelationshipType().equals(XSSFRelation.TABLE.getRelation())) {
+ Table table = (Table) p;
+ tables.add(table);
+ }
+ }
+ return tables;
+ }
}
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;
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;
}
+ /**
+ * 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<Table> 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());
+ }
}