tableRowOne.addNewTableCell().setText("Mo"); tableRowOne.addNewTableCell().setText("Tu"); tableRowOne.addNewTableCell().setText("We"); tableRowOne.addNewTableCell().setText("Th"); tableRowOne.addNewTableCell().setText("Fr"); tableRowOne.addNewTableCell().setText("Sa");
public static void main(String[] args) throws IOException { XWPFDocument document = new XWPFDocument(); XWPFTable tableOne = document.createTable(); XWPFTableRow tableOneRowOne = tableOne.getRow(0); tableOneRowOne.getCell(0).setText("Header1"); tableOneRowOne.addNewTableCell().setText("header2"); XWPFTableRow tableOneRowTwo = tableOne.createRow(); tableOneRowTwo.getCell(0).setText("Data1"); tableOneRowTwo.getCell(1).setText("Data2"); FileOutputStream outStream = new FileOutputStream("test.doc"); document.write(outStream); outStream.close(); }
tableRow.addNewTableCell();
/** * 渲染一列单元格操作 * * @param cell 原始单元格(表达式所在的单元格) * @param params 单元格值 */ public void nextCell(XWPFTableCell cell, Object... params) { XWPFTableCell cell_tmp = nowRow.getCell(firstRow.getTableCells().indexOf(cell)); if (params == null) params = new String[]{""}; if (cell_tmp == null) { cell_tmp = nowRow.addNewTableCell(); cell_tmp.addParagraph(cell.getParagraphArray(0)); } for (int i = 0, len = cell.getParagraphs().size(); i < len; i++) { cell.removeParagraph(i); } cell_tmp.setText(StringUtils.concat(params)); }
/** * 渲染一列单元格操作 * * @param cell 原始单元格(表达式所在的单元格) * @param params 单元格值 */ public void nextCell(XWPFTableCell cell, Object... params) { XWPFTableCell cell_tmp = nowRow.getCell(firstRow.getTableCells().indexOf(cell)); if (params == null) params = new String[]{""}; if (cell_tmp == null) { cell_tmp = nowRow.addNewTableCell(); cell_tmp.addParagraph(cell.getParagraphArray(0)); } for (int i = 0, len = cell.getParagraphs().size(); i < len; i++) { cell.removeParagraph(i); } cell_tmp.setText(StringUtils.concat(params)); }
tableRowOne.addNewTableCell().setText("col two, row one"); tableRowOne.addNewTableCell().setText("col three, row one");
tableRowOne.addNewTableCell().setText("col two, row one"); tableRowOne.addNewTableCell().setText("col three, row one");
tableRowOne.addNewTableCell().setText("col two, row one"); tableRowOne.addNewTableCell().setText("col three, row one");