【发布时间】:2016-03-31 01:20:28
【问题描述】:
通过像 http://poi.apache.org 这样的一些库,我们可以创建具有任何文本颜色的 word 文档,但是对于文本的 background 或突出显示,我没有找到任何解决方案。
以手动方式为单词的页面颜色!:
这是我通过 poi.apache 创建 word 文档的主要代码
// Blank Document
@SuppressWarnings("resource")
XWPFDocument document = new XWPFDocument();
// Write the Document in file system
FileOutputStream out = new FileOutputStream(new File(file_address));
// create Paragraph
XWPFParagraph paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.RIGHT);
XWPFRun run = paragraph.createRun();
run.setFontFamily(font_name);
run.setFontSize(font_size);
// This only set text color not background!
run.setColor(hex_color);
for (String s : text_array) {
run.setText(s);
run.addCarriageReturn();
}
document.write(out);
out.close();
【问题讨论】:
-
请找stcakoverflow回答stackoverflow.com/questions/35419619/…
-
@LearNer 谢谢!通常初学者在这个网站上反应更快!
标签: java ms-word apache-poi background-color