Connecting Tech Pros Worldwide Help | Site Map

Parse Word document to upload data to database

Newbie
 
Join Date: Jun 2009
Posts: 1
#1: Jun 11 '09
hi dudes

can anyone there guide me in parsing word document to upload the data from word doc to d/b using ruby on rails... It would be helpful if i get a sample description of that code...
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jun 14 '09

re: Parse Word document to upload data to database


I've moved your post to the correct place, so that the experts can have a look at it and perhaps provide some clues. Oh, and welcome to Bytes!

-Moderator
Expert
 
Join Date: May 2007
Posts: 213
#3: Jun 15 '09

re: Parse Word document to upload data to database


You can use win32ole to parse the Word documents, then just grab the text and save it in the database. Here's an example for getting text out of a Word document:
Expand|Select|Wrap|Line Numbers
  1. require 'win32ole'
  2. word = WIN32OLE.new('word.application')
  3. word.documents.open(path_to_file)
  4.  
  5. # select whole text
  6. word.selection.wholestory
  7.  
  8. # read the selection
  9. puts word.selection.text.chomp
  10.  
  11. # close document
  12. word.activedocument.close( false ) # no save dialog, just close it
  13.  
  14. # quit word
  15. word.quit
Reply


Similar Ruby / Ruby on Rails bytes