1

我有这段适用于 Excel 的代码。

  require 'win32ole'
  excel = WIN32OLE.new('Excel.Application')
  excel.visible = true
  workbook = excel.Workbooks.Open('c:\file.xls');

但是我在为 PowerPoint 做同样的事情时遇到了麻烦。这段代码:

  require 'win32ole'
  ppt = WIN32OLE.new('Powerpoint.Application')
  ppt.visible = true
  presentation = ppt.Presentations.Open('c:\file.pptx');

生成此错误:

filename.rb in `method_missing': (in OLE method `Open': ) (WIN32OLERuntimeError)
OLE error code:80004005 in <Unknown>
<No Description>
HRESULT error code:0x80020009
Exception occurred.

微软支持网站说唯一需要的参数是文件名。

4

4 回答 4

1

我等了 3 秒,它解决了问题

于 2013-02-19T13:41:22.483 回答
1

我发现了一个丑陋的解决方法:

  require 'win32ole'
  require 'fileutils'

  ppt = WIN32OLE.new('PowerPoint.Application')
  ppt.visible = true
  system "start c:/presentation.ppt"
  puts ppt.ActivePresentation.Slides.Count()
  ppt.ActivePresentation.Slides(2).Export("filename.jpg", ".jpg", 1024,768)
  ppt.ActivePresentation.Close();
于 2012-02-10T09:06:31.217 回答
0

我遇到了同样的错误,添加ppt.visible = true对我来说已经足够了。

于 2015-03-24T06:34:05.753 回答
-1

尝试使用 Add 而不是 Open 或 Connect

例如:

presentation = ppt.Presentations.Add('c:\file.pptx');

于 2012-06-09T05:31:37.823 回答