我正在使用docx4j创建一个word文档,我需要设置'Title'的样式,但是,我找不到合适的函数来执行此操作。
private static P createIt() {
org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
P p = wmlObjectFactory.createP();
// Create object for pPr
PPr ppr = wmlObjectFactory.createPPr();
p.setPPr(ppr);
// Create object for pStyle
PPrBase.PStyle pprbasepstyle = wmlObjectFactory.createPPrBasePStyle();
ppr.setPStyle(pprbasepstyle);
pprbasepstyle.setVal( "Title");
// Create object for r
R r = wmlObjectFactory.createR();
p.getContent().add(r);
// Create object for t (wrapped in JAXBElement)
Text text = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
r.getContent().add(textWrapped);
text.setValue( "\u041E\u041E\u041E \u00AB\u0418\u043D\u0442\u0435\u0440\u041F\u043E\u043B\u00BB");
// Create object for br
Br br = wmlObjectFactory.createBr();
r.getContent().add(br);
// Create object for t (wrapped in JAXBElement)
Text text2 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped2 = wmlObjectFactory.createRT(text2);
r.getContent().add(textWrapped2);
text2.setValue( "630001, \u041D\u043E\u0432\u043E\u0441\u0438\u0431\u0438\u0440\u0441\u043A\u0430\u044F \u043E\u0431\u043B\u0430\u0441\u0442\u044C, \u0433. \u041D\u043E\u0432\u043E\u0441\u0438\u0431\u0438\u0440\u0441\u043A, \u0443\u043B. \u0421\u0443\u0445\u0430\u0440\u043D\u0430\u044F, \u0434.35, \u043A\u043E\u0440\u043F.4, \u043E\u0444\u0438\u0441 406");
r.getContent().add(br);
// Create object for t (wrapped in JAXBElement)
Text text3 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped3 = wmlObjectFactory.createRT(text3);
r.getContent().add(textWrapped3);
text3.setValue( "\u0422\u0435\u043B. (383) 375-70-35, 8-909-529-57-57");
r.getContent().add(br);
// Create object for t (wrapped in JAXBElement)
Text text4 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped4 = wmlObjectFactory.createRT(text4);
r.getContent().add(textWrapped4);
text4.setValue( "e-mail: info@interpol-nsk.ru, \u0441\u0430\u0439\u0442: www.interpol-nsk.ru");
r.getContent().add(br);
// Create object for t (wrapped in JAXBElement)
Text text5 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped5 = wmlObjectFactory.createRT(text5);
r.getContent().add(textWrapped5);
text5.setValue( "\u0418\u041D\u041D 5402549079 \u041A\u041F\u041F 540201001, \u041E\u0413\u0420\u041D 1125476048983");
r.getContent().add(br);
// Create object for t (wrapped in JAXBElement)
Text text6 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped6 = wmlObjectFactory.createRT(text6);
r.getContent().add(textWrapped6);
text6.setValue( "\u0440/\u0441 40702810401300023124 \u0432 \u00AB\u0411\u0430\u043D\u043A24.\u0440\u0443\u00BB (\u041E\u0410\u041E) \u0433.\u0415\u043A\u0430\u0442\u0435\u0440\u0438\u043D\u0431\u0443\u0440\u0433");
r.getContent().add(br);
// Create object for t (wrapped in JAXBElement)
Text text7 = wmlObjectFactory.createText();
JAXBElement<org.docx4j.wml.Text> textWrapped7 = wmlObjectFactory.createRT(text7);
r.getContent().add(textWrapped7);
text7.setValue( "\u0411\u0418\u041A 046577859, \u043A/\u0441 30101810600000000859 \u0432 \u0413\u0420\u041A\u0426 \u0413\u0423 \u0411\u0430\u043D\u043A\u0430 \u0420\u043E\u0441\u0441\u0438\u0438 \u043F\u043E \u0421\u0432\u0435\u0440\u0434\u043B\u043E\u0432\u0441\u043A\u043E\u0439 \u043E\u0431\u043B\u0430\u0441\u0442\u0438\r\u041E\u041E\u041E \u00AB\u0418\u043D\u0442\u0435\u0440\u041F\u043E\u043B\u00BB\r630001, \u041D\u043E\u0432\u043E\u0441\u0438\u0431\u0438\u0440\u0441\u043A\u0430\u044F \u043E\u0431\u043B\u0430\u0441\u0442\u044C, \u0433. \u041D\u043E\u0432\u043E\u0441\u0438\u0431\u0438\u0440\u0441\u043A, \u0443\u043B. \u0421\u0443\u0445\u0430\u0440\u043D\u0430\u044F, \u0434.35, \u043A\u043E\u0440\u043F.4, \u043E\u0444\u0438\u0441 406\r\u0422\u0435\u043B. (383) 375-70-35, 8-909-529-57-57\re-mail: info@interpol-nsk.ru, \u0441\u0430\u0439\u0442: www.interpol-nsk.ru\r\u0418\u041D\u041D 5402549079 \u041A\u041F\u041F 540201001, \u041E\u0413\u0420\u041D 1125476048983\r\u0440/\u0441 40702810401300023124 \u0432 \u00AB\u0411\u0430\u043D\u043A24.\u0440\u0443\u00BB (\u041E\u0410\u041E) \u0433.\u0415\u043A\u0430\u0442\u0435\u0440\u0438\u043D\u0431\u0443\u0440\u0433\r\u0411\u0418\u041A 046577859, \u043A/\u0441 30101810600000000859 \u0432 \u0413\u0420\u041A\u0426 \u0413\u0423 \u0411\u0430\u043D\u043A\u0430 \u0420\u043E\u0441\u0441\u0438\u0438 \u043F\u043E \u0421\u0432\u0435\u0440\u0434\u043B\u043E\u0432\u0441\u043A\u043E\u0439 \u043E\u0431\u043B\u0430\u0441\u0442\u0438\r");
return p;
}
我需要将字体更改为新罗马字体和尺寸10。
感谢任何帮助。
答案 0 :(得分:1)
这可能有助于在word文档中设置硬代码文本..
wordMLPackage.getMainDocumentPart()。addStyledParagraphOfText(“Title”,“此标题现在是Arial”); wordMLPackage.getMainDocumentPart()addStyledParagraphOfText( “字幕”, “Arial字体”)。 wordMLPackage.getMainDocumentPart()。addStyledParagraphOfText(“Heading1”,“As as Heading1”); wordMLPackage.getMainDocumentPart()。addStyledParagraphOfText(“Heading2”,“Heading2现在是Arialand fontsize 12”);
这可能有助于在word文档中设置硬代码文本..
但我需要设置字体大小和系列整个文档有什么办法吗?