java Docx4j:PPTX在插入椭圆对象时损坏
我一整天都在寻找解决办法,但找不到。这就是为什么我决定问一个问题
我的问题是我在PPTX文件中插入了一个椭圆对象。当我试图打开演示文稿时,微软OFfice表示它已损坏并试图修复。它最终会删除幻灯片并显示主幻灯片
请参见下面我的代码:
函数officeXReport.getTemplatename()
包含PPTX的文件名(例如*Status_Report_template.PPTX*)
模板pptx文件仅包含一张幻灯片
函数officeXReport.getNewfilename()
包含PPTX的新文件名(例如*Status_Report_2014-03-16.PPTX*)
try {
PresentationMLPackage presentationMLPackage = (PresentationMLPackage)OpcPackage.load(new java.io.File(officeXReport.getTemplatename()));
MainPresentationPart pp = presentationMLPackage.getMainPresentationPart();
boolean noLine = false;
STShapeType st = STShapeType.ELLIPSE;
int i = 1;
SlidePart slidePart = (SlidePart)presentationMLPackage.getParts().getParts().get(pp.getSlide(0).getPartName());
Shape sample = ((Shape)XmlUtils.unmarshalString(
getPresetShape(st.value(), noLine, Long.toString(1839580), Long.toString(1314971), Long.toString(184337), Long.toString(184338), "92D050"), Context.jcPML) );
slidePart.getJaxbElement().getCSld().getSpTree().getSpOrGrpSpOrGraphicFrame().add(sample);
presentationMLPackage.save(new java.io.File(officeXReport.getNewfilename()));
} catch (Exception ex) {
System.out.println("Exception thrown = " + ex.getMessage());
return null;
}
相关函数getPresetShape()
:
private static String getPresetShape(String preset, boolean noLine, String x, String y, String cx, String cy, String colorcode) {
String txBody = "";
String ln = "";
String style = "";
if (!noLine) {
ln = "<a:ln w=\"3175\">"
+"<a:solidFill>"
+"<a:srgbClr val=\"000000\"/>"
+"</a:solidFill>"
+"</a:ln>";
style = "<p:style>\n" +
"<a:lnRef idx=\"1\">\n" +
"<a:schemeClr val=\"accent1\"/>\n" +
"</a:lnRef>\n" +
"<a:fillRef idx=\"3\">\n" +
"<a:schemeClr val=\"accent1\"/>\n" +
"</a:fillRef>\n" +
"<a:effectRef idx=\"2\">\n" +
"<a:schemeClr val=\"accent1\"/>\n" +
"</a:effectRef>\n" +
"<a:fontRef idx=\"minor\">\n" +
"<a:schemeClr val=\"lt1\"/>\n" +
"</a:fontRef>\n" +
"</p:style>";
txBody = "<p:txBody>\n" +
"<a:bodyPr rtlCol=\"false\" anchor=\"ctr\"/>\n" +
"<a:lstStyle/>\n" +
"<a:p>\n" +
"<a:pPr algn=\"ctr\"/>\n" +
"<a:endParaRPr lang=\"en-US\" sz=\"1100\" u=\"sng\" dirty=\"false\">\n" +
"<a:latin typeface=\"Futura Com Light\" panose=\"020B0402020204020303\" pitchFamily=\"34\" charset=\"0\"/>\n" +
"</a:endParaRPr>\n" +
"</a:p>\n" +
"</p:txBody>";
}
return
"<p:sp xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:p=\"http://schemas.openxmlformats.org/presentationml/2006/main\">"
+ "<p:nvSpPr>"
+ "<p:cNvPr id=\"32\" name=\"Ellipse 2\" />"
+ "<p:cNvSpPr/>"
+ "<p:nvPr/>"
+ "</p:nvSpPr>"
+ "<p:spPr>"
+ "<a:xfrm>"
+ "<a:off x=\"" + x + "\" y=\"" + y + "\"/>"
+ "<a:ext cx=\"" + cx + "\" cy=\""+ cy + "\"/>"
+ "</a:xfrm>"
+ "<a:prstGeom prst=\"" + preset + "\">"
+ "<a:avLst/>"
+ "</a:prstGeom>"
+ "<a:solidFill>"
+ "<a:srgbClr val=\""+ colorcode + "\"/>"
+ "</a:solidFill>"
+ ln
+ "</p:spPr>"
+ style
+ txBody
+ "</p:sp>";
}
我已经看过幻灯片了。与正确的幻灯片1相比,缺少xml标头的xml文件。xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
如何将xml标题定义放入幻灯片1中。xml
谢谢
阿萨德
共 (0) 个答案