简体   繁体   中英

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新段落的指示固定了输出。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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