From: "Ara.T.Howard" Date: 2005-08-10T23:32:10+09:00 Subject: Re: xls2csv 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 ===============================================================================