使用docx4j java在docx文件的同一行中添加页脚文本和页码

时间:2018-03-16 15:24:29

标签: java docx4j

我正在尝试在同一行的.docx文档的页脚上添加小文本(左侧)和页码(右侧)

到目前为止,我可以添加文本和页码,但需要2行

<head>
    .......................................
    .......................................
    .......................................
    <!-- Load the Content Experiment JavaScript API client for the experiment -->
    <script src="//www.google-analytics.com/cx/api.js?experiment=MY_EXPERIMENT_ID"></script>
    <script>
        // Ask Google Analytics which variation to show the user.
        var chosenVariation = cxApi.chooseVariation();
        // Define JavaScript for each page variation of this experiment.
        // Wait for the DOM to load, then execute the view for the chosen variation.
        $(document).ready(function(){
        switch (chosenVariation) {
            case 0:
                // Original: Do nothing. This will render the default HTML.
                break;
            case 1:
                //document.getElementsByClassName('logo_tagline')[0].value = 'I love programming';
                $(".logo_tagline:first").text("I love programming");
                break;
            case 2:
                //document.getElementsByClassName('logo_tagline')[0].value = 'Programming is my passion';
                $(".logo_tagline:first").text("Programming is my passion");
                break;
            case 3:
                //document.getElementsByClassName('logo_tagline')[0].value = 'I enjoy writing code';
                $(".logo_tagline:first").text("I enjoy writing code");
            }
        });
    </script>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-XXXXXXXXX-X');
    </script>
</head>

但我需要它

TextVersionv02312     
                                                                                   1

我用来添加文字和页码的代码是:

TextVersionv02312                                                                        1

我一直在考虑在页脚上添加一个表格或类似的东西,将元素放在同一行中,但似乎我过于复杂了。

或者我可以将页码附加到文本段落

你觉得怎么样?

提前谢谢!

1 个答案:

答案 0 :(得分:0)

您可以在Word中以任何方式执行此操作,例如,使用制表位。 (或者正如你所说,表格,但是如果你想要中心那么我会用一个中心对齐然后是右对齐标签)

最简单的方法是在Word中使用它,然后使用docx4j webapp或Docx4j Helper Word AddIn,从该示例文档生成相应的Java代码。