lib/write_xlsx/workbook.rb in write_xlsx-0.75.0 vs lib/write_xlsx/workbook.rb in write_xlsx-0.76.0

- old
+ new

@@ -7,14 +7,15 @@ require 'write_xlsx/formats' require 'write_xlsx/format' require 'write_xlsx/shape' require 'write_xlsx/utility' require 'write_xlsx/chart' +ruby_18 { require 'write_xlsx/zip_file_utils' } +ruby_19 { require 'zip' } require 'tmpdir' require 'tempfile' require 'digest/md5' -require 'zip' module Writexlsx OFFICE_URL = 'http://schemas.microsoft.com/office/' # :nodoc: @@ -871,11 +872,11 @@ # unique colors. The WriteXLSX gem will be extended at a later stage to # support the newer, semi-infinite, palette. # def set_custom_color(index, red = 0, green = 0, blue = 0) # Match a HTML #xxyyzz style parameter - if !red.nil? && red =~ /^#(\w\w)(\w\w)(\w\w)/ + if red =~ /^#(\w\w)(\w\w)(\w\w)/ red = $1.hex green = $2.hex blue = $3.hex end @@ -1162,11 +1163,11 @@ def write_mx_arch_id #:nodoc: @writer.empty_tag('mx:ArchID', ['Flags', 2]) end def write_defined_names #:nodoc: - return if @defined_names.nil? || @defined_names.empty? + return unless ptrue?(@defined_names) @writer.tag_elements('definedNames') do @defined_names.each { |defined_name| write_defined_name(defined_name) } end end @@ -1230,14 +1231,17 @@ # Free up the Packager object. packager = nil # Store the xlsx component files with the temp dir name removed. - # See https://github.com/randym/axlsx - Zip::OutputStream.open(@filename) do |zip| - write_parts(zip) - end + ruby_19 do + # See https://github.com/randym/axlsx + Zip::OutputStream.open(@filename) do |zip| + write_parts(zip) + end + end || + ruby_18 { ZipFileUtils.zip("#{@tempdir}", @filename) } IO.copy_stream(@filename, @fileobj) if @fileobj Writexlsx::Utility.delete_files(@tempdir) end @@ -1560,9 +1564,17 @@ # Convert the range formula to a sheet name and cell range. sheetname, *cells = get_chart_range(range) # Skip if we couldn't parse the formula. next unless sheetname + + # Handle non-contiguous ranges: (Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5). + # We don't try to parse the ranges. We just return an empty list. + if sheetname =~ /^\([^,]+,/ + chart.formula_data[id] = [] + seen_ranges[range] = [] + next + end # Raise if the name is unknown since it indicates a user error in # a chart series formula. unless worksheets[sheetname] raise "Unknown worksheet reference '#{sheetname} in range '#{range}' passed to add_series()\n"