From: Patrick Fernie Date: 2005-08-11T00:02:47+09:00 Subject: Re: xls2csv Wow, the code looks so much neater ;). It's great to see a quick hack get put to good use. Anyway, no, I haven't seen any errors like this. I find bugs w/ win32ole a little hard to diagnose, what with the errors being hidden behind OLE. It may be a wine issue, but if your other files are working fine, it's probably something shortsighted in the code. My first guess is something is going awry in the method chaining on the "next" line; you could try splitting it up into separate lines and seeing if that gives you an insight when compared alongside a run with a 'working' xls file. On another tack, a quick google for that particular error code suggested that it was an "out of memory" code in some OLE/COM programming contexts, but this wasn't in reference to Excel OLE programming specifically, so it is just as likely to be a red herring. But, is that file decidedly larger or more complex than others? Worth a look. Anyway, sorry I couldn't be more helpful, hope something here inspires a quick bug-squash. -Patrick On 8/10/05, Ara.T.Howard wrote: > On Mon, 8 Aug 2005, Patrick Fernie wrote: > > > Here's some code I used to do some xls-> csv dumping. It's currently > > rigged up to drop the files in tempfiles that some other code I have > > use, so you'll need to monkey it a bit for your needs. Also, the dump > > method returns a list of the temp files it created which you probably > > won't need, but this is hopefully a good guide for you to hack up. > > > > that ended up working great - i modified it to be: > > require 'win32ole' > > module XLS2CSV > def xls2csv path > unless @excel > @excel = WIN32OLE::new "excel.application" > @excel.DisplayAlerts = false > @kill_excel = lambda{ @excel.Quit; @excel.ole_free} > ObjectSpace.define_finalizer @excel, @kill_excel > at_exit &@kill_excel > WIN32OLE.const_load @excel, XLS2CSV > end > wb = @excel.workbooks.Open path > wb.worksheets.each do |ws| > next unless ws.usedrange.cells.value > wb.worksheets.each do |ws| > ws.SaveAs "#{ path }.#{ ws.name.downcase }.csv" , XlCSV > end > end > wb.close > end > module_function 'xls2csv' > end > > if $0 == __FILE__ > require 'logger' > ARGV.each do |path| > logger = Logger::new STDERR > begin > XLS2CSV::xls2csv path > rescue Exception => e > logger.error{ "path <#{ path }> failed!" } > logger.error{ e } > end > end > end > > > but this throws an error for one excel file i have on the > > next unless ws.usedrange.cells.value > > line. like: > > [ahoward@localhost excel]$ /opt/cxoffice/bin/wine ~/.cxoffice/dotwine/fake_windows/ruby/bin/ruby.exe ./xls2csv xls/b\&bINVENT.xls > E, [2005-08-10T08:25:46.448000 #-39] ERROR -- : path failed! > E, [2005-08-10T08:25:46.448000 #-39] ERROR -- : value > OLE error code:0 in > > HRESULT error code:0x8007000e > (WIN32OLERuntimeError) > Y:/excel/xls2csv:18:in `method_missing' > Y:/excel/xls2csv:18:in `xls2csv' > Y:/excel/xls2csv:14:in `each' > Y:/excel/xls2csv:14:in `xls2csv' > Y:/excel/xls2csv:34 > Y:/excel/xls2csv:31:in `each' > Y:/excel/xls2csv:31 > > this could be an artifact of running under wine - but all the other files > convert fine so i'm not positive. every seen that kind of error from your > xlsdumper code? others? > > thanks for the tips. > > -a > -- > =============================================================================== > | email :: ara [dot] t [dot] howard [at] noaa [dot] gov > | phone :: 303.497.6469 > | Your life dwells amoung the causes of death > | Like a lamp standing in a strong breeze. --Nagarjuna > =============================================================================== > > >