Browse Source

Add support for adding a table to a XSSFSheet

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1090289 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_8_BETA3
Nick Burch 13 years ago
parent
commit
e9b19a79f7

+ 1
- 0
src/documentation/content/xdocs/status.xml View File



<changes> <changes>
<release version="3.8-beta3" date="2011-??-??"> <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">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="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> <action dev="poi-developers" type="fix">OutlookTextExtractor now requests 7 bit encoding guessing</action>

+ 18
- 0
src/ooxml/java/org/apache/poi/xssf/model/Table.java View File

public String getName() { public String getName() {
return ctTable.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 the display name of the Table, if set
return ctTable.getDisplayName(); 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) * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4)
*/ */

+ 28
- 8
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java View File

* Master shared formula is the first formula in a group of shared formulas is saved in the f element. * 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 Map<Integer, CTCellFormula> sharedFormulas;
private TreeMap<String,Table> tables;
private List<CellRangeAddress> arrayFormulas; private List<CellRangeAddress> arrayFormulas;
private XSSFDataValidationHelper dataValidationHelper; private XSSFDataValidationHelper dataValidationHelper;


sheetComments = (CommentsTable)p; sheetComments = (CommentsTable)p;
break; break;
} }
if(p instanceof Table) {
tables.put( p.getPackageRelationship().getId(), (Table)p );
}
} }
// Process external hyperlinks for the sheet, if there are any // 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 @SuppressWarnings("deprecation") //YK: getXYZArray() array accessors are deprecated in xmlbeans with JDK 1.5 support
private void initRows(CTWorksheet worksheet) { private void initRows(CTWorksheet worksheet) {
_rows = new TreeMap<Integer, XSSFRow>(); _rows = new TreeMap<Integer, XSSFRow>();
tables = new TreeMap<String, Table>();
sharedFormulas = new HashMap<Integer, CTCellFormula>(); sharedFormulas = new HashMap<Integer, CTCellFormula>();
arrayFormulas = new ArrayList<CellRangeAddress>(); arrayFormulas = new ArrayList<CellRangeAddress>();
for (CTRow row : worksheet.getSheetData().getRowArray()) { for (CTRow row : worksheet.getSheetData().getRowArray()) {
return new XSSFAutoFilter(this); 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 * Returns any tables associated with this Sheet
*/ */
public List<Table> getTables() { 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;
} }
} }

+ 32
- 0
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java View File

assertEquals("Tabella1", t.getName()); assertEquals("Tabella1", t.getName());
assertEquals("Tabella1", t.getDisplayName()); assertEquals("Tabella1", t.getDisplayName());
assertEquals("A1:C3", t.getCTTable().getRef()); 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());
} }
/** /**

Loading…
Cancel
Save