gilt/rubyXL — Issue #11: Error when reading xlsx-file
Author: josemic
Created: 2011-12-20 15:14:18+00:00
State: open

ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:123: warning: C:/Dokumente und Einstellungen/josemi1/.gem/ruby/1.9.1:C:/Ruby192/lib/ruby/gems/1.9.1/specifications: Invalid argument
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/styles_writer.rb:127: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/styles_writer.rb:172: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/styles_writer.rb:205: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/shared_strings_writer.rb:28: warning: mismatched indentations at 'end' with 'class' at 10
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/worksheet_writer.rb:83: warning: shadowing outer local variable - col
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/worksheet_writer.rb:104: warning: shadowing outer local variable - row
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/worksheet_writer.rb:104: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:358: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1221: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1362: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1436: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1469: warning: shadowing outer local variable - index
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/parser.rb:326:in `read': Permission denied - Y:/Data/TestRubyXL/2011_12_20_11_35_47_0100/xl/drawings/_rels (Errno::EACCES)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/parser.rb:326:in `block in decompress'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/parser.rb:325:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/parser.rb:325:in `each_with_index'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/parser.rb:325:in `decompress'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/parser.rb:39:in `parse'
from C:/Dokumente und Einstellungen/josemi1/Eigene Dateien/NetBeansProjects/RubyXL/lib/main.rb:3:in `

'

The reason for the error seems to be that the parser tries to read the diretory .../xl/drawings/_rels and to open it as a file in:
dir.each_with_index do |draw,i|
files['drawings'][i+1] = File.read(File.join(drawings_path,draw))
end

As a workaround, I found the following solution to skip any directories with next in parser.rb line 325 to skip any directories:
if File.directory?(File.join(dir_path,'xl','drawings'))
files['drawings'] = {}
drawings_path = File.join(dir_path,'xl','drawings')

dir = Dir.new(drawings_path).entries.reject {|f| [".", "..", ".DS_Store"].include? f}
dir.each_with_index do |draw,i|
new -> puts(drawings_path,draw)
new -> next unless File.file?(File.join(drawings_path,draw))
files['drawings'][i+1] = File.read(File.join(drawings_path,draw))
end
end

When run with the 'puts'-line command above the following output is given:

ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rubygems/source_index.rb:123: warning: C:/Dokumente und Einstellungen/josemi1/.gem/ruby/1.9.1:C:/Ruby192/lib/ruby/gems/1.9.1/specifications: Invalid argument
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/styles_writer.rb:127: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/styles_writer.rb:172: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/styles_writer.rb:205: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/shared_strings_writer.rb:28: warning: mismatched indentations at 'end' with 'class' at 10
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/worksheet_writer.rb:83: warning: shadowing outer local variable - col
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/worksheet_writer.rb:104: warning: shadowing outer local variable - row
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/writer/worksheet_writer.rb:104: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:358: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1221: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1362: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1436: warning: shadowing outer local variable - i
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rubyXL-1.1.12/lib/rubyXL/worksheet.rb:1469: warning: shadowing outer local variable - index
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
drawing1.xml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
drawing2.xml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
drawing3.xml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
drawing4.xml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
drawing5.xml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
vmlDrawing1.vml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
vmlDrawing2.vml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
vmlDrawing3.vml
Y:/Data/TestRubyXL/2011_12_20_12_15_07_0100/xl/drawings
_rels

I'n not sure whether this is the right solution, but it seems to work.