【问题标题】:docx4j - Why is the text truncated of spaces?docx4j - 为什么文本会被空格截断?
【发布时间】:2015-02-08 15:21:26
【问题描述】:

代码如下:

    P para = factory.createP();
    R run = factory.createR();
    Text text = factory.createText();

    text.setValue( "              abc                " );
    run.getContent().add( text );
    para.getContent().add( run );
    wordMLPack.getMainDocumentPart().add( para );

这里是生成的docx:

标题和尾随空格都不见了。

【问题讨论】:

    标签: java docx4j


    【解决方案1】:

    您需要告诉 docx4j 在您的 Text 实例中显式保留空格(基础格式当然是 XML,它往往不太注意空格)。像这样的:

    text.setValue("              abc             ");
    text.setSpace("preserve");
    ...
    

    【讨论】:

    • 这应该已经记录在 docx4j wiki 中了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多