Wed Aug 31, 2022 6:36 am
您好,
感谢您的咨询。
请参考如下代码进行测试。如代码不是您所需要的,请您再附以更详细的说明来描述您的需求,谢谢。
- Code: Select all
Document doc = new Document();
//自定义新的段落样式
ParagraphStyle style=new ParagraphStyle(doc);
//设置样式名
style.setName("test1234");
//设置字体相关
style.getCharacterFormat().setBold(true);
style.getCharacterFormat().setFontName("黑体");
style.getCharacterFormat().setTextColor(Color.RED);
style.getCharacterFormat().setFontSize(18f);
//设置该样式对应的段落的大纲级别为Leve1 也就是跟默认样式Heading1的段落等级一样
style.getParagraphFormat().setOutlineLevel(OutlineLevel.Level_1);
//将自定义样式添加进文档中
doc.getStyles().add(style);
//新建段落和文本进行测试
Section section=doc.addSection();
Paragraph paragraph=section.addParagraph();
paragraph.appendText("Spire.Doc For Java");
//使用自定义样式
paragraph.applyStyle("test1234");
doc.saveToFile("output.docx", FileFormat.Docx);
Sincerely,
Andy
E-iceblue support team