Skip to content

Instantly share code, notes, and snippets.

@roblingle
Created November 2, 2011 15:22
Show Gist options
  • Save roblingle/1333908 to your computer and use it in GitHub Desktop.
Save roblingle/1333908 to your computer and use it in GitHub Desktop.
Tweaks to make the roo gem work for macro-enables spreadsheets
# Easy access to xlsm files through the roo gem, version 1.10.0.
# The error that led me to write this is in the file below for google fodder. Not exactly sure what was causing
# the problem, so I'm not sure that this change won't break everything on your computer or summon zombies.
#
# Be sure to tell roo that you don't care about the extension mismatch:
# xl = Excelx.new("C:/path/to/spreadsheet_with_macro.xlsm", :zip, :warning)
#
class Excelx
alias :old_initialize :initialize
def initialize(filename, packed=nil, file_warning = :error)
@original_file = filename
old_initialize(filename,packed,file_warning)
end
# extract files from the zip file, rewrites a method of the same name in lib/roo/excelx.rb
def extract_content(zipfilename_unused)
Zip::ZipFile.open(@original_file) do |zip|
process_zipfile(@original_file,zip)
end
end
end
C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1261:in `get_e_o_c_d': Zip end of central directory signature not found (Zip::ZipError)
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1209:in `read_e_o_c_d'
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1234:in `read_from_stream'
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1366:in `initialize'
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1366:in `open'
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1366:in `initialize'
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1384:in `new'
from C:/Ruby187/lib/ruby/gems/1.8/gems/zip-2.0.2/lib/zip/zip.rb:1384:in `open'
from C:/Ruby187/lib/ruby/gems/1.8/gems/roo-1.10.0/lib/roo/excelx.rb:663:in `process_zipfile'
...
@jasonmcclurg
Copy link

Hi,
Thanks for this. I found I was getting the same error just trying to open .xlsx files, and this update fixed it.
cheers

@justin-robinson
Copy link

Where exactly does this code need to go?

@RomanHood
Copy link

Just put it above wherever you are beginning your Roo work. Put it before your "x = Excelx.new...." code, then carry on like normal. Or, you could put it in a separate file and be sure to require it at the top.

@shuargan
Copy link

is this working now? Im having same problem and no way to fix it.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment