我使用docx4j創建word文檔,但我需要樣式'標題',但是,我找不到正確的功能來執行此操作。docx4j ObjectFactory將字體樣式設置爲標題
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: [email protected], \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: [email protected], \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;
}
我需要的字體更改爲Times New Roman字體和大小10
任何幫助表示讚賞。
您正在將樣式設置爲「標題」。在文檔的樣式部分中是否定義了另一個問題。 當你說「改變字體時代新的羅馬和大小10」,你的意思是改變標題樣式定義?因爲如果您只是指運行,您可以使用docx4j webapp生成該代碼。 – JasonPlutext
我改變了我的策略,並用docx4j編輯了模板。更容易。 –