gpt4 book ai didi

java - docx4j ObjectFactory 将字体样式设置为标题

转载 作者:行者123 更新时间:2023-12-01 13:23:41 29 4
gpt4 key购买 nike

我正在使用 docx4j 创建一个 Word 文档,并且需要设置“标题”的样式,但是,我找不到执行此操作的正确函数。

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;
}

我需要将字体更改为 times new roman 和大小 10。

感谢任何帮助。

最佳答案

这可能有助于在Word文档中设置硬代码文本..

wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Title","此标题现在为 Arial 格式");wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("字幕","Arial");wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Heading1","与 Heading1 相同");wordMLPackage.getMainDocumentPart().addStyledParagraphOfText("Heading2","Heading2 现在是 Arialand 字体大小 12");

这可能有助于在Word文档中设置硬代码文本..

但是我需要设置整个文档的字体大小和家庭有什么办法吗?

关于java - docx4j ObjectFactory 将字体样式设置为标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21899373/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com