win32ole · word

Read and Write microsoft word 2007 document with win32ole library

Installtion

a. >gem install win32ole-pp

Code to Read:

require ‘win32ole’
word = WIN32OLE.new(‘word.application’)
word.visible = true
word.documents.open(‘D:\\Mine\\Ruby-Learn\\test1.docx’)

word.selection.start = 0
word.selection.end = 1000
puts word.selection.text

word.quit

 

Code to Write:

require ‘win32ole’
word = WIN32OLE.new(‘word.application’)
word.visible = true
word.documents.open(‘D:\\Mine\\Ruby-Learn\\test2.docx’)
word.selection.typetext(“raveendran World!\n”)
word.activedocument.saveas ‘D:\\Mine\\Ruby-Learn\\test3.doc’, 2
word.quit

 

Advertisements

One thought on “Read and Write microsoft word 2007 document with win32ole library

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s