Search in sources :

Example 6 with CTTable

use of org.openxmlformats.schemas.drawingml.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)

Example 7 with CTTable

use of org.openxmlformats.schemas.drawingml.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 8 with CTTable

use of org.openxmlformats.schemas.drawingml.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 9 with CTTable

use of org.openxmlformats.schemas.drawingml.x2006.main.CTTable in project poi by apache.

the class XSLFCommonSlideData method getDrawingText.

public List<DrawingTextBody> getDrawingText() {
    CTGroupShape gs = data.getSpTree();
    List<DrawingTextBody> out = new ArrayList<DrawingTextBody>();
    processShape(gs, out);
    for (CTGroupShape shape : gs.getGrpSpArray()) {
        processShape(shape, out);
    }
    for (CTGraphicalObjectFrame frame : gs.getGraphicFrameArray()) {
        CTGraphicalObjectData data = frame.getGraphic().getGraphicData();
        XmlCursor c = data.newCursor();
        c.selectPath("declare namespace pic='" + CTTable.type.getName().getNamespaceURI() + "' .//pic:tbl");
        while (c.toNextSelection()) {
            XmlObject o = c.getObject();
            if (o instanceof XmlAnyTypeImpl) {
                // Pesky XmlBeans bug - see Bugzilla #49934
                try {
                    o = CTTable.Factory.parse(o.toString(), DEFAULT_XML_OPTIONS);
                } catch (XmlException e) {
                    throw new POIXMLException(e);
                }
            }
            if (o instanceof CTTable) {
                DrawingTable table = new DrawingTable((CTTable) o);
                for (DrawingTableRow row : table.getRows()) {
                    for (DrawingTableCell cell : row.getCells()) {
                        DrawingTextBody textBody = cell.getTextBody();
                        out.add(textBody);
                    }
                }
            }
        }
        c.dispose();
    }
    return out;
}
Also used : CTGraphicalObjectFrame(org.openxmlformats.schemas.presentationml.x2006.main.CTGraphicalObjectFrame) ArrayList(java.util.ArrayList) POIXMLException(org.apache.poi.POIXMLException) CTGroupShape(org.openxmlformats.schemas.presentationml.x2006.main.CTGroupShape) XmlCursor(org.apache.xmlbeans.XmlCursor) CTGraphicalObjectData(org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData) XmlException(org.apache.xmlbeans.XmlException) CTTable(org.openxmlformats.schemas.drawingml.x2006.main.CTTable) XmlAnyTypeImpl(org.apache.xmlbeans.impl.values.XmlAnyTypeImpl) XmlObject(org.apache.xmlbeans.XmlObject)

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 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 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 QName (javax.xml.namespace.QName)1 POIXMLException (org.apache.poi.POIXMLException)1 DrawPaint (org.apache.poi.sl.draw.DrawPaint)1 SolidPaint (org.apache.poi.sl.usermodel.PaintStyle.SolidPaint)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1