简体   繁体   English

如何在不使用段落和运行的情况下更改特定表单元上的Apache POI Word文档中的字体颜色?

[英]How to change font color in Apache POI word document on a specific table cell without using paragraph and run?

I have created a method for formatting a table cell according to some criteria and the problem is that when using paragraph and run it creates a new line inside the cell and this is something I do not want. 我已经创建了一种根据某些条件格式化表格单元格的方法,问题是使用段落并运行它会在单元格内创建新行,而这是我所不希望的。

private void setTab1CellValue(XWPFTable table, int r, int c, String label, BigInteger condition, String value) {
    table.getRow(r).getCell(c).setText(label);
    if (value != null) {
        if (condition != null && condition.equals(BigInteger.ONE)) {
            XWPFParagraph paragraph = table.getRow(r).getCell(c + 1).addParagraph();
            XWPFRun run = paragraph.createRun();
            run.setColor("FF0000");
            run.setText(value);
        } else {
            table.getRow(r).getCell(c + 1).setText(value);
        }
    }
}

Is there an other way so that I could modify the above code to change the font color of the cell without using paragraph and run (or without getting the newline inside the cell)? 还有其他方法可以使我修改上面的代码以更改单元格的字体颜色,而无需使用段落和运行(或在单元格内没有换行符)?

Please help. 请帮忙。 Thanks in advance. 提前致谢。

我刚刚删除了索引为0的段落, 并按表单元格中此答案XWPF新段落的指示固定了输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM