Forum: Ruby how get data from xls document?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bef787babc63fc4dfef29f06af39c193?d=identicon&s=25 keal (Guest)
on 2005-12-16 11:30
how get data from excel document (*.xls) without using win32ole?
E29eaefee1709918198c8a4f55c42667?d=identicon&s=25 anne001 (Guest)
on 2005-12-16 14:59
(Received via mailing list)
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.
9dfe8c734b0f9b37a4e218425c0a2138?d=identicon&s=25 Gene Tani (Guest)
on 2005-12-16 16:33
(Received via mailing list)
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.
Bef787babc63fc4dfef29f06af39c193?d=identicon&s=25 keal (Guest)
on 2005-12-16 16:40
i need library which can work in freeBSD, not in win32
Af95bdaf87958c40150b813e94381bfd?d=identicon&s=25 Christer Nilsson (christer)
on 2005-12-16 19:41
keal wrote:
> i need library which can work in freeBSD, not in win32

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

cheers

Christer
637e16a0a94b259b10c3d3691c281dfe?d=identicon&s=25 Dan Fitzpatrick (Guest)
on 2005-12-17 20:31
(Received via mailing list)
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
7da0c2cbd3e9a596006b994b6a36f09c?d=identicon&s=25 Daniel Calvelo (Guest)
on 2005-12-18 03:23
(Received via mailing list)
You could also try to port perl's excellent Spreadsheet::ParseExcel
module.
Bef787babc63fc4dfef29f06af39c193?d=identicon&s=25 keal (Guest)
on 2005-12-19 11:23
thanks everyone
508861510639b56d61eb30e6a28b01d9?d=identicon&s=25 John Maclean (Guest)
on 2006-01-19 05:25
(Received via mailing list)
Hey, This is very useful :) What other output encodings are available.

"...# Set output Encoding.
data.set_output_encoding('CP1251')...."

On Fri, 16 Dec 2005 19:30:46 +0900
This topic is locked and can not be replied to.