You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用XWPF为新Word文件添加标准荷兰语标题样式?

问题:使用XWPF为Word文档添加荷兰语标题样式“Kop 1”失败

需要为新建Word文件添加标准荷兰语标题样式,首个标题需应用荷兰语样式“Kop 1”(对应英文Heading1),但尝试以下两种基于XWPF的解决方案后均无效,生成的文档始终显示默认样式:

尝试方案1:使用带样式的空白Word文件作为模板

尝试过两种设置方式:

方式1:

XWPFDocument document = new XWPFDocument(new FileInputStream("template.docx"));
XWPFParagraph paragraph = document.createParagraph();
paragraph.setStyle("Heading1");

方式2:

XWPFDocument document = new XWPFDocument(new FileInputStream("template.docx"));
XWPFParagraph paragraph = document.createParagraph();
paragraph.setStyle("Kop 1");

尝试方案2:使用.dotx模板文件

XWPFDocument template = new XWPFDocument(new FileInputStream(new File("Template.dotx")));       
XWPFDocument doc = new XWPFDocument();
XWPFStyles newStyles = doc.createStyles();
newStyles.setStyles(template.getStyles());

XWPFParagraph para = doc.createParagraph();
para.setStyle("Heading1");
// 或尝试:para.setStyle("Kop 1");

XWPFRun run = para.createRun();
run.setText("Header 1");
// 或尝试:run.setText("Kop 1");

内容的提问来源于stack exchange,提问作者tm1701

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 23:45:02