使用Docx4J将内容控件与XML合并时如何创建新行?

时间:2016-01-26 12:49:08

标签: java xml docx4j

有没有办法在生成的docx文件中创建一个新行,我们在使用Docx4J将xx合并到docx模板时得到,如example所示。

考虑到我想在docx文件中使用多行,但是我通过XML文件将这些行传递给我将与docx文件合并的XML文件,如何为一组特定的单词创建一个新行在XML元素中,当它与docx模板合并时?

供参考 - >示例XML数据。

<?xml version="1.0" encoding="UtF-8" standalone="yes"  ?>
<ChargesInvoice>
    <invoicedate>05/01/2016</invoicedate>
    <vatnumber>GB 123456789</vatnumber>
    <dealercode>123456789</dealercode>
    <intenralcontact>956532456987321</intenralcontact>
    <invoicenumber>qwertyuiop</invoicenumber>

    <invoicedetails>
        <invoice>
            <Description>Lorem Ipsum is simply dummy text of the
            Lorem Ipsum is simply dummy text of the Lorem Ipsum is simply dummy text of the
            Lorem Ipsum is simply dummy text of the Ipsum is simply dummy text of the
            Lorem Ipsum is simply dummy text of the Lorem Ipsum is simply dummy text of the
            Lorem Ipsum is simply dummy text of the Lorem Ipsum is simply dummy text of the
            Lorem Ipsum is simply dummy text of the Lorem Ipsum is simply dummy text of the
            Lorem Ipsum is simply dummy text of the Lorem Ipsum is simply dummy text of the
            </Description>
            <NettAmount>300</NettAmount>
            <VATRate>30%</VATRate>
            <VATAmount>30</VATAmount>
            <GrossAmount>310</GrossAmount>
        </invoice>
        <invoice>
            <Description>apak</Description>
            <NettAmount>220</NettAmount>
            <VATRate>12%</VATRate>
            <VATAmount>24.4</VATAmount>
            <GrossAmount>234.4</GrossAmount>
        </invoice>
    </invoicedetails>
</ChargesInvoice>

正如我们在上面看到的那样,invoice元素中存在更多数据,我想在新行中显示它的一部分。我该怎么做?

1 个答案:

答案 0 :(得分:0)

BindingTraverserXSLT应该插入br元素来代替以下标记:

    // tokenize on the newline character, the carriage-return character, 
    // and the form-feed character
    StringTokenizer st = new StringTokenizer(r, "\n\r\f"); 

或者,它可以转换转义的Flat OPC XML或XHTML,但需要进行一些设置。