@Override public XSLFTableCell getCell(int row, int col) { List<XSLFTableRow> rows = getRows(); if (row < 0 || rows.size() <= row) { return null; } XSLFTableRow r = rows.get(row); if (r == null) { // empty row return null; } List<XSLFTableCell> cells = r.getCells(); if (col < 0 || cells.size() <= col) { return null; } // cell can be potentially empty ... return cells.get(col); }
public XSLFTableRow addRow(){ CTTableRow tr = _table.addNewTr(); XSLFTableRow row = new XSLFTableRow(tr, this); // default height is 20 points row.setHeight(20.0); _rows.add(row); updateRowColIndexes(); return row; }
@Override public XSLFTable createTable(int numRows, int numCols){ if (numRows < 1 || numCols < 1) { throw new IllegalArgumentException("numRows and numCols must be greater than 0"); } XSLFTable sh = getDrawing().createTable(); _shapes.add(sh); sh.setParent(this); for (int r=0; r<numRows; r++) { XSLFTableRow row = sh.addRow(); for (int c=0; c<numCols; c++) { row.addCell(); } } return sh; }
XSLFTableRow titleRow = tbl.addRow(); titleRow.setHeight(50); XSLFTableCell titleCell1 = titleRow.addCell(); XSLFTextParagraph p1 = titleCell1.addNewTextParagraph(); p1.setTextAlign(TextAlign.CENTER); XSLFTextRun r1 = p1.addNewTextRun(); r1.setText("Column title"); r1.setBold(true); r1.setFontColor(new Color(0, 104, 145)); titleCell1.setFillColor(new Color(190, 230, 245)); r1.setFontSize(25.0); titleCell1.setVerticalAlignment(VerticalAlignment.MIDDLE);
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape, sheet); CTGraphicalObjectData god = shape.getGraphic().getGraphicData(); XmlCursor xc = god.newCursor(); try { if (!xc.toChild(XSLFRelation.NS_DRAWINGML, "tbl")) { throw new IllegalStateException("a:tbl element was not found in\n " + god); } XmlObject xo = xc.getObject(); // Pesky XmlBeans bug - see Bugzilla #49934 // it never happens when using the full ooxml-schemas jar but may happen with the abridged poi-ooxml-schemas if (xo instanceof XmlAnyTypeImpl){ String errStr = "Schemas (*.xsb) for CTTable can't be loaded - usually this happens when OSGI " + "loading is used and the thread context classloader has no reference to " + "the xmlbeans classes" ; throw new IllegalStateException(errStr); } _table = (CTTable)xo; } finally { xc.dispose(); } _rows = new ArrayList<>(_table.sizeOfTrArray()); for(CTTableRow row : _table.getTrList()) { _rows.add(new XSLFTableRow(row, this)); } updateRowColIndexes(); }
int numRows = 5; XSLFTableRow headerRow = tbl.addRow(); headerRow.setHeight(50); XSLFTableCell th = headerRow.addCell(); XSLFTextParagraph p = th.addNewTextParagraph(); p.setTextAlign(TextAlign.CENTER); tr.setHeight(50); XSLFTableCell cell = tr.addCell(); XSLFTextParagraph p = cell.addNewTextParagraph(); XSLFTextRun r = p.addNewTextRun();
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape, sheet); CTGraphicalObjectData god = shape.getGraphic().getGraphicData(); XmlCursor xc = god.newCursor(); try { if (!xc.toChild(XSLFRelation.NS_DRAWINGML, "tbl")) { throw new IllegalStateException("a:tbl element was not found in\n " + god); } XmlObject xo = xc.getObject(); // Pesky XmlBeans bug - see Bugzilla #49934 // it never happens when using the full ooxml-schemas jar but may happen with the abridged poi-ooxml-schemas if (xo instanceof XmlAnyTypeImpl){ String errStr = "Schemas (*.xsb) for CTTable can't be loaded - usually this happens when OSGI " + "loading is used and the thread context classloader has no reference to " + "the xmlbeans classes" ; throw new IllegalStateException(errStr); } _table = (CTTable)xo; } finally { xc.dispose(); } _rows = new ArrayList<>(_table.sizeOfTrArray()); for(CTTableRow row : _table.getTrList()) { _rows.add(new XSLFTableRow(row, this)); } updateRowColIndexes(); }
XSLFTableCell cell = row.getCells().get(colPos);
public XSLFTableRow addRow(){ CTTableRow tr = _table.addNewTr(); XSLFTableRow row = new XSLFTableRow(tr, this); row.setHeight(20.0); // default height is 20 points _rows.add(row); return row; }
@Override public XSLFTable createTable(int numRows, int numCols){ if (numRows < 1 || numCols < 1) { throw new IllegalArgumentException("numRows and numCols must be greater than 0"); } XSLFTable sh = getDrawing().createTable(); getShapes().add(sh); sh.setParent(this); for (int r=0; r<numRows; r++) { XSLFTableRow row = sh.addRow(); for (int c=0; c<numCols; c++) { row.addCell(); } } return sh; }
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape, sheet); XmlObject[] rs = shape.getGraphic().getGraphicData() .selectPath("declare namespace a='http://schemas.openxmlformats.org/drawingml/2006/main' ./a:tbl"); if (rs.length == 0) { throw new IllegalStateException("a:tbl element was not found in\n " + shape.getGraphic().getGraphicData()); } // Pesky XmlBeans bug - see Bugzilla #49934 // it never happens when using the full ooxml-schemas jar but may happen with the abridged poi-ooxml-schemas if(rs[0] instanceof XmlAnyTypeImpl){ try { rs[0] = CTTable.Factory.parse(rs[0].toString()); }catch (XmlException e){ throw new POIXMLException(e); } } _table = (CTTable) rs[0]; _rows = new ArrayList<XSLFTableRow>(_table.sizeOfTrArray()); for(CTTableRow row : _table.getTrList()) _rows.add(new XSLFTableRow(row, this)); }
private void extractTable(XSLFTable tbl, XHTMLContentHandler xhtml) throws SAXException { xhtml.startElement("table"); for (XSLFTableRow row : tbl) { xhtml.startElement("tr"); for (XSLFTableCell c : row.getCells()) { xhtml.startElement("td"); //TODO: Need to wait for fix in POI to test for hyperlink first //shouldn't need to catch NPE... XSLFHyperlink hyperlink = null; try { hyperlink = c.getHyperlink(); } catch (NullPointerException e) { //swallow } if (hyperlink != null && hyperlink.getAddress() != null) { xhtml.startElement("a", "href", hyperlink.getAddress()); } xhtml.characters(c.getText()); if (hyperlink != null && hyperlink.getAddress() != null) { xhtml.endElement("a"); } xhtml.endElement("td"); } xhtml.endElement("tr"); } xhtml.endElement("table"); }
public XSLFTableRow addRow(){ CTTableRow tr = _table.addNewTr(); XSLFTableRow row = new XSLFTableRow(tr, this); // default height is 20 points row.setHeight(20.0); _rows.add(row); updateRowColIndexes(); return row; }
XSLFTableRow headerRow = table.addRow(); for(int i = 0; i < 3; i++) { XSLFTableCell th = headerRow.addCell(); XSLFTextParagraph p = th.addNewTextParagraph(); XSLFTextRun r = p.addNewTextRun(); r.setText("Text"); }
@Override public XSLFTableCell getCell(int row, int col) { List<XSLFTableRow> rows = getRows(); if (row < 0 || rows.size() <= row) { return null; } XSLFTableRow r = rows.get(row); if (r == null) { // empty row return null; } List<XSLFTableCell> cells = r.getCells(); if (col < 0 || cells.size() <= col) { return null; } // cell can be potentially empty ... return cells.get(col); }
@Override public XSLFTable createTable(int numRows, int numCols){ if (numRows < 1 || numCols < 1) { throw new IllegalArgumentException("numRows and numCols must be greater than 0"); } XSLFTable sh = getDrawing().createTable(); _shapes.add(sh); sh.setParent(this); for (int r=0; r<numRows; r++) { XSLFTableRow row = sh.addRow(); for (int c=0; c<numCols; c++) { row.addCell(); } } return sh; }
XSLFTableCell cell = row.getCells().get(colPos);
@Override public XSLFTable createTable(int numRows, int numCols){ if (numRows < 1 || numCols < 1) { throw new IllegalArgumentException("numRows and numCols must be greater than 0"); } XSLFTable sh = getDrawing().createTable(); getShapes().add(sh); sh.setParent(this); for (int r=0; r<numRows; r++) { XSLFTableRow row = sh.addRow(); for (int c=0; c<numCols; c++) { row.addCell(); } } return sh; }
XSLFTableCell cell = row.getCells().get(colPos);