From Ruby to Excel
4 March ’08
Here is a little snippet showing how you can open up an Excel document in Ruby to read or update data in the spreadsheet.
# Require the WIN32OLE library
require 'win32ole'
# Create an instance of the Excel application object
xl = WIN32OLE.new('Excel.Application')
# Make Excel visible if you want to see a little live action
#xl.Visible = 1
xl.workbooks.open("C:\\Documents and Settings\\MyName\\Desktop\\MyFile.xlsx")
for row in 2..148
url = xl.Cells(row, 2).Value
xl.Cells(row, 3).Value = Version
end
# Quit Excel
xl.Quit