我XWPFTable
使用Apache POI 创建了一个单词.现在,表格正确地显示在列中的文本.现在我想格式化表格中的文字以及大小,字体等.我该怎么做?我所看到的是每个技巧都与运行选项相关联.但我想要的是TableRow
.看看到目前为止我做了什么:
XWPFTable tableTwo = document.createTable(); XWPFTableRow tableTwoRowOne = tableTwo.getRow(0); tableTwo.getCTTbl().getTblPr().unsetTblBorders(); tableTwoRowOne.getCell(0).setText("No Match – Location: "); tableTwoRowOne.addNewTableCell().setText("Prospect has expressed unwillingness to relocate or is based out of area where commute is not feasible"); XWPFTableRow tableTwoRowTwo = tableTwo.createRow(); tableTwoRowTwo.getCell(0).setText("No Match – Scalability: "); tableTwoRowTwo.getCell(1).setText("Prospect’s recent organizational size, structure, and complexity is not scalable to client’s environment");
我想格式化表的文本tableTwo
和tableTwoRowTwo
.我怎样才能做到这一点?
在单元格中添加段落.
XWPFTableRow rowOne = table.getRow(0); XWPFParagraph paragraph = rowOne.getCell(0).addParagraph(); setRun(paragraph.createRun() , "Calibre LIght" , 10, "2b5079" , "Some string" , false, false); private static void setRun (XWPFRun run , String fontFamily , int fontSize , String colorRGB , String text , boolean bold , boolean addBreak) { run.setFontFamily(fontFamily); run.setFontSize(fontSize); run.setColor(colorRGB); run.setText(text); run.setBold(bold); if (addBreak) run.addBreak(); }
通常这会在单元格中添加一个段落,但单元格已经有一个.因此,首先删除单元格中的段落,然后添加新段落,否则结果将在新段落之前为空行.
rowOne.getCell(0).removeParagraph(0);