Aspose.words.java

请问怎样利用aspose插件对word中的一级标题和二级标题设置样式(java代码)

@liyong199466

谢谢你的询问。 我们建议您阅读以下文章。
指定格式

下面的代码示例演示如何将paragaph的样式设置为标题1并修改标题1样式。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("First paragraph");

//Set the paragraphformat style as heading 1
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_1);
builder.write("Hello");

builder.getParagraphFormat().clearFormatting();

//Get the first paragraph of document and set its styles to heading1
Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
Style heading1 = doc.getStyles().getByStyleIdentifier(StyleIdentifier.HEADING_1);
paragraph.getParagraphFormat().setStyle(heading1);

//modify the heading style

heading1.getFont().setName("Arial");
heading1.getFont().setSize(14.5);

doc.save(MyDir + "output.docx");

如果您仍然遇到问题,请在此处输入您的输入和预期输出Word文档,以供我们参考。 然后,我们将为您提供有关查询的更多信息。