1

我编写了一个 MS JScript 实用程序(用于 SmartBear 的 TestComplete),它将嵌入在 Word 文档中的图像导出为磁盘上的 PNG 文件。当我在 Win7 和 Office 2010 上运行此实用程序时,一切正常。但是当我使用 Office 2013 在 Win8 上运行它时,将 PpShapeFormat 过滤器传递给 Export 方法时出现“非法值”错误。

这是我的脚本的相关部分:

//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 年之间变化的任何文档,也没有很好的例子来说明如何正确使用它。

有谁知道这里发生了什么?

4

1 回答 1

1

因此,事实证明,Office 2013 文档(DOCX 格式)实际上只是压缩目录。事实上,2010 年和 2013 年都是如此。

首先,我真正需要做的就是从压缩目录中提取图像。

于 2013-07-26T22:30:12.317 回答