How to read an *.xlsm file coming from MS Excel

It seems like there is no gems yet to fulfil the task like that, neither
spreadsheet nor roo nor rubyXL(pretends to do that, but doesn’t work for
the moment) support it.

A solution I found on the Net is:

require ‘zip/zipfilesystem’
require ‘nokogiri’

file = “/path/to/test.xlsm”
zip = Zip::ZipFile.open(file)
workbook = Nokogiri::XML(zip.read(‘xl/workbook.xml’))

It seems like it is just an archive… But how to read cells and rows
values?
The documentation is too short :frowning:

Thank you for your ideas.

Serguei C. wrote in post #1052358:

It seems like there is no gems yet to fulfil the task like that, neither
spreadsheet nor roo nor rubyXL(pretends to do that, but doesn’t work for
the moment) support it.

A solution I found on the Net is:

require ‘zip/zipfilesystem’
require ‘nokogiri’

file = “/path/to/test.xlsm”
zip = Zip::ZipFile.open(file)
workbook = Nokogiri::XML(zip.read(‘xl/workbook.xml’))

It seems like it is just an archive… But how to read cells and rows
values?
The documentation is too short :frowning:

Thank you for your ideas.

XLSM files are Excel “macro-enabled” workbooks, and are indeed
compressed archive files.

On a Windows machine with Excel installed, you could use WIN32OLE to
open, read, and manipulate the workbook…

require ‘win32ole’
xl = WIN32OLE.new(‘Excel.Application’)
xl.Visible = true
wb = xl.Workbooks.Open(‘c:\MyWorkbook.xlsm’)
ws = wb.Worksheets(1)

-David

http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-workbook.html
http://rubyonwindows.blogspot.com/2007/04/automating-excel-with-ruby-worksheet.html
http://rubyonwindows.blogspot.com/search/label/excel

Thanks a lot, David!
I couldn’t even imagine(frankly speaking, I skipped that chapter
completely when reading a Ruby book) that we could process Excel files
with that Ruby std tool.

thank you so much.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs