use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable in project poi by apache.
the class XSLFTable method getTableStyle.
/**
* Get assigned TableStyle
*
* @return the assigned TableStyle
*
* @since POI 3.15-beta2
*/
protected XSLFTableStyle getTableStyle() {
CTTable tab = getCTTable();
// TODO: support inline table style
if (!tab.isSetTblPr() || !tab.getTblPr().isSetTableStyleId()) {
return null;
}
String styleId = tab.getTblPr().getTableStyleId();
XSLFTableStyles styles = getSheet().getSlideShow().getTableStyles();
for (XSLFTableStyle style : styles.getStyles()) {
if (style.getStyleId().equals(styleId)) {
return style;
}
}
return null;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable in project poi by apache.
the class XSLFTableCell method getTablePartStyle.
/**
* Retrieves the part style depending on the location of this cell
*
* @param tablePartStyle the part to be returned, usually this is null
* and only set when used as a helper method
* @return the table part style
*/
private CTTablePartStyle getTablePartStyle(TablePartStyle tablePartStyle) {
CTTable ct = table.getCTTable();
if (!ct.isSetTblPr()) {
return null;
}
CTTableProperties pr = ct.getTblPr();
boolean bandRow = (pr.isSetBandRow() && pr.getBandRow());
boolean firstRow = (pr.isSetFirstRow() && pr.getFirstRow());
boolean lastRow = (pr.isSetLastRow() && pr.getLastRow());
boolean bandCol = (pr.isSetBandCol() && pr.getBandCol());
boolean firstCol = (pr.isSetFirstCol() && pr.getFirstCol());
boolean lastCol = (pr.isSetLastCol() && pr.getLastCol());
TablePartStyle tps;
if (tablePartStyle != null) {
tps = tablePartStyle;
} else if (row == 0 && firstRow) {
tps = TablePartStyle.firstRow;
} else if (row == table.getNumberOfRows() - 1 && lastRow) {
tps = TablePartStyle.lastRow;
} else if (col == 0 && firstCol) {
tps = TablePartStyle.firstCol;
} else if (col == table.getNumberOfColumns() - 1 && lastCol) {
tps = TablePartStyle.lastCol;
} else {
tps = TablePartStyle.wholeTbl;
int br = row + (firstRow ? 1 : 0);
int bc = col + (firstCol ? 1 : 0);
if (bandRow && (br & 1) == 0) {
tps = TablePartStyle.band1H;
} else if (bandCol && (bc & 1) == 0) {
tps = TablePartStyle.band1V;
}
}
XSLFTableStyle tabStyle = table.getTableStyle();
if (tabStyle == null) {
return null;
}
CTTablePartStyle part = tabStyle.getTablePartStyle(tps);
return (part == null) ? tabStyle.getTablePartStyle(TablePartStyle.wholeTbl) : part;
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable in project poi by apache.
the class XSSFTable method writeTo.
/**
* write table XML to stream
* @param out
* @throws IOException
*/
public void writeTo(OutputStream out) throws IOException {
updateHeaders();
TableDocument doc = TableDocument.Factory.newInstance();
doc.setTable(ctTable);
doc.save(out, DEFAULT_XML_OPTIONS);
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable in project poi by apache.
the class TestXSSFTable method testCTTableStyleInfo.
@Test
public void testCTTableStyleInfo() throws IOException {
XSSFWorkbook outputWorkbook = new XSSFWorkbook();
XSSFSheet sheet = outputWorkbook.createSheet();
//Create
XSSFTable outputTable = sheet.createTable();
outputTable.setDisplayName("Test");
CTTable outputCTTable = outputTable.getCTTable();
//Style configurations
CTTableStyleInfo outputStyleInfo = outputCTTable.addNewTableStyleInfo();
outputStyleInfo.setName("TableStyleLight1");
outputStyleInfo.setShowColumnStripes(false);
outputStyleInfo.setShowRowStripes(true);
XSSFWorkbook inputWorkbook = XSSFTestDataSamples.writeOutAndReadBack(outputWorkbook);
List<XSSFTable> tables = inputWorkbook.getSheetAt(0).getTables();
assertEquals("Tables number", 1, tables.size());
XSSFTable inputTable = tables.get(0);
assertEquals("Table display name", outputTable.getDisplayName(), inputTable.getDisplayName());
CTTableStyleInfo inputStyleInfo = inputTable.getCTTable().getTableStyleInfo();
assertEquals("Style name", outputStyleInfo.getName(), inputStyleInfo.getName());
assertEquals("Show column stripes", outputStyleInfo.getShowColumnStripes(), inputStyleInfo.getShowColumnStripes());
assertEquals("Show row stripes", outputStyleInfo.getShowRowStripes(), inputStyleInfo.getShowRowStripes());
inputWorkbook.close();
outputWorkbook.close();
}
use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable in project poi by apache.
the class TestXSSFTable method getCellReferences.
@Test
public void getCellReferences() {
// make sure that cached start and end cell references
// can be synchronized with the underlying CTTable
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sh = wb.createSheet();
XSSFTable table = sh.createTable();
CTTable ctTable = table.getCTTable();
ctTable.setRef("B2:E8");
assertEquals(new CellReference("B2"), table.getStartCellReference());
assertEquals(new CellReference("E8"), table.getEndCellReference());
// At this point start and end cell reference are cached
// and may not follow changes to the underlying CTTable
ctTable.setRef("C1:M3");
assertEquals(new CellReference("B2"), table.getStartCellReference());
assertEquals(new CellReference("E8"), table.getEndCellReference());
// Force a synchronization between CTTable and XSSFTable
// start and end cell references
table.updateReferences();
assertEquals(new CellReference("C1"), table.getStartCellReference());
assertEquals(new CellReference("M3"), table.getEndCellReference());
}
Aggregations