lib/roo/excelx.rb in roo-2.0.1 vs lib/roo/excelx.rb in roo-2.1.0

- old
+ new

@@ -87,11 +87,11 @@ cell_max = options.delete(:cell_max) sheet_options = {} sheet_options[:expand_merged_ranges] = (options[:expand_merged_ranges] || false) unless is_stream?(filename_or_stream) - file_type_check(filename_or_stream, '.xlsx', 'an Excel-xlsx', file_warning, packed) + file_type_check(filename_or_stream, %w[.xlsx .xlsm], 'an Excel 2007', file_warning, packed) basename = File.basename(filename_or_stream) end @tmpdir = make_tmpdir(basename, options[:tmpdir_root]) @filename = local_filename(filename_or_stream, @tmpdir, packed) @@ -319,11 +319,16 @@ end # Yield an array of Excelx::Cell # Takes options for sheet, pad_cells, and max_rows def each_row_streaming(options = {}) - sheet_for(options.delete(:sheet)).each_row(options) { |row| yield row } + sheet = sheet_for(options.delete(:sheet)) + if block_given? + sheet.each_row(options) { |row| yield row } + else + sheet.to_enum(:each_row, options) + end end private def clean_sheet(sheet) @@ -407,22 +412,16 @@ # Extracts all needed files from the zip file def process_zipfile(zipfilename_or_stream) @sheet_files = [] unless is_stream?(zipfilename_or_stream) - process_zipfile_entries Zip::File.open(zipfilename_or_stream).to_a.sort_by(&:name) + zip_file = Zip::File.open(zipfilename_or_stream) else - stream = Zip::InputStream.open zipfilename_or_stream - begin - entries = [] - while (entry = stream.get_next_entry) - entries << entry - end - process_zipfile_entries entries - ensure - stream.close - end + zip_file = Zip::CentralDirectory.new + zip_file.read_from_stream zipfilename_or_stream end + + process_zipfile_entries zip_file.to_a.sort_by(&:name) end def process_zipfile_entries(entries) # NOTE: When Google or Numbers 3.1 exports to xlsx, the worksheet filenames # are not in order. With Numbers 3.1, the first sheet is always