【问题标题】:How to center text in docx4j如何在 docx4j 中将文本居中
【发布时间】:2014-08-08 03:07:30
【问题描述】:

我有一段文本希望出现在文档的中心。我怎样才能在 docx4j 中做到这一点?我目前正在使用:

    PPr paragraphProperties = factory.createPPr();

    //creating the alignment
    TextAlignment align = new TextAlignment();
    align.setVal("center");
    paragraphProperties.setTextAlignment(align);

    //centering the paragraph
    paragraph.setPPr(paragraphProperties);

但它不起作用。

【问题讨论】:

    标签: openxml docx4j


    【解决方案1】:

    你快到了。与其使用TextAlignment 对象来设置它,不如使用Jc 实例(理由):

    PPr paragraphProperties = factory.createPPr();
    Jc justification = factory.createJc();
    justification.setVal(JcEnumeration.CENTER);
    paragraphProperties.setJc(justification);
    

    解决这些问题的简单方法:

    • 在 Microsoft Word 中创建您要查找的文档(和格式)并保存文件
    • 将 .docx 文件后缀更改为“zip”
    • 打开压缩包,打开'word'目录,解压其中的document.xml文件
    • 检查 XML,这将为您提供有关使用哪些 OpenXML 对象的线索

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-02
      • 2014-07-21
      • 2011-06-12
      • 2012-07-23
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多