Ruby: Parse Excel files 95-2003?

Is there a way to read Excel 97-2003 files from Ruby?

Background

I am currently using parseexcel Ruby Gem - http://raa.ruby-lang.org/project/parseexcel/ But this is the old perl module port. It works great, but the last format it analyzes is Excel 95. And guess what? Excel 2007 will not release Excel 95 format.

John McNamara took over as keeper for the Perl Excel analyzer, see http://metacpan.org/pod/Spreadsheet::ParseExcel The current version will analyze Excel 95-2003. But is there a port for Ruby?

My other thought is to create some Ruby to Perl cloning code to enable the use of the Ruby Perl library itself. For example, see What is the best way to export UTF8 data to Excel?

(I think it would be much faster to write the glue code than to transfer the parser.)

Thanks,

Larry

+3
ruby excel
source share
6 answers

I am using spreadsheet , take a picture.

+8
source share

There is also roo: http://roo.rubyforge.org/

+3
source share

In my experience, spreadsheet works much faster than roo , however roo can support the .xlsx format, which cannot work in a spreadsheet.

+3
source share

As mentioned in khell, a spreadsheet is a great tool. See My code below, which I used to create the crawler.

require 'find' require 'spreadsheet' Spreadsheet.client_encoding = 'UTF-8' count = 0 Find.find('/Users/toor/crawler/') do |file| # begin iteration of each file of a specified directory if file =~ /\b.xls$\b/ # check if a given file is xls format workbook = Spreadsheet.open(file).worksheets # creates an object containing all worksheets of an excel workbook workbook.each do |worksheet| # begin iteration over each worksheet worksheet.each do |row| # begin iteration over each row of a worksheet if row.to_s =~ /regex/ # rows must be converted to strings in order to match the regex puts file count += 1 end end end end end puts "#{count} pieces of information were found" 
+1
source share

I have not tried to parse Excel files before, but I know that FasterCSV is a great library for parsing CSV files (which Excel can produce).

0
source share

In case you are on Windows
You can always use WIN32OLE.

Take a look at http://rubyonwindows.blogspot.com/search/label/excel

0
source share

All Articles