报错详情:
org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1258)
at org.openxmlformats.schemas.drawingml.x2006.main.impl.CTTextLineBreakImpl.isSetRPr(Unknown Source)
at org.apache.poi.xslf.usermodel.XSLFTextRun.getRPr(XSLFTextRun.java:486)
at org.apache.poi.xslf.usermodel.XSLFTextParagraph.clearButKeepProperties(XSLFTextParagraph.java:1140)
at org.apache.poi.xslf.usermodel.XSLFTextShape.setText(XSLFTextShape.java:121)
解析pptx文件,要用一个文本,替换另一个文本时报错。
打断点发现原文本是:“Team China starts strongly\n”
上网查的原因是因为替换的标签内有\n导致
但是我有没有办法避免原文有换行符,所以在调用setText(“替换的文字”)之前,调用一次clearText()方法,将原文清空,换上我想要的内容
((XSLFTextShape) shape).clearText();
((XSLFTextShape) shape).setText(tgt_text);
这样就不会报错了。