通过诸如之类的某些库,我们可以创建具有任何文本颜色的
Word文档 ,但是对于文本的 背景 或突出显示,我没有找到任何解决方案。
页面颜色以手动方式显示!:
这是我通过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();