<changes>
<release version="3.8-beta3" date="2011-??-??">
+ <action dev="poi-developers" type="add">Support for adding a table to a XSSFSheet</action>
<action dev="poi-developers" type="add">Improve HSMF MAPIMessage access to the HTML and RTF versions of the message body (where available)</action>
<action dev="poi-developers" type="add">Add new method to HSMF of MAPIMessage.has7BitEncodingStrings() to make it easier to decide when encoding guessing is needed</action>
<action dev="poi-developers" type="fix">OutlookTextExtractor now requests 7 bit encoding guessing</action>
public String getName() {
return ctTable.getName();
}
+
+ /**
+ * Changes the name of the Table
+ */
+ public void setName(String name) {
+ if(name == null) {
+ ctTable.unsetName();
+ return;
+ }
+ ctTable.setName(name);
+ }
/**
* @return the display name of the Table, if set
return ctTable.getDisplayName();
}
+ /**
+ * Changes the display name of the Table
+ */
+ public void setDisplayName(String name) {
+ ctTable.setDisplayName(name);
+ }
+
/**
* @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4)
*/
* Master shared formula is the first formula in a group of shared formulas is saved in the f element.
*/
private Map<Integer, CTCellFormula> sharedFormulas;
+ private TreeMap<String,Table> tables;
private List<CellRangeAddress> arrayFormulas;
private XSSFDataValidationHelper dataValidationHelper;
sheetComments = (CommentsTable)p;
break;
}
+ if(p instanceof Table) {
+ tables.put( p.getPackageRelationship().getId(), (Table)p );
+ }
}
// Process external hyperlinks for the sheet, if there are any
@SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
private void initRows(CTWorksheet worksheet) {
_rows = new TreeMap<Integer, XSSFRow>();
+ tables = new TreeMap<String, Table>();
sharedFormulas = new HashMap<Integer, CTCellFormula>();
arrayFormulas = new ArrayList<CellRangeAddress>();
for (CTRow row : worksheet.getSheetData().getRowArray()) {
return new XSSFAutoFilter(this);
}
+ /**
+ * Creates a new Table, and associates it with this Sheet
+ */
+ public Table createTable() {
+ if(! worksheet.isSetTableParts()) {
+ worksheet.addNewTableParts();
+ }
+
+ CTTableParts tblParts = worksheet.getTableParts();
+ CTTablePart tbl = tblParts.addNewTablePart();
+
+ Table table = (Table)createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tblParts.sizeOfTablePartArray());
+ tbl.setId(table.getPackageRelationship().getId());
+
+ tables.put(tbl.getId(), table);
+
+ return table;
+ }
+
/**
* 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;
+ List<Table> tableList = new ArrayList<Table>(
+ tables.values()
+ );
+ return tableList;
}
}
assertEquals("Tabella1", t.getName());
assertEquals("Tabella1", t.getDisplayName());
assertEquals("A1:C3", t.getCTTable().getRef());
+
+
+ // Add some more tables, and check
+ t = s2.createTable();
+ t.setName("New 2");
+ t.setDisplayName("New 2");
+ t = s3.createTable();
+ t.setName("New 3");
+ t.setDisplayName("New 3");
+
+ wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
+ s1 = wb.getSheetAt(0);
+ s2 = wb.getSheetAt(1);
+ s3 = wb.getSheetAt(2);
+ s4 = wb.getSheetAt(3);
+ assertEquals(0, s1.getTables().size());
+ assertEquals(2, s2.getTables().size());
+ assertEquals(1, s3.getTables().size());
+ assertEquals(0, s4.getTables().size());
+
+ t = s2.getTables().get(0);
+ assertEquals("Tabella1", t.getName());
+ assertEquals("Tabella1", t.getDisplayName());
+ assertEquals("A1:C3", t.getCTTable().getRef());
+
+ t = s2.getTables().get(1);
+ assertEquals("New 2", t.getName());
+ assertEquals("New 2", t.getDisplayName());
+
+ t = s3.getTables().get(0);
+ assertEquals("New 3", t.getName());
+ assertEquals("New 3", t.getDisplayName());
}
/**