gpt4 book ai didi

java - 尝试使用 Apache poi 在单词中设置阿拉伯语句子?

转载 作者:行者123 更新时间:2023-11-29 05:12:39 35 4
gpt4 key购买 nike

我正在尝试使用 apache poi api 生成一个 word 文档,我想在这个词中设置一个阿拉伯语句子,但是这些词没有保留在订单上!!!因为我得到了 بالملك شهادو ,而不是“شهادة بالملك”

public class word {

public static void main (String [] args) {
XWPFDocument docx = new XWPFDocument();

try {

XWPFParagraph tmpParagraph = docx.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("شهادة بالملك");
tmpRun.setFontSize(18);
tmpRun.setFontFamily("Calibri (Corps)");
tmpRun.setBold(true);
tmpRun.setColor("003894");
tmpParagraph.setAlignment(ParagraphAlignment.LEFT);
tmpRun.setUnderline(UnderlinePatterns.SINGLE);
tmpParagraph.setSpacingAfter(300);

FileOutputStream fos = new FileOutputStream("Word2.docx");
docx.write(fos);
fos.close();
}
catch (Exception e ) {
e.printStackTrace();
}
}
}

最佳答案

这是答案:

public class word {

public enum TextOrientation {
LTR,
RTL
}

public static void main (String [] args) {

XWPFDocument docx = new XWPFDocument();

try {

XWPFParagraph tmpParagraph = docx.createParagraph();
XWPFRun tmpRun = tmpParagraph.createRun();
tmpRun.setText("شهادة بالملك");
tmpRun.setFontSize(18);
tmpRun.setFontFamily("Calibri (Corps)");
tmpRun.setBold(true);
tmpRun.setColor("003894");
tmpParagraph.setAlignment(ParagraphAlignment.CENTER);
tmpRun.setUnderline(UnderlinePatterns.SINGLE);
tmpParagraph.setSpacingAfter(300);
setOrientation(tmpParagraph, TextOrientation.RTL);

FileOutputStream fos = new FileOutputStream("Word2.docx");
docx.write(fos);
fos.close();
}
catch (Exception e ) {
e.printStackTrace();
}
}

private static void setOrientation(XWPFParagraph par, TextOrientation orientation) {
if ( par.getCTP().getPPr()==null ) {
par.getCTP().addNewPPr();
}
if ( par.getCTP().getPPr().getBidi()==null ) {
par.getCTP().getPPr().addNewBidi();
}
par.getCTP().getPPr().getBidi().setVal(orientation==TextOrientation.RTL?STOnOff.ON:STOnOff.OFF);
}
}

关于java - 尝试使用 Apache poi 在单词中设置阿拉伯语句子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27831749/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com