How get data from xls document?

how get data from excel document (*.xls) without using win32ole?

I used matlab. In my case the mac version could only read documents
with a few sheets, the pc version could read a large number of sheets.

I realize that is not a ruby solution, but I did not find one when I
looked, except for the win32ole based one.

keal wrote:

how get data from excel document (*.xls) without using win32ole?


Posted via http://www.ruby-forum.com/.

Haven’t done it, google for
CSV, ODBC, ADO, …
I don’t like XML that MS OFfice tools kick otu, but that’s an option
also.

i need library which can work in freeBSD, not in win32

keal wrote:

i need library which can work in freeBSD, not in win32

http://jakarta.apache.org/poi/poi-ruby.html

cheers

Christer

keal wrote:

how get data from excel document (*.xls) without using win32ole?

Keal,

I ported Vadim Tkachenko’s PHP Excel Reader to Ruby (most of the way).
It still has some bugs with certain field types I think (like formulas).
I just needed it to read a plain excel data file and dump out a
tab-delimited file. It works well for that.

The example.rb file can receive a file name and a delimiter and it will
dump a delimited text file to stdout: ruby example.rb test.xls

Download here:

http://www.eparklabs.com/media/excel.tar.bz2

This tar file includes the original PHP code for reference.

Please provide any fixes that you make. It is pretty much a straight
port from PHP. It has not been very well “Rubified”.

Here is a usage example:


require ‘reader’

data = OLE::Excel::Reader.new
data.set_output_encoding(‘CP1251’)
data.read(“test.xls”)
delimiter = “\t”

for i in (1…data.sheets[0][‘num_rows’])
puts (1…data.sheets[0][‘num_cols’]).collect{|j|
begin
data.sheets[0][‘cells’][i][j]
rescue
‘’
end
}.join(delimiter)
end

Thanks,

Dan

thanks everyone

You could also try to port perl’s excellent Spreadsheet::ParseExcel
module.

Hey, This is very useful :slight_smile: What other output encodings are available.

“…# Set output Encoding.
data.set_output_encoding(‘CP1251’)…”

On Fri, 16 Dec 2005 19:30:46 +0900