Search in sources :

Example 6 with CTTable

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;
}
Also used : CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable)

Example 7 with CTTable

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;
}
Also used : CTTablePartStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTTablePartStyle) TablePartStyle(org.apache.poi.xslf.usermodel.XSLFTableStyle.TablePartStyle) CTTablePartStyle(org.openxmlformats.schemas.drawingml.x2006.main.CTTablePartStyle) CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable) CTTableProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTTableProperties) DrawPaint(org.apache.poi.sl.draw.DrawPaint) SolidPaint(org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)

Example 8 with CTTable

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);
}
Also used : TableDocument(org.openxmlformats.schemas.spreadsheetml.x2006.main.TableDocument)

Example 9 with CTTable

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();
}
Also used : CTTableStyleInfo(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo) CTTable(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Example 10 with CTTable

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());
}
Also used : CTTable(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CellReference(org.apache.poi.ss.util.CellReference) Test(org.junit.Test)

Aggregations

CTTable (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable)5 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)4 Test (org.junit.Test)4 CTTable (org.openxmlformats.schemas.drawingml.x2006.main.CTTable)4 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 CellReference (org.apache.poi.ss.util.CellReference)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 XmlException (org.apache.xmlbeans.XmlException)2 CTGraphicalObjectData (org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData)2 CTGraphicalObjectFrame (org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame)2 CTTableColumn (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn)2 CTTableStyleInfo (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo)2 TableDocument (org.openxmlformats.schemas.spreadsheetml.x2006.main.TableDocument)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 QName (javax.xml.namespace.QName)1 POIXMLException (org.apache.poi.POIXMLException)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1