mirror of https://github.com/apache/poi.git
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
This commit is contained in:
parent
6ef52df6dd
commit
5cf593d1c7
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta1" date="2010-??-??">
|
<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">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">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>
|
<action dev="poi-developers" type="fix">50786 - Fix XSSFColor to fetch the RGB values of old-style indexed colours</action>
|
||||||
|
|
|
@ -186,6 +186,20 @@ public class Table extends POIXMLDocumentPart {
|
||||||
return xmlColumnPr;
|
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)
|
* @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -55,6 +55,7 @@ import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.apache.poi.xssf.model.CommentsTable;
|
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.ColumnHelper;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
|
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
|
@ -2954,4 +2955,18 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
||||||
|
|
||||||
return new XSSFAutoFilter(this);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.*;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
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.CommentsTable;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.xssf.model.CalculationChain;
|
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.xssf.usermodel.helpers.ColumnHelper;
|
||||||
import org.apache.poi.util.HexDump;
|
import org.apache.poi.util.HexDump;
|
||||||
import org.apache.poi.hssf.record.PasswordRecord;
|
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<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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue