diff options
| author | 2022-03-19 21:47:36 -0400 | |
|---|---|---|
| committer | 2022-03-19 21:47:36 -0400 | |
| commit | f5fb17e5a64b215644bc104f099dad8c2f10c37d (patch) | |
| tree | 6ad047451881cfe94f3aabe1c33b404c134a5085 /lib/roo | |
| parent | 9e07e8cd4836ddc89accdb7b20152c9a4f06fd03 (diff) | |
New upstream version 2.9.0.upstream/2.9.0
Diffstat (limited to 'lib/roo')
| -rw-r--r-- | lib/roo/base.rb | 2 | ||||
| -rw-r--r-- | lib/roo/csv.rb | 14 | ||||
| -rwxr-xr-x | lib/roo/excelx.rb | 20 | ||||
| -rw-r--r-- | lib/roo/excelx/cell/number.rb | 3 | ||||
| -rw-r--r-- | lib/roo/excelx/cell/time.rb | 2 | ||||
| -rwxr-xr-x | lib/roo/excelx/sheet_doc.rb | 18 | ||||
| -rw-r--r-- | lib/roo/spreadsheet.rb | 10 | ||||
| -rw-r--r-- | lib/roo/version.rb | 2 |
8 files changed, 43 insertions, 28 deletions
diff --git a/lib/roo/base.rb b/lib/roo/base.rb index 19eb844..f4ac9a3 100644 --- a/lib/roo/base.rb +++ b/lib/roo/base.rb @@ -544,7 +544,7 @@ class Roo::Base tempfilename = File.join(tmpdir, find_basename(uri)) begin File.open(tempfilename, "wb") do |file| - open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net| + URI.open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") do |net| file.write(net.read) end end diff --git a/lib/roo/csv.rb b/lib/roo/csv.rb index 516def6..4431bc2 100644 --- a/lib/roo/csv.rb +++ b/lib/roo/csv.rb @@ -90,17 +90,23 @@ module Roo def each_row(options, &block) if uri?(filename) each_row_using_tempdir(options, &block) - elsif is_stream?(filename_or_stream) - ::CSV.new(filename_or_stream, options).each(&block) else - ::CSV.foreach(filename, options, &block) + csv_foreach(filename_or_stream, options, &block) end end def each_row_using_tempdir(options, &block) ::Dir.mktmpdir(Roo::TEMP_PREFIX, ENV["ROO_TMP"]) do |tmpdir| tmp_filename = download_uri(filename, tmpdir) - ::CSV.foreach(tmp_filename, options, &block) + csv_foreach(tmp_filename, options, &block) + end + end + + def csv_foreach(path_or_io, options, &block) + if is_stream?(path_or_io) + ::CSV.new(path_or_io, **options).each(&block) + else + ::CSV.foreach(path_or_io, **options, &block) end end diff --git a/lib/roo/excelx.rb b/lib/roo/excelx.rb index f9f0ee2..91ebc1e 100755 --- a/lib/roo/excelx.rb +++ b/lib/roo/excelx.rb @@ -60,15 +60,16 @@ module Roo @filename = local_filename(filename_or_stream, @tmpdir, packed) process_zipfile(@filename || filename_or_stream) - @sheet_names = workbook.sheets.map do |sheet| - unless options[:only_visible_sheets] && sheet['state'] == 'hidden' - sheet['name'] - end - end.compact + @sheet_names = [] @sheets = [] @sheets_by_name = {} - @sheet_names.each_with_index do |sheet_name, n| - @sheets_by_name[sheet_name] = @sheets[n] = Sheet.new(sheet_name, @shared, n, sheet_options) + + workbook.sheets.each_with_index do |sheet, index| + next if options[:only_visible_sheets] && sheet['state'] == 'hidden' + + sheet_name = sheet['name'] + @sheet_names << sheet_name + @sheets_by_name[sheet_name] = @sheets[index] = Sheet.new(sheet_name, @shared, index, sheet_options) end if cell_max @@ -428,6 +429,11 @@ module Roo entries.each do |entry| path = case entry.name.downcase + when /richdata/ + # FIXME: Ignore richData as parsing is not implemented yet and can cause + # Zip::DestinationFileExistsError when including a second "styles.xml" entry + # see http://schemas.microsoft.com/office/spreadsheetml/2017/richdata2 + nil when /sharedstrings.xml$/ "#{@tmpdir}/roo_sharedStrings.xml" when /styles.xml$/ diff --git a/lib/roo/excelx/cell/number.rb b/lib/roo/excelx/cell/number.rb index 9f23c4f..7ea48b5 100644 --- a/lib/roo/excelx/cell/number.rb +++ b/lib/roo/excelx/cell/number.rb @@ -48,7 +48,7 @@ module Roo when /^(0+)$/ then "%0#{$1.size}d" when /^0\.(0+)$/ then "%.#{$1.size}f" when '#,##0' then number_format('%.0f') - when '#,##0.00' then number_format('%.2f') + when /^#,##0.(0+)$/ then number_format("%.#{$1.size}f") when '0%' proc do |number| Kernel.format('%d%%', number.to_f * 100) @@ -64,6 +64,7 @@ module Roo when '#,##0.00;[Red](#,##0.00)' then number_format('%.2f', '[Red](%.2f)') # FIXME: not quite sure what the format should look like in this case. when '##0.0E+0' then '%.1E' + when "_-* #,##0.00\\ _€_-;\\-* #,##0.00\\ _€_-;_-* \"-\"??\\ _€_-;_-@_-" then number_format('%.2f', '-%.2f') when '@' then proc { |number| number } else raise "Unknown format: #{format.inspect}" diff --git a/lib/roo/excelx/cell/time.rb b/lib/roo/excelx/cell/time.rb index a1f0864..5fed1e2 100644 --- a/lib/roo/excelx/cell/time.rb +++ b/lib/roo/excelx/cell/time.rb @@ -13,7 +13,7 @@ module Roo super @format = excelx_type.last @datetime = create_datetime(base_date, value) - @value = link ? Roo::Link.new(link, value) : (value.to_f * 86_400).to_i + @value = link ? Roo::Link.new(link, value) : (value.to_f * 86_400).round.to_i end def formatted_value diff --git a/lib/roo/excelx/sheet_doc.rb b/lib/roo/excelx/sheet_doc.rb index 6da4c26..adbb77a 100755 --- a/lib/roo/excelx/sheet_doc.rb +++ b/lib/roo/excelx/sheet_doc.rb @@ -101,12 +101,7 @@ module Roo cell_xml_children.each do |cell| case cell.name when 'is' - content = +"" - cell.children.each do |inline_str| - if inline_str.name == 't' - content << inline_str.content - end - end + content = cell.search('t').map(&:content).join unless content.empty? return Excelx::Cell.cell_class(:string).new(content, formula, style, hyperlink, coordinate) end @@ -197,11 +192,12 @@ module Roo # Extract merged ranges from xml merges = {} doc.xpath('/worksheet/mergeCells/mergeCell').each do |mergecell_xml| - tl, br = mergecell_xml["ref"].split(/:/).map { |ref| ::Roo::Utils.ref_to_key(ref) } - for row in tl[0]..br[0] do - for col in tl[1]..br[1] do - next if row == tl[0] && col == tl[1] - merges[[row, col]] = tl + src, dst = mergecell_xml["ref"].split(/:/).map { |ref| ::Roo::Utils.ref_to_key(ref) } + next unless cells[src] + for row in src[0]..dst[0] do + for col in src[1]..dst[1] do + next if row == src[0] && col == src[1] + merges[[row, col]] = src end end end diff --git a/lib/roo/spreadsheet.rb b/lib/roo/spreadsheet.rb index cdc93f0..54063b6 100644 --- a/lib/roo/spreadsheet.rb +++ b/lib/roo/spreadsheet.rb @@ -24,8 +24,14 @@ module Roo options[:file_warning] = :ignore extension.tr('.', '').downcase.to_sym else - res = ::File.extname((path =~ /\A#{::URI::DEFAULT_PARSER.make_regexp}\z/) ? ::URI.parse(::URI.encode(path)).path : path) - res.tr('.', '').downcase.to_sym + parsed_path = + if path =~ /\A#{::URI::DEFAULT_PARSER.make_regexp}\z/ + # path is 7th match + Regexp.last_match[7] + else + path + end + ::File.extname(parsed_path).tr('.', '').downcase.to_sym end end end diff --git a/lib/roo/version.rb b/lib/roo/version.rb index 262847c..d2bb2bf 100644 --- a/lib/roo/version.rb +++ b/lib/roo/version.rb @@ -1,3 +1,3 @@ module Roo - VERSION = "2.8.3" + VERSION = "2.9.0" end |
