Java 如何设置;“拉萨”;使用poi jar写入docx文件时默认使用字体
我需要使用ApachePOI创建一个docx文件,并且需要将其字体设置为Latha。下面是我的代码,但当我使用setfontfamily(“Latha”)时,它不起作用。拉萨是泰米尔字体Java 如何设置;“拉萨”;使用poi jar写入docx文件时默认使用字体,java,apache-poi,Java,Apache Poi,我需要使用ApachePOI创建一个docx文件,并且需要将其字体设置为Latha。下面是我的代码,但当我使用setfontfamily(“Latha”)时,它不起作用。拉萨是泰米尔字体 XWPFDocument document = new XWPFDocument(); FileOutputStream out = null; try { out = new FileOutputStream(new File("PageCounter.docx"));
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);
}
Systen正在写入文件,但unicode文本显示为方框。这是3.7中的一个错误:
但在3.8版本中工作(目前处于测试阶段):
我使用相同版本的poi jar 3.10进行poi,也使用docj4 jar,我获得了所需的输出。poi 3.8是在3年前发布的!最新的ApachePOI版本是3.12,于2015年5月发布。为了设置泰米尔字体,我们必须使用这两种方法。xssfont.setFontName(“Latha”);assertEquals(“Latha”,ctFont.getNameArray(0.getVal());run.setFontFamily(“Latha”); run.setText(replaceAll2);如果您没有找到所需的答案,请使用getCTR()方法。然后在ApacheOffice中,它的工作将在Ms word中出现一些错误