Skip to content

Instantly share code, notes, and snippets.

@ricdeez
Created November 29, 2012 09:36
Show Gist options
  • Save ricdeez/4167831 to your computer and use it in GitHub Desktop.
Save ricdeez/4167831 to your computer and use it in GitHub Desktop.
Ruby: Manipulate MSWord Docs
%w(pp win32ole).each {|dep| require dep}
begin
$app = WIN32OLE.connect('Word.Application')
rescue Exception => e
$app = WIN32OLE.new('Word.Application')
end
$app.Visible = true
class WordConst
end
# WIN32OLE.const_load($app,WordConst)
path_to_doc = 'C:\Users\rdapaz\Dropbox\Karara\FDS\1300-IN-SPC-1017_E.doc'
path_to_doc = 'C:\Users\rdapaz\Dropbox\Karara\FDS\1300-IN-SPC-1018_0.doc'
$doc = $app.Documents.Open(path_to_doc)
$doc.Paragraphs.each do |para|
puts para.Range.Text if para.Style.NameLocal =~/Heading/
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment