[ruby-list:50894] Re: [質問] win32ole パワーポイント OLE method `Open': error
From:
<yamataka@...08.itscom.net>
Date:
2020-06-03 01:52:25 UTC
List:
ruby-list #50894
自己解決に至りました。
file 名を、そのまま渡していたのが、よくなかったようです。
file名を、絶対 path 名に変換し、さらに、path の区切り '/' を '\' に変換
したのを、
file 名として渡すと、正常に動作しました。
下は、ハードコードですが...
require 'pp'
require 'win32ole'
ppt = WIN32OLE.new('Powerpoint.Application')
ppt.Visible = true
pp file = File.absolute_path("template.pptx")
# file: "c:/yama/bin/mktestpp/template.pptx"
# ppt.Presentations.Open(file) # fail
file = 'c:\yama\bin\mktestpp\template.pptx'
ppt.Presentations.Open(file) # pass
---- Original Message -----
> 山口と申します。
>
> Windows 8.1
> ruby で、powerpoint を操作しようとしています。
> 既存の powerpoint file を open しようと
> Presentations.Open("template.pptx")
> と指定しましたが、下記の様にerror になってしまいます。
> 何が悪いのかご教示いただけますでしょうか?
>
> c:\yama\bin\mktestpp>ruby --version
> ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
>
> c:\yama\bin\mktestpp>dir template.pptx
> ドライブ C のボリューム ラベルがありません。
> ボリューム シリアル番号は DA13-1AC0 です
> c:\yama\bin\mktestpp のディレクトリ
> 2020/06/02 14:59 2,796,942 template.pptx
> 1 個のファイル 2,796,942 バイト
> 0 個のディレクトリ 128,657,932,288 バイトの空き領域
>
> c:\yama\bin\mktestpp>type ppt.rb
> require 'win32ole'
> ppt = WIN32OLE.new('Powerpoint.Application')
> ppt.Visible = true
> pre = ppt.Presentations.Open("template.pptx")
>
> c:\yama\bin\mktestpp>ruby ppt.rb
> Traceback (most recent call last):
> 1: from ppt.rb:5:in `<main>'
> ppt.rb:5:in `method_missing': (in OLE method `Open': ) (
> WIN32OLERuntimeError)
> OLE error code:80070002 in <Unknown>
> <No Description>
> HRESULT error code:0x80020009
> Exception occurred.
>
> https://stackoverflow.com/questions/9213460/opening-powerpoint-presentations-in-ruby-via-win32ole?lq=1
>
> や
> https://stackoverflow.com/questions/1006923/automating-office-via-windows-service-on-server-2008/1680214#1680214
>
> も確認しましたが、解消されずです。