问题遇到的现象和发生背景
private static void setCellText(XWPFTableCell cell, String text, String bgcolor, Integer width){
CTTc ctTc = cell.getCTTc();
CTTcPr ctTcPr = ctTc.addNewTcPr();
ctTcPr.addNewTcW().setW(BigInteger.valueOf(width));
cell.setColor(bgcolor);
CTTcPr ctPr = ctTc.addNewTcPr();
ctPr.addNewVAlign().setVal(STVerticalJc.CENTER);
ctTc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
}
运行后,未设置字体
private static void setCellText(XWPFTableCell cell, String text, String bgcolor, Integer width){
CTTc ctTc = cell.getCTTc();
CTTcPr ctTcPr = ctTc.addNewTcPr();
ctTcPr.addNewTcW().setW(BigInteger.valueOf(width));
cell.setColor(bgcolor);
CTTcPr ctPr = ctTc.addNewTcPr();
ctPr.addNewVAlign().setVal(STVerticalJc.CENTER);
ctTc.getPList().get(0).addNewPPr().addNewJc().setVal(STJc.CENTER);
XWPFParagraph paragraph = cell.addParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = paragraph.createRun();
run.setFontFamily("宋体");
run.setFontSize(14);
run.setText(text);
}
设置字体运行后,未水平居中