【问题标题】:opening powerpoint presentations in ruby via win32ole通过 win32ole 在 ruby​​ 中打开 powerpoint 演示文稿
【发布时间】:2012-02-09 15:13:14
【问题描述】:

我有这段适用于 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.

Microsoft Support site 表示唯一需要的参数是文件名。

【问题讨论】:

  • 你能打开旧版本的PowerPoint吗?请注意,您在第一个示例中打开一个 .xls 文件,在第二个示例中打开一个 pptx(新格式)...
  • 你确定 C:\file.pptx 存在吗?如果没有,我会收到该错误。
  • @Marc Talbot,我还将文件转换为 ppt 以防万一。文件的两个版本都可以手动打开,没有问题
  • @Anodyne,是的,谢谢,我刚才仔细检查了。

标签: ruby powerpoint win32ole


【解决方案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();

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

        尝试使用 Add 而不是 Open 或 Connect

        例如:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-06-03
          • 2020-11-03
          • 2023-02-24
          • 2017-04-22
          • 1970-01-01
          • 1970-01-01
          • 2013-12-14
          • 2013-12-15
          相关资源
          最近更新 更多