【发布时间】:2018-03-16 15:24:28
【问题描述】:
我正在尝试在 .docx 文档的页脚上添加小文本(左侧)和页码(右侧)在同一行中
到目前为止,我可以添加文本和页码,但在 2 行中
TextVersionv02312
1
但我需要它
TextVersionv02312 1
我用来添加文本和页码的代码是:
private static Ftr createFooter(WordprocessingMLPackage wordMLPackage, String content, ObjectFactory factory, Part sourcePart, InputStream is) throws IOException, Throwable {
Ftr footer = factory.createFtr();
P paragraph = factory.createP();
R run = factory.createR();
/*
* Change the font size to 8 points(the font size is defined to be in half-point
* size so set the value as 16).
*/
RPr rpr = new RPr();
HpsMeasure size = new HpsMeasure();
size.setVal(BigInteger.valueOf(16));
rpr.setSz(size);
run.setRPr(rpr);
Text text = new Text();
text.setValue(content);
run.getContent().add(text);
paragraph.getContent().add(run);
footer.getContent().add(paragraph);
// add page number
P pageNumParagraph = factory.createP();
addFieldBegin(factory, pageNumParagraph);
addPageNumberField(factory, pageNumParagraph);
addFieldEnd(factory, pageNumParagraph);
footer.getContent().add(pageNumParagraph);
return footer;
}
private static void addPageNumberField(ObjectFactory factory, P paragraph) {
R run = factory.createR();
PPr ppr = new PPr();
Jc jc = new Jc();
jc.setVal(JcEnumeration.RIGHT);
ppr.setJc(jc);
paragraph.setPPr(ppr);
Text txt = new Text();
txt.setSpace("preserve");
txt.setValue(" PAGE \\* MERGEFORMAT ");
run.getContent().add(factory.createRInstrText(txt));
paragraph.getContent().add(run);
}
我一直在考虑在页脚添加一个表格或类似的东西来将元素放在同一行,但似乎我过于复杂了。
或者我可以将页码附加到文本段落
你怎么看?
提前致谢!
【问题讨论】: