Why am I getting an illegal value error using PpShapeFormat in Office 2013 Interop
我编写了一个 MS JScript 实用程序(用于 SmartBear 的 TestComplete),它将嵌入在 Word 文档中的图像导出为磁盘上的 PNG 文件。当我在 Win7 和 Office 2010 上运行此实用程序时,一切正常。但是当我使用 Office 2013 在 Win8 上运行它时,将 PpShapeFormat 过滤器传递给 Export 方法时出现"非法值"错误。
这是我的脚本的相关部分:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | //get the list of shapes from the word doc, and how many there are var iShapeList = DocObj.InlineShapes; //DocObj is created elsewhere var iShapeTotal = iShapeList.count; //create a powerpoint object and instantiate a presentation var pptApp = Sys.OleObject("PowerPoint.Application"); //open PowerPoint var pptDoc = pptApp.Presentations.Add(); //create a new blank document var pptDocSlide = pptDoc.Slides.Add(1, 12); //12 = ppLayoutBlank var pptShapeFmt = pptApp.PpShapeFormat; //format filter object //loop through the Word document shapes, copy each one, paste it to the Ppt slide, //export the image out of the slide, and then delete it for(var iShapeNo = 1; iShapeNo <= iShapeTotal; iShapeNo++) { var iShape = iShapeList(iShapeNo); //get a shape iShape.ScaleHeight = hScale; //set the shape height and width iShape.ScaleWidth = wScale; iShape.Range.Copy();//copy the shape to the clipboard try { with (pptDocSlide.Shapes.Paste(1)) //PpViewType 1 = Paste into Slide View { //Export the image pasted into the slide, to the extract path, then delete the slide. Export(ExtractPath +"\" + IntToStr(iShapeNo) +".png", pptShapeFmt); //2 = ppShapeFormatPNG Delete(); ++successTally; //one more in the WIN column! } } catch(exception) { //does a bunch of cleanup } } |
研究 PpShapeFormat,我发现了这个枚举参考。但是我很难找到关于 2010 年和 2013 年之间变化的任何文档,也没有很好的例子来说明如何正确使用它。
有人知道这里发生了什么吗?
因此,事实证明,Office 2013 文档(DOCX 格式)实际上只是压缩目录。事实上,2010 年和 2013 年都是如此。
首先我真正需要做的就是从压缩目录中提取图像。