我需要使用 apache poi 创建一个 docx 文件,并且需要将其字体设置为 Latha。下面是我的代码,但当我使用 setfontfamily("Latha") 时它不起作用。 Latha 是一种泰米尔字体。
XWPFDocument document = new XWPFDocument();
FileOutputStream out = null;
try {
out = new FileOutputStream(new File("PageCounter.docx"));
} catch (FileNotFoundException ex) {
Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
}
try {
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText(replaceAll2);
run.setFontFamily("Latha");
run.setFontSize(10);
document.write(out);
} catch (IOException ex) {
Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
}
try {
out.close();
} catch (IOException ex) {
Logger.getLogger(WordDocCreation.class.getName()).log(Level.SEVERE, null, ex);
}
系统正在写入文件,但 unicode 文本显示为框。
最佳答案
这是3.7中的一个错误: http://apache-poi.1045710.n5.nabble.com/NPE-setting-font-family-for-a-XWPFRun-td5050524.html
但是可以在 3.8 中使用(目前处于测试版): https://issues.apache.org/bugzilla/show_bug.cgi?id=52288
关于java - 如何使用 poi jar 编写 docx 文件时默认设置 "Latha"字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30229214/