Wil*_*ill 6 java locale encode file apache-poi
我正在评估apache poi作为编写docx文件的选项.我正在寻找的具体事情是在docx文件中生成不同语言的内容(hindi/marathi具体).我面临以下问题:
当docx文件被写入时,"Hindi/Marathi"文本显示为方框,即使字体"Arial Unicode MS"支持它.关键是,当我们选中复选框时,MS Word会将字体显示为"Cailbri",即使我已将字体显式设置为"Arial Unicode MS".如果我选择MS Word中的框,然后将字体更改为"Arial Unicode MS",则可以正确显示印地文/马拉地语单词.知道为什么会这样吗?请注意我使用POI的开发版本,因为之前的稳定版本不支持设置字体系列.这是来源:
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
public class CreateDocumentFromScratch
{
public static void main(String[] args)
{
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraphTwo = document.createParagraph();
XWPFRun paragraphTwoRunOne = paragraphTwo.createRun();
paragraphTwoRunOne.setFontFamily("Arial Unicode MS");
paragraphTwoRunOne.setText("???????");
XWPFParagraph paragraphThree = document.createParagraph();
XWPFRun paragraphThreeRunOne = paragraphThree.createRun();
paragraphThreeRunOne.setFontFamily("Arial Unicode MS");
paragraphThreeRunOne.setText("This is nice");
FileOutputStream outStream = null;
try {
outStream = new FileOutputStream("c:/will/First.doc");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
document.write(outStream);
outStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
恢复一个非常旧的帖子;OP可以确认正在使用的MS Office版本吗?问题似乎出在 Windows XP 上运行的 MS Office 2003 上。但它也可能在更高的操作系统版本上。
看来 MS Word 应用了印地语脚本的 Mangal 字体 [编码标准:印度语:印地语 ISCII 57002 (Devanagari)]。以下链接解释了这一点:
建议的解决方法:从 Windows XP 控制面板中,选择区域和语言选项。选择语言。选中“安装复杂脚本和从右到左语言(包括泰语)的文件”框。
重新启动电脑。
但是,在 Windows 上使用 LibreOffice 版本 4.3.5.2 和 Linux (Ubuntu) 上使用 LibreOffice 4.2.7.2 打开文件时,没有观察到此类问题。
使用以下库:poi-3.10-FINAL-20140208.jar、poi-ooxml-3.10-FINAL-20140208.jar、
poi-ooxml-schemas-3.10-FINAL-20140208.jar、xmlbeans-2.3.0.jar、dom4j -1.6.1.jar,stax-api-1.0.1.jar