Java docx4j向段落添加样式会破坏文档
我正在尝试添加一个包含标题(带有样式)和一些无格式文本的段落。以下代码将销毁该文档 编辑:执行以下代码并尝试在word中打开文档后,我收到一条错误消息“Unspecified error”位置:Part/word/document.xml第1行第0列Java docx4j向段落添加样式会破坏文档,java,docx4j,Java,Docx4j,我正在尝试添加一个包含标题(带有样式)和一些无格式文本的段落。以下代码将销毁该文档 编辑:执行以下代码并尝试在word中打开文档后,我收到一条错误消息“Unspecified error”位置:Part/word/document.xml第1行第0列 ObjectFactory factory = new ObjectFactory(); P complete = factory.createP(); org.docx4j.wml.P headl
ObjectFactory factory = new ObjectFactory();
P complete = factory.createP();
org.docx4j.wml.P headline=factory.createP();
R hrun = factory.createR();
Text htxt = new Text();
hrun.getContent().add(htxt);
htxt.setValue(View_Beta.this.falseAlarmChoice.getSelectedItem().toString());
headline.getContent().add(hrun);
org.docx4j.wml.PPr pPr = factory.createPPr();
headline.setPPr(pPr);
org.docx4j.wml.PPrBase.PStyle pStyle = factory.createPPrBasePStyle();
pPr.setPStyle(pStyle);
pStyle.setVal("Title");
complete.getContent().add(headline);
P ptext = factory.createP();
R rtext = factory.createR();
Text ttext = new Text();
rtext.getContent().add(ttext);
ptext.getContent().add(rtext);
ttext.setValue(falseAlarmChoice.getSelectedItem()
+ falseAlarmDsc.getText());
complete.getContent().add(ptext);
//add to document context
View_Beta.this.c.insertAtPos(complete,
paragraphlst.getSelectedIndex());
在代码中
complete.getContent().add(headline)
在段落内添加段落,根据Open XML规范,该段落无效。欢迎使用StackOverflow。详细说明“销毁文档”的含义。删除文件、中断格式设置、清除文档内容?请尽可能多地提供详细信息。请解压缩docx,然后将word/document.xml部分的内容复制到您的问题中