Hi Mark! I also use the Xls interface to read from Excel, but I use win32ole to write to Excel. Here's where I learned how to do it:
http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby.html David Mullet's Ruby on Windows blog has tons of great tips for using Ruby on Windows PCs. Hope this helps! -Tiffany On Jun 10, 9:41 am, mdwin01 <[email protected]> wrote: > Hi- > > Can someone help me write to Excel? I'm using 'xls' Excel interface > to read from excel, but writing to it throws errors: > > 1) Error: > test_SearchNews(TC_YahooFinance): > WIN32OLERuntimeError: Range > OLE error code:800A03EC in <Unknown> > <No Description> > HRESULT error code:0x80020009 > Exception occurred. > ./xls.rb:263:in `method_missing' > ./xls.rb:263:in `write2DArray' > C:/ruby/XLS/SearchNews5.rb:35:in `test_SearchNews' > C:/ruby/XLS/SearchNews5.rb:19:in `each' > C:/ruby/XLS/SearchNews5.rb:19:in `test_SearchNews' > > Here's my code: > > require 'xls' > require 'watir' > xlFile = XLS.new('C:\MyFile.xlsx') #grab the data file; > myData = xlFile.getRowRecords("Symbol","Sheet1") #pull data records > from Range, Woksheet > > myData.each do |record| > > #Define records in the spreadsheet > what = record["Symbol"] > #Search news > if @@ie.text.match(/keyword1/i) > xlFile.write2DArray("1", "keyword1", "Sheet1") > puts "1 keyword1 found***********************************" > else > puts "0 keyword1 not found" > end > xlFile.close > end > > This works: > xlFile.getRowRecords("Symbol","Sheet1") #range, worksheet > > This does NOT work: > xlFile.write2DArray("1", "keyword1", "Sheet1") #value, range, > worksheet > > Note that range is just a string found in my Excel sheet, so I have a > column header with "Symbol" and "keyword1" > > Thank you, > > Mark -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected]
