private void extractTableText(XHTMLContentHandler xhtml, HSLFTable shape) throws SAXException { xhtml.startElement("table"); for (int row = 0; row < shape.getNumberOfRows(); row++) { xhtml.startElement("tr"); for (int col = 0; col < shape.getNumberOfColumns(); col++) { HSLFTableCell cell = shape.getCell(row, col); //insert empty string for empty cell if cell is null String txt = ""; if (cell != null) { txt = cell.getText(); } xhtml.element("td", txt); } xhtml.endElement("tr"); } xhtml.endElement("table"); }
@Override public void setBorderCompound(BorderEdge edge, LineCompound compound) { if (edge == null || compound == null) { throw new IllegalArgumentException("BorderEdge and/or LineCompound need to be specified."); } HSLFLine l = addLine(edge); l.setLineCompound(compound); }
/** * Create a border to format this table * * @return the created border */ private HSLFLine createBorder(BorderEdge edge) { HSLFTable table = getParent(); HSLFLine line = new HSLFLine(table); table.addShape(line); AbstractEscherOptRecord opt = getEscherOptRecord(); setEscherProperty(opt, EscherProperties.GEOMETRY__SHAPEPATH, -1); setEscherProperty(opt, EscherProperties.GEOMETRY__FILLOK, -1); setEscherProperty(opt, EscherProperties.SHADOWSTYLE__SHADOWOBSURED, 0x20000); setEscherProperty(opt, EscherProperties.THREED__LIGHTFACE, 0x80000); anchorBorder(edge, line); return line; }
case bottom: { if (borderBottom == null) { borderBottom = createBorder(edge); HSLFTableCell c = getSiblingCell(1,0); if (c != null) { assert(c.borderTop == null); borderTop = createBorder(edge); HSLFTableCell c = getSiblingCell(-1,0); if (c != null) { assert(c.borderBottom == null); borderRight = createBorder(edge); HSLFTableCell c = getSiblingCell(0,1); if (c != null) { assert(c.borderLeft == null); borderLeft = createBorder(edge); HSLFTableCell c = getSiblingCell(0,-1); if (c != null) { assert(c.borderRight == null);
Rectangle2D anchor = sh.getAnchor(); colSet.add(anchor.getX()); rowSet.add(anchor.getY()); Rectangle2D anchor = sh.getAnchor(); int row = rowLst.indexOf(anchor.getY()); int col = colLst.indexOf(anchor.getX()); int rowSpan = calcSpan(rowLst, anchor.getHeight(), row); sh.setGridSpan(gridSpan); sh.setRowSpan(rowSpan);
@Override public void setColumnWidth(int col, final double width){ if (col < 0 || col >= cells[0].length) { throw new IllegalArgumentException("Column index '"+col+"' is not within range [0-"+(cells[0].length-1)+"]"); } double currentWidth = cells[0][col].getAnchor().getWidth(); double dx = width - currentWidth; for (HSLFTableCell cols[] : cells) { Rectangle2D anchor = cols[col].getAnchor(); anchor.setRect(anchor.getX(), anchor.getY(), width, anchor.getHeight()); cols[col].setAnchor(anchor); if (col < cols.length - 1) { for (int j = col+1; j < cols.length; j++) { anchor = cols[j].getAnchor(); anchor.setRect(anchor.getX()+dx, anchor.getY(), anchor.getWidth(), anchor.getHeight()); cols[j].setAnchor(anchor); } } } Rectangle2D tblanchor = getAnchor(); tblanchor.setRect(tblanchor.getX(), tblanchor.getY(), tblanchor.getWidth() + dx, tblanchor.getHeight()); setExteriorAnchor(tblanchor); }
@Override public double getRowHeight(int row) { if (row < 0 || row >= cells.length) { throw new IllegalArgumentException("Row index '"+row+"' is not within range [0-"+(cells.length-1)+"]"); } return cells[row][0].getAnchor().getHeight(); }
x = 0; for (int j = 0; j < cells[i].length; j++) { cells[i][j] = new HSLFTableCell(this); Rectangle2D anchor = new Rectangle2D.Double(x, y, HSLFTableCell.DEFAULT_WIDTH, HSLFTableCell.DEFAULT_HEIGHT); cells[i][j].setAnchor(anchor); x += HSLFTableCell.DEFAULT_WIDTH;
@Override public LineDash getLineDash() { return getBorderDash(edge); }
@Override public LineCompound getLineCompound() { return getBorderCompound(edge); }
@Override public void setAnchor(Rectangle2D anchor){ super.setAnchor(anchor); anchorBorder(BorderEdge.top, borderTop); anchorBorder(BorderEdge.right, borderRight); anchorBorder(BorderEdge.bottom, borderBottom); anchorBorder(BorderEdge.left, borderLeft); }
@Override public StrokeStyle getBorderStyle(final BorderEdge edge) { final Double width = getBorderWidth(edge); return (width == null) ? null : new StrokeStyle() { @Override public PaintStyle getPaint() { return DrawPaint.createSolidPaint(getBorderColor(edge)); } @Override public LineCap getLineCap() { return null; } @Override public LineDash getLineDash() { return getBorderDash(edge); } @Override public LineCompound getLineCompound() { return getBorderCompound(edge); } @Override public double getLineWidth() { return width; } }; }
@Override public PaintStyle getPaint() { return DrawPaint.createSolidPaint(getBorderColor(edge)); }
spContainer.addChildRecord(etr); shape = new HSLFTableCell(spContainer, (HSLFTable)parent); } else { shape = new HSLFAutoShape(spContainer, parent);
@Override public double getColumnWidth(int col) { if (col < 0 || col >= cells[0].length) { throw new IllegalArgumentException("Column index '"+col+"' is not within range [0-"+(cells[0].length-1)+"]"); } // TODO: check for merged cols return cells[0][col].getAnchor().getWidth(); }
private void extractTableText(XHTMLContentHandler xhtml, HSLFTable shape) throws SAXException { xhtml.startElement("table"); for (int row = 0; row < shape.getNumberOfRows(); row++) { xhtml.startElement("tr"); for (int col = 0; col < shape.getNumberOfColumns(); col++) { HSLFTableCell cell = shape.getCell(row, col); //insert empty string for empty cell if cell is null String txt = ""; if (cell != null) { txt = cell.getText(); } xhtml.element("td", txt); } xhtml.endElement("tr"); } xhtml.endElement("table"); }
@Override public void setBorderDash(BorderEdge edge, LineDash dash) { if (edge == null || dash == null) { throw new IllegalArgumentException("BorderEdge and/or LineDash need to be specified."); } HSLFLine l = addLine(edge); l.setLineDash(dash); }
return; Rectangle2D cellAnchor = getAnchor(); double x,y,w,h; switch(edge){
private void extractTableText(XHTMLContentHandler xhtml, HSLFTable shape) throws SAXException { xhtml.startElement("table"); for (int row = 0; row < shape.getNumberOfRows(); row++) { xhtml.startElement("tr"); for (int col = 0; col < shape.getNumberOfColumns(); col++) { HSLFTableCell cell = shape.getCell(row, col); //insert empty string for empty cell if cell is null String txt = ""; if (cell != null) { txt = cell.getText(); } xhtml.element("td", txt); } xhtml.endElement("tr"); } xhtml.endElement("table"); }