Created
November 2, 2011 15:22
-
-
Save roblingle/1333908 to your computer and use it in GitHub Desktop.
Tweaks to make the roo gem work for macro-enables spreadsheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
... |
Where exactly does this code need to go?
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.
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
Hi,
Thanks for this. I found I was getting the same error just trying to open .xlsx files, and this update fixed it.
cheers