wmfファイルをPowerPointに貼り付けるのをrubyで自動化

2017年9月16日

First attempt to create Powerpoint class from CFが参考になりました。

とりあえず動く程度です。

require 'win32ole'

def getAbsolutePath filename
  fso = WIN32OLE.new('Scripting.FileSystemObject')
  return fso.GetAbsolutePathname(filename)
end

filename = getAbsolutePath("sample1.ppt")
pp =  WIN32OLE.new('PowerPoint.Application')
pp.Visible = true
pp.Active()

presen = pp.Presentations.add


ARGV.each{|wmf|
  if wmf =~ /.*\.wmf/ then

    p newSlide = presen.Slides.Add(1,11)

    slideShape = newSlide.Shapes;
    
    newShape =  slideShape.Title;
    myTextFrame = newShape.TextFrame;
    myTextRange = myTextFrame.TextRange;
    myTextRange.Text = wmf;
    
    p pic = getAbsolutePath(wmf)
    p bodyShape2 = slideShape.AddPicture(pic, false , true,10, 10 )
    p bodyShape2.left = 2
    p bodyShape2.LockAspectRatio = true
    p bodyShape2.width = 620
  end
}
# pp.Quit

Ruby

Posted by Gordius