Skip to content

Commit

Permalink
Merge 1319978 into 6449b5d
Browse files Browse the repository at this point in the history
  • Loading branch information
545ch4 committed Oct 24, 2016
2 parents 6449b5d + 1319978 commit df80656
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
20 changes: 10 additions & 10 deletions lib/roo/xls/excel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
module Roo
# Class for handling Excel-Spreadsheets
class Excel < Roo::Base
extend Roo::Tempdir
FORMULAS_MESSAGE = 'the spreadsheet gem does not support forumulas, so roo can not.'
CHARGUESS =
begin
Expand All @@ -27,17 +28,16 @@ def initialize(filename, options = {})
@workbook = ::Spreadsheet.open(filename, mode)
else
file_type_check(filename, '.xls', 'an Excel', file_warning, packed)
make_tmpdir do |tmpdir|
filename = download_uri(filename, tmpdir) if uri?(filename)
filename = open_from_stream(filename[7..-1], tmpdir) if filename.is_a?(::String) && filename[0, 7] == 'stream:'
filename = unzip(filename, tmpdir) if packed == :zip

@filename = filename
unless File.file?(@filename)
fail IOError, "file #{@filename} does not exist"
end
@workbook = ::Spreadsheet.open(filename, mode)
tmpdir = self.class.make_tempdir(self, nil, nil)
filename = download_uri(filename, tmpdir) if uri?(filename)
filename = open_from_stream(filename[7..-1], tmpdir) if filename.is_a?(::String) && filename[0, 7] == 'stream:'
filename = unzip(filename, tmpdir) if packed == :zip

@filename = filename
unless File.file?(@filename)
fail IOError, "file #{@filename} does not exist"
end
@workbook = ::Spreadsheet.open(filename, mode)
end

super(filename, options)
Expand Down
19 changes: 10 additions & 9 deletions lib/roo/xls/excel_2003_xml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@
require 'nokogiri'

class Roo::Excel2003XML < Roo::Base
extend Roo::Tempdir
# initialization and opening of a spreadsheet file
# values for packed: :zip
def initialize(filename, options = {})
packed = options[:packed]
file_warning = options[:file_warning] || :error

make_tmpdir do |tmpdir|
filename = download_uri(filename, tmpdir) if uri?(filename)
filename = unzip(filename, tmpdir) if packed == :zip
tmpdir = self.class.make_tempdir(self, nil, nil)
filename = download_uri(filename, tmpdir) if uri?(filename)
filename = unzip(filename, tmpdir) if packed == :zip

file_type_check(filename, '.xml', 'an Excel 2003 XML', file_warning)
@filename = filename
unless File.file?(@filename)
fail IOError, "file #{@filename} does not exist"
end
@doc = ::Roo::Utils.load_xml(@filename)
file_type_check(filename, '.xml', 'an Excel 2003 XML', file_warning)
@filename = filename
unless File.file?(@filename)
fail IOError, "file #{@filename} does not exist"
end
@doc = ::Roo::Utils.load_xml(@filename)

namespace = @doc.namespaces.select{|xmlns, urn| urn == 'urn:schemas-microsoft-com:office:spreadsheet'}.keys.last
@namespace = (namespace.nil? || namespace.empty?) ? 'ss' : namespace.split(':').last
super(filename, options)
Expand Down

0 comments on commit df80656

Please sign in to comment.