ASF Bugzilla – Attachment 36562 Details for
Bug 63400
XSSFSheet.createTable should add a default table style
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
This is a patch illustrating the suggested enhancement
file_63400.txt (text/plain), 3.56 KB, created by
David Gauntt
on 2019-05-04 16:34:09 UTC
(
hide
)
Description:
This is a patch illustrating the suggested enhancement
Filename:
MIME Type:
Creator:
David Gauntt
Created:
2019-05-04 16:34:09 UTC
Size:
3.56 KB
patch
obsolete
> /** > * Creates a new Table, and associates it with this Sheet. > * <p> > * The table is assigned a default display name (since 4.1.1) which can be overridden > * by calling {@code setDisplayName}. The default display name is guaranteed to not conflict > * with the names of any {@code XSSFName} or {@code XSSFTable} in the workbook. > * > * @param tableArea > * the area that the table should cover, should not be null > * @return the created table > * @since 4.0.0 > */ > public XSSFTable createTable(AreaReference tableArea) { > 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 > boolean loop = true; > while(loop) { > loop = false; > 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++; > loop = true; > } > } > } > > 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); > > if(tableArea != null) { > table.setArea(tableArea); > } > > // Bug fix 62906 > // Set the default name of the table. This must not conflict with any defined names. > final boolean bUseDMGFix=true; > > if(bUseDMGFix) { > final XSSFWorkbook workbook=getWorkbook(); > > while(tableNumber<Integer.MAX_VALUE) { > final String displayName="Table"+tableNumber; > if(!XSSFTable.isInvalidTableName(workbook,displayName)) { > System.out.println(String.format("%s: displayName=%s","XSSFSheet.createTable",displayName)); > table.setDisplayName(displayName); > table.setName(displayName); > break; > } > ++tableNumber; > } > > } else { > // Bug 62906: Must set a display name; can be overridden using setDisplayName > final String displayName = "Table" + tableNumber; > table.setDisplayName(displayName); > > } > > // Enhancement > table.getCTTable().addNewTableStyleInfo(); > table.getCTTable().getTableStyleInfo().setName("TableStyleMedium2"); > > // Style the table > XSSFTableStyleInfo style = (XSSFTableStyleInfo) table.getStyle(); > style.setName("TableStyleMedium2"); > style.setShowColumnStripes(false); > style.setShowRowStripes(true); > style.setFirstColumn(false); > style.setLastColumn(false); > > > return table; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 63400
: 36562