为有中文需求的客户提供多渠道中文技术支持.

Wed Aug 31, 2022 6:15 am

如何自定义设置 BuiltinStyle.Heading_1 的样式
Code: Select all
para.applyStyle(BuiltinStyle.Heading_1);

hannibal22
 
Posts: 52
Joined: Wed Aug 17, 2022 7:01 am

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
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Return to 中文技术支持

cron