|
|
@@ -3957,24 +3957,40 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { |
|
|
|
* Creates a new Table, and associates it with this Sheet |
|
|
|
*/ |
|
|
|
public XSSFTable createTable() { |
|
|
|
if(! worksheet.isSetTableParts()) { |
|
|
|
worksheet.addNewTableParts(); |
|
|
|
} |
|
|
|
if(! worksheet.isSetTableParts()) { |
|
|
|
worksheet.addNewTableParts(); |
|
|
|
} |
|
|
|
|
|
|
|
CTTableParts tblParts = worksheet.getTableParts(); |
|
|
|
CTTablePart tbl = tblParts.addNewTablePart(); |
|
|
|
|
|
|
|
// Table numbers need to be unique in the file, not just |
|
|
|
// unique within the sheet. Find the next one |
|
|
|
int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size() + 1; |
|
|
|
|
|
|
|
// the id could already be taken after insertion/deletion of different tables |
|
|
|
outerloop: |
|
|
|
while(true) { |
|
|
|
for (PackagePart packagePart : getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType())) { |
|
|
|
String fileName = XSSFRelation.TABLE.getFileName(tableNumber); |
|
|
|
if(fileName.equals(packagePart.getPartName().getName())) { |
|
|
|
// duplicate found, increase the number and start iterating again |
|
|
|
tableNumber++; |
|
|
|
continue outerloop; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
CTTableParts tblParts = worksheet.getTableParts(); |
|
|
|
CTTablePart tbl = tblParts.addNewTablePart(); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
// Table numbers need to be unique in the file, not just |
|
|
|
// unique within the sheet. Find the next one |
|
|
|
int tableNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.TABLE.getContentType()).size() + 1; |
|
|
|
RelationPart rp = createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tableNumber, false); |
|
|
|
XSSFTable table = rp.getDocumentPart(); |
|
|
|
tbl.setId(rp.getRelationship().getId()); |
|
|
|
table.getCTTable().setId(tableNumber); |
|
|
|
RelationPart rp = createRelationship(XSSFRelation.TABLE, XSSFFactory.getInstance(), tableNumber, false); |
|
|
|
XSSFTable table = rp.getDocumentPart(); |
|
|
|
tbl.setId(rp.getRelationship().getId()); |
|
|
|
table.getCTTable().setId(tableNumber); |
|
|
|
|
|
|
|
tables.put(tbl.getId(), table); |
|
|
|
tables.put(tbl.getId(), table); |
|
|
|
|
|
|
|
return table; |
|
|
|
return table; |
|
|
|
} |
|
|
|
|
|
|
|
/** |