public TableRow(Object[] cols) { txt.append(tableRowTop); for (int i = 0; i < cols.length; i++) { //TableCell knows how to do the rest. txt.append( TableCell.with(cols[i]).create().getContent() ); } txt.append(tableRowBottom); }
tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableCell- Style to the whole cell, Par").create()), "Simple String" ).withStyle().bold().create() ); tbl.addRow( TableRow.with("Style to the whole cell, Str", "String").withStyle().bold().create() ); tbl.addRow( TableRow.with( TableCell.with(Paragraph.with("TableRowV2 with merge").create()).withStyle().gridSpan(2).create() ).withStyle().bold().create() ); tbl.addRow( TableRow.with( TableCell.with(Paragraph.withPieces( ParagraphPiece.with("Paragraph with Style inside TableCell").withStyle().bold().fontSize("20").create() ).create()).withStyle().bgColor("00FFFF").create(), "String" ));
/** * It can receive a String, TableCell or any other IElement. * for String, text will be wrapped on a Paragraph. * * Use TableCell when you need to apply style to the Cell. Eg.: Background color. * PS.: If you need to apply "bold", "italic" or "underline" to the cell, use a Paragraph with its Pieces. * * If you pass an IElement, the getContent() method will be blindly call. So be careful on what you pass. * Remember you can always wrap elements or build your own String XML that represents what you want - Be creative! * * You can also pass 2 different kinds objects at the same time. Eg.: * <code> * tbl.addRow( TableRowV2.with( TableCell.with(Paragraph.with("Paragraph01").create()), "Simple String" ).withStyle().bold().create() ); * </code> * **/ public static TableCell with(Object cell) { if(cell instanceof TableCell){ //it is already TableCell so no need to create another instance //it is a Paragraph at this moment. It needs Column Top and Bottom ((TableCell) cell).txt.insert(0, "\n <w:tc>\n {styleCellPh}"); ((TableCell) cell).txt.append("\n </w:tc>"); return (TableCell) cell; }else{ TableCell tableCell = new TableCell(cell); return tableCell; } }
/** * It can receive a String, TableCell or any other IElement. * for String, text will be wrapped on a Paragraph. * * Use TableCell when you need to apply style to the Cell. Eg.: Background color. * PS.: If you need to apply "bold", "italic" or "underline" to the cell, use a Paragraph with its Pieces. * * If you pass an IElement, the getContent() method will be blindly call. So be careful on what you pass. * Remember you can always wrap elements or build your own String XML that represents what you want - Be creative! * * You can also pass 2 different kinds objects at the same time. Eg.: * <code> * tbl.addRow( TableRowV2.with( TableCell.with(Paragraph.with("Paragraph01").create()), "Simple String" ).withStyle().bold().create() ); * </code> * **/ public static TableCell with(Object cell) { if(cell instanceof TableCell){ //it is already TableCell so no need to create another instance //it is a Paragraph at this moment. It needs Column Top and Bottom ((TableCell) cell).txt.insert(0, "\n <w:tc>\n {styleCellPh}"); ((TableCell) cell).txt.append("\n </w:tc>"); return (TableCell) cell; }else{ TableCell tableCell = new TableCell(cell); return tableCell; } }
public TableRow(Object[] cols) { txt.append(tableRowTop); for (int i = 0; i < cols.length; i++) { //TableCell knows how to do the rest. txt.append( TableCell.with(cols[i]).create().getContent() ); } txt.append(tableRowBottom); }