[英]How do i change docx4j text direction with java?
I am writting text to a docx document using docx4j i want to change default text direction to right-to-left , this is my code: 我正在使用docx4j将文本写入docx文档,我想将默认文本方向更改为从右到左,这是我的代码:
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
MainDocumentPart mainDocumentPart = wordPackage.getMainDocumentPart();
mainDocumentPart.addParagraphOfText("some plain text");
File exportFile = new File("test.docx");
wordPackage.save(exportFile);
It is suggested to use Apache POI . 建议使用Apache POI 。 Please check this page for a tutorial and use a template file for your goal as described here .
请查看此页面的教程,并按照此处所述使用模板文件实现您的目标。
In the WordML/OpenXML file format, r2l is a boolean property on a run: http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/rtl.html 在WordML / OpenXML文件格式中,r2l是运行时的布尔属性: http : //webapp.docx4java.org/OnlineDemo/ecma376/WordML/rtl.html
So: 所以:
// Create object for rtl
BooleanDefaultTrue booleandefaulttrue = wmlObjectFactory.createBooleanDefaultTrue();
rpr.setRtl(booleandefaulttrue);
You set rPr on a run (R object), for example: 您在运行(R对象)上设置rPr,例如:
RPr rpr = wmlObjectFactory.createRPr();
r.setRPr(rpr);
In the above: 在上面:
org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
You can generate code for docx4j by creating a sample document in Word which contains what you want, then using the docx4j webapp or docx4j Helper Word AddIn. 您可以通过在Word中创建一个包含所需内容的示例文档来生成docx4j的代码,然后使用docx4j webapp或docx4j Helper Word加载项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.