use of org.xlsx4j.sml.CTTableColumns in project com.revolsys.open by revolsys.
the class XlsxRecordWriter method close.
/**
* Closes the underlying reader.
*/
@Override
public synchronized void close() {
if (this.out != null) {
try {
final long fieldCount = this.recordDefinition.getFieldCount();
final String ref = "A1:" + getRef(fieldCount, this.sheetRows.size());
final TablePart tablePart = new TablePart();
this.spreadsheetPackage.addTargetPart(tablePart);
final CTTable table = smlObjectFactory.createCTTable();
tablePart.setContents(table);
table.setId(1);
table.setName("Table1");
table.setDisplayName(this.recordDefinition.getName());
table.setRef(ref);
final CTAutoFilter autoFilter = smlObjectFactory.createCTAutoFilter();
autoFilter.setRef(ref);
table.setAutoFilter(autoFilter);
long columnIndex = 1;
final CTTableColumns tableColumns = smlObjectFactory.createCTTableColumns();
tableColumns.setCount(fieldCount);
table.setTableColumns(tableColumns);
final List<CTTableColumn> columns = tableColumns.getTableColumn();
for (final String fieldName : this.recordDefinition.getFieldNames()) {
final CTTableColumn column = smlObjectFactory.createCTTableColumn();
column.setId(columnIndex);
column.setName(fieldName);
columns.add(column);
columnIndex++;
}
final CTTableStyleInfo tableStyleInfo = smlObjectFactory.createCTTableStyleInfo();
table.setTableStyleInfo(tableStyleInfo);
tableStyleInfo.setName("TableStyleMedium14");
tableStyleInfo.setShowFirstColumn(false);
tableStyleInfo.setShowLastColumn(false);
tableStyleInfo.setShowRowStripes(true);
tableStyleInfo.setShowColumnStripes(false);
this.sheet.addTargetPart(tablePart, "rId1");
final Save save = new Save(this.spreadsheetPackage);
save.save(this.out);
try {
this.out.flush();
} catch (final IOException e) {
}
} catch (final Docx4JException e) {
throw Exceptions.wrap(e);
} finally {
FileUtil.closeSilent(this.out);
this.out = null;
this.sheet = null;
this.sheetData = null;
this.spreadsheetPackage = null;
this.sheetRows = Collections.emptyList();
}
}
}
Aggregations