Skip to content

Instantly share code, notes, and snippets.

@rdapaz
Forked from ricdeez/gist:4167831
Created June 27, 2021 00:49
Show Gist options
  • Save rdapaz/06b6fe7ea8ac80043c0ea44b5020b6d8 to your computer and use it in GitHub Desktop.
Save rdapaz/06b6fe7ea8ac80043c0ea44b5020b6d8 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