diff options
| -rw-r--r-- | .travis.yml | 43 | ||||
| -rw-r--r-- | Gemfile | 9 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | appveyor.yml | 23 | ||||
| -rw-r--r-- | lib/axlsx/drawing/pic.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/drawing/scaling.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/drawing/view_3D.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/util/simple_typed_list.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/util/validators.rb | 10 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 6 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell_serializer.rb | 18 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/merged_cells.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/row.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 2 | ||||
| -rw-r--r-- | test/stylesheet/tc_styles.rb | 4 | ||||
| -rw-r--r-- | test/tc_axlsx.rb | 10 | ||||
| -rw-r--r-- | test/util/tc_simple_typed_list.rb | 2 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 37 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_row.rb | 5 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_worksheet.rb | 9 |
20 files changed, 150 insertions, 51 deletions
diff --git a/.travis.yml b/.travis.yml index 8371fef4..89c56f22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,28 +1,41 @@ language: ruby -sudo: false +sudo: required +dist: trusty +group: beta cache: bundler bundler_args: --without profile -env: - - JRUBY_OPTS="-Xcli.debug=true --debug" + notifications: irc: "irc.freenode.org#axlsx" email: recipients: on_success: always -rvm: - - 1.9.2 - - 1.9.3 - - 2.0 - - 2.1 - - 2.2 - - rbx - - jruby-19mode - - jruby-9.0.0.0 - - ruby-head - - jruby-head + matrix: + include: + - rvm: 1.9.3 + - rvm: 2.0 + - rvm: 2.1 + - rvm: 2.2 + - rvm: 2.3.1 + - rvm: rbx-3 + - rvm: jruby-19mode + env: JRUBY_OPTS="-Xcli.debug=true --debug" + - rvm: jruby-9.1.5.0 + env: JRUBY_OPTS="-Xcli.debug=true --debug" + - rvm: ruby-head + - rvm: jruby-head + env: JRUBY_OPTS="-Xcli.debug=true --debug" allow_failures: + - rvm: rbx-3 - rvm: ruby-head - - rvm: jruby-9.0.0.0 + - rvm: jruby-9.1.5.0 - rvm: jruby-head + +# https://github.com/jruby/jruby/wiki/FAQs#why-is-jruby-so-slow-to-install-via-rvm +# https://docs.travis-ci.com/user/installing-dependencies#Installing-Packages-with-the-APT-Addon +addons: + apt: + packages: + - haveged @@ -2,7 +2,12 @@ source 'https://rubygems.org' gemspec group :test do - gem 'rake', '>= 0.8.7' + if RUBY_VERSION.to_i < 2 + gem 'rake', '>= 0.8.7', '< 11' + gem 'json', '< 2' + else + gem 'rake' + end gem 'simplecov' gem 'test-unit' end @@ -15,5 +20,5 @@ platforms :rbx do gem 'rubysl' gem 'rubysl-test-unit' gem 'racc' - gem 'rubinius-coverage', '~> 2.0' + gem 'rubinius-coverage', '~> 2.0' end @@ -1,6 +1,6 @@ Axlsx: Office Open XML Spreadsheet Generation ==================================== -[](http://travis-ci.org/randym/axlsx/) +[](http://travis-ci.org/randym/axlsx/) If you are using axlsx for commercial purposes, or just want to show your appreciation for the gem, please don't hesitate to make a donation. diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..0d7d5fce --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,23 @@ +version: 2.1.0.{build}-{branch} + +environment: + matrix: + - RUBY_VERSION: 23 + - RUBY_VERSION: 22 + - RUBY_VERSION: 21 + - RUBY_VERSION: 200 + - RUBY_VERSION: 193 + +install: + - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH% + - bundle install + +build: off + +before_test: + - ruby -v + - gem -v + - bundle -v + +test_script: + - bundle exec rake diff --git a/lib/axlsx/drawing/pic.rb b/lib/axlsx/drawing/pic.rb index 275a6d06..5a418df0 100644 --- a/lib/axlsx/drawing/pic.rb +++ b/lib/axlsx/drawing/pic.rb @@ -53,7 +53,7 @@ module Axlsx attr_reader :hyperlink # Picture opacity - # @return [Fixnum] + # @return [Integer] attr_reader :opacity # sets or updates a hyperlink for this image. diff --git a/lib/axlsx/drawing/scaling.rb b/lib/axlsx/drawing/scaling.rb index fcbea9f8..4c9d6888 100644 --- a/lib/axlsx/drawing/scaling.rb +++ b/lib/axlsx/drawing/scaling.rb @@ -6,7 +6,7 @@ module Axlsx include Axlsx::OptionsParser # creates a new Scaling object - # @option options [Integer, Fixnum] logBase + # @option options [Integer] logBase # @option options [Symbol] orientation # @option options [Float] max # @option options [Float] min @@ -35,7 +35,7 @@ module Axlsx attr_reader :min # @see logBase - def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer, Fixnum], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end + def logBase=(v) DataTypeValidator.validate "Scaling.logBase", [Integer], v, lambda { |arg| arg >= 2 && arg <= 1000}; @logBase = v; end # @see orientation def orientation=(v) RestrictionValidator.validate "Scaling.orientation", [:minMax, :maxMin], v; @orientation = v; end # @see max diff --git a/lib/axlsx/drawing/view_3D.rb b/lib/axlsx/drawing/view_3D.rb index 9c320b4a..55bbc6c3 100644 --- a/lib/axlsx/drawing/view_3D.rb +++ b/lib/axlsx/drawing/view_3D.rb @@ -86,12 +86,12 @@ module Axlsx alias :rAngAx= :r_ang_ax= # @see perspective - def perspective=(v) + def perspective=(v) RangeValidator.validate "View3D.perspective", 0, 240, v @perspective = v end - # DataTypeValidator.validate "#{self.class}.perspective", [Integer, Fixnum], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end + # DataTypeValidator.validate "#{self.class}.perspective", [Integer], v, lambda {|arg| arg >= 0 && arg <= 240 }; @perspective = v; end # Serializes the object # @param [String] str diff --git a/lib/axlsx/util/simple_typed_list.rb b/lib/axlsx/util/simple_typed_list.rb index 95f5b3f2..77bed775 100644 --- a/lib/axlsx/util/simple_typed_list.rb +++ b/lib/axlsx/util/simple_typed_list.rb @@ -147,7 +147,7 @@ module Axlsx # determines if the index is protected # @param [Integer] index def protected? index - return false unless locked_at.is_a? Fixnum + return false unless locked_at.is_a? Integer index < locked_at end diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 9c6f34aa..2b4afd8d 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -80,16 +80,16 @@ module Axlsx end UINT_VALIDATOR = lambda { |arg| arg.respond_to?(:>=) && arg >= 0 } - - # Requires that the value is a Fixnum or Integer and is greater or equal to 0 + + # Requires that the value is a Integer and is greater or equal to 0 # @param [Any] v The value validated - # @raise [ArgumentError] raised if the value is not a Fixnum or Integer value greater or equal to 0 + # @raise [ArgumentError] raised if the value is not a Integer value greater or equal to 0 # @return [Boolean] true if the data is valid def self.validate_unsigned_int(v) DataTypeValidator.validate(:unsigned_int, Integer, v, UINT_VALIDATOR) end - # Requires that the value is a Fixnum Integer or Float and is greater or equal to 0 + # Requires that the value is a Integer or Float and is greater or equal to 0 # @param [Any] v The value validated # @raise [ArgumentError] raised if the value is not a Fixnun, Integer, Float value greater or equal to 0 # @return [Boolean] true if the data is valid @@ -104,7 +104,7 @@ module Axlsx end # Requires that the value is a form that can be evaluated as a boolean in an xml document. - # The value must be an instance of Fixnum, String, Integer, Symbol, TrueClass or FalseClass and + # The value must be an instance of String, Integer, Symbol, TrueClass or FalseClass and # it must be one of 0, 1, "true", "false", :true, :false, true, false, "0", or "1" # @param [Any] v The value validated def self.validate_boolean(v) diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index cd832f7b..777b7812 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -66,7 +66,7 @@ module Axlsx :vertAlign, :sz, :color, :scheme].freeze CELL_TYPES = [:date, :time, :float, :integer, :richtext, - :string, :boolean, :iso_8601].freeze + :string, :boolean, :iso_8601, :text].freeze # The index of the cellXfs item to be applied to this cell. # @return [Integer] @@ -123,7 +123,7 @@ module Axlsx # Indicates if the cell is good for shared string table def plain_string? - type == :string && # String typed + (type == :string || type == :text) && # String typed !is_text_run? && # No inline styles [email protected]? && # Not nil [email protected]? && # Not empty @@ -368,7 +368,7 @@ module Axlsx # TODO find a better way to do this as it accounts for 30% of # processing time in benchmarking... def clean_value - if type == :string && !Axlsx::trust_input + if (type == :string || type == :text) && !Axlsx::trust_input Axlsx::sanitize(::CGI.escapeHTML(@value.to_s)) else @value.to_s diff --git a/lib/axlsx/workbook/worksheet/cell_serializer.rb b/lib/axlsx/workbook/worksheet/cell_serializer.rb index 9a9f9465..76a3c386 100644 --- a/lib/axlsx/workbook/worksheet/cell_serializer.rb +++ b/lib/axlsx/workbook/worksheet/cell_serializer.rb @@ -14,7 +14,7 @@ module Axlsx method = cell.type self.send(method, cell, str) str << '</c>' - end + end # builds an xml text run based on this cells attributes. # @param [String] str The string instance this run will be concated to. @@ -22,7 +22,7 @@ module Axlsx def run_xml_string(cell, str = '') if cell.is_text_run? valid = RichTextRun::INLINE_STYLES - [:value, :type] - data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }] + data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }] data = data.select { |key, value| valid.include?(key) && !value.nil? } RichText.new(cell.value.to_s, data).to_xml_string(str) elsif cell.contains_rich_text? @@ -124,7 +124,7 @@ module Axlsx inline_string_serialization cell, str end end - + # Serializes cells that are of the type richtext # @param [Cell] cell The cell that is being serialized # @param [String] str The string the serialized content will be appended to. @@ -137,6 +137,18 @@ module Axlsx end end + # Serializes cells that are of the type text + # @param [Cell] cell The cell that is being serialized + # @param [String] str The string the serialized content will be appended to. + # @return [String] + def text(cell, str) + if cell.ssti.nil? + inline_string_serialization cell, str + else + value_serialization 's', cell.ssti, str + end + end + private def numeric(cell, str = '') diff --git a/lib/axlsx/workbook/worksheet/merged_cells.rb b/lib/axlsx/workbook/worksheet/merged_cells.rb index 6ea1edc9..67753bd3 100644 --- a/lib/axlsx/workbook/worksheet/merged_cells.rb +++ b/lib/axlsx/workbook/worksheet/merged_cells.rb @@ -19,6 +19,8 @@ module Axlsx cells elsif cells.is_a?(Array) Axlsx::cell_range(cells, false) + elsif cells.is_a?(Row) + Axlsx::cell_range(cells, false) end end diff --git a/lib/axlsx/workbook/worksheet/row.rb b/lib/axlsx/workbook/worksheet/row.rb index 078e281f..b394279f 100644 --- a/lib/axlsx/workbook/worksheet/row.rb +++ b/lib/axlsx/workbook/worksheet/row.rb @@ -103,6 +103,13 @@ module Axlsx c end + # sets the color for every cell in this row + def color=(color) + each_with_index do | cell, index | + cell.color = color.is_a?(Array) ? color[index] : color + end + end + # sets the style for every cell in this row def style=(style) each_with_index do | cell, index | diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 26be8bd8..031a081f 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -555,7 +555,7 @@ module Axlsx # @example This would set the first and third column widhts but leave the second column in autofit state. # ws.column_widths 7.2, nil, 3 # @note For updating only a single column it is probably easier to just set the width of the ws.column_info[col_index].width directly - # @param [Integer|Float|Fixnum|nil] widths + # @param [Integer|Float|nil] widths def column_widths(*widths) widths.each_with_index do |value, index| next if value == nil diff --git a/test/stylesheet/tc_styles.rb b/test/stylesheet/tc_styles.rb index 98c8e3ef..eb1680ad 100644 --- a/test/stylesheet/tc_styles.rb +++ b/test/stylesheet/tc_styles.rb @@ -133,7 +133,7 @@ class TestStyles < Test::Unit::TestCase :font_name => "woot font" } assert_equal(@styles.parse_font_options {}, nil, "noop if no font keys are set") - assert_equal(@styles.parse_font_options(:b=>1).class, Fixnum, "return index of font if not :dxf type") + assert(@styles.parse_font_options(:b=>1).is_a?(Integer), "return index of font if not :dxf type") assert_equal(@styles.parse_font_options(:b=>1, :type => :dxf).class, Axlsx::Font, "return font object if :dxf type") f = @styles.parse_font_options(options.merge(:type => :dxf)) @@ -147,7 +147,7 @@ class TestStyles < Test::Unit::TestCase def test_parse_fill_options assert_equal(@styles.parse_fill_options {}, nil, "noop if no fill keys are set") - assert_equal(@styles.parse_fill_options(:bg_color => "DE").class, Fixnum, "return index of fill if not :dxf type") + assert(@styles.parse_fill_options(:bg_color => "DE").is_a?(Integer), "return index of fill if not :dxf type") assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type") f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf) assert(f.fill_type.bgColor.rgb == "FFDEDEDE") diff --git a/test/tc_axlsx.rb b/test/tc_axlsx.rb index 1be9166c..99832f63 100644 --- a/test/tc_axlsx.rb +++ b/test/tc_axlsx.rb @@ -45,6 +45,16 @@ class TestAxlsx < Test::Unit::TestCase assert_equal(Axlsx.cell_range([c2, c1], true), "'Sheet <''>" 1'!$A$1:$B$1") end + def test_cell_range_row + p = Axlsx::Package.new + ws = p.workbook.add_worksheet + row = ws.add_row + row.add_cell + row.add_cell + row.add_cell + assert_equal("A1:C1", Axlsx.cell_range(row, false)) + end + def test_name_to_indices setup_wide @wide_test_points.each do |key, value| diff --git a/test/util/tc_simple_typed_list.rb b/test/util/tc_simple_typed_list.rb index 1596ac13..72bd6246 100644 --- a/test/util/tc_simple_typed_list.rb +++ b/test/util/tc_simple_typed_list.rb @@ -1,7 +1,7 @@ require 'tc_helper.rb' class TestSimpleTypedList < Test::Unit::TestCase def setup - @list = Axlsx::SimpleTypedList.new Fixnum + @list = Axlsx::SimpleTypedList.new Integer end def teardown diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 5ae2a51f..f61a254f 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -238,7 +238,7 @@ class TestCell < Test::Unit::TestCase @c.merge @row.cells.last assert_equal(@c.row.worksheet.send(:merged_cells).last, "A1:C1") end - + def test_reverse_merge_with_cell @c.row.add_cell 2 @c.row.add_cell 3 @@ -284,7 +284,7 @@ class TestCell < Test::Unit::TestCase c_xml = Nokogiri::XML(@c.to_xml_string(1,1)) assert_equal(c_xml.xpath("/c[@s=1]").size, 1) end - + def test_to_xml_string_with_run # Actually quite a number of similar run styles # but the processing should be the same @@ -294,7 +294,7 @@ class TestCell < Test::Unit::TestCase @c.font_name = 'arial' @c.color = 'FF0000' c_xml = Nokogiri::XML(@c.to_xml_string(1,1)) - assert(c_xml.xpath("//b")) + assert(c_xml.xpath("//b").any?) end def test_to_xml_string_formula @@ -303,8 +303,8 @@ class TestCell < Test::Unit::TestCase sheet.add_row ["=IF(2+2=4,4,5)"] end doc = Nokogiri::XML(ws.to_xml_string) - assert(doc.xpath("//f[@text()='IF(2+2=4,4,5)']")) - + doc.remove_namespaces! + assert(doc.xpath("//f[text()='IF(2+2=4,4,5)']").any?) end def test_to_xml_string_array_formula @@ -314,9 +314,24 @@ class TestCell < Test::Unit::TestCase end doc = Nokogiri::XML(ws.to_xml_string) doc.remove_namespaces! - assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']")) - assert(doc.xpath("//f[@t='array']")) - assert(doc.xpath("//f[@ref='A1']")) + assert(doc.xpath("//f[text()='SUM(C2:C11*D2:D11)']").any?) + assert(doc.xpath("//f[@t='array']").any?) + assert(doc.xpath("//f[@ref='A1']").any?) + end + + def test_to_xml_string_text_formula + p = Axlsx::Package.new + ws = p.workbook.add_worksheet do |sheet| + sheet.add_row ["=1+1", "-1+1"], type: :text + end + doc = Nokogiri::XML(ws.to_xml_string) + doc.remove_namespaces! + + assert(doc.xpath("//f[text()='1+1']").empty?) + assert(doc.xpath("//t[text()='=1+1']").any?) + + assert(doc.xpath("//f[text()='1+1']").empty?) + assert(doc.xpath("//t[text()='-1+1']").any?) end def test_font_size_with_custom_style_and_no_sz @@ -335,17 +350,17 @@ class TestCell < Test::Unit::TestCase sz = @c.send(:font_size) assert_equal(sz, 52) end - + def test_cell_with_sz @c.sz = 25 assert_equal(25, @c.send(:font_size)) end - + def test_to_xml # TODO This could use some much more stringent testing related to the xml content generated! @ws.add_row [Time.now, Date.today, true, 1, 1.0, "text", "=sum(A1:A2)", "2013-01-13T13:31:25.123"] @ws.rows.last.cells[5].u = true - + schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(@ws.to_xml_string) errors = [] diff --git a/test/workbook/worksheet/tc_row.rb b/test/workbook/worksheet/tc_row.rb index 808e0138..43e7d23f 100644 --- a/test/workbook/worksheet/tc_row.rb +++ b/test/workbook/worksheet/tc_row.rb @@ -27,6 +27,11 @@ class TestRow < Test::Unit::TestCase r.cells.each { |c| assert_equal(c.style,1) } end + def test_color + r = @ws.add_row([1,2,3,4,5]) + r.color = "FF00FF00" + r.cells.each { |c| assert_equal(c.color.rgb, "FF00FF00") } + end def test_index assert_equal(@row.row_index, @row.worksheet.rows.index(@row)) diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb index f8bd69ae..166850e5 100644 --- a/test/workbook/worksheet/tc_worksheet.rb +++ b/test/workbook/worksheet/tc_worksheet.rb @@ -323,6 +323,13 @@ class TestWorksheet < Test::Unit::TestCase assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="E1:F1"]').size, 1) end + def test_to_xml_string_merge_cells_row + row = @ws.add_row [1, "two"] + @ws.merge_cells row + doc = Nokogiri::XML(@ws.to_xml_string) + assert_equal(doc.xpath('//xmlns:worksheet/xmlns:mergeCells/xmlns:mergeCell[@ref="A1:B1"]').size, 1) + end + def test_to_xml_string_row_breaks @ws.add_page_break("A1") doc = Nokogiri::XML(@ws.to_xml_string) @@ -476,7 +483,7 @@ class TestWorksheet < Test::Unit::TestCase @ws.column_widths nil, 0.5 assert_equal(@ws.column_info[1].width, 0.5, 'eat my width') assert_raise(ArgumentError, 'only accept unsigned ints') { @ws.column_widths 2, 7, -1 } - assert_raise(ArgumentError, 'only accept Integer, Float or Fixnum') { @ws.column_widths 2, 7, "-1" } + assert_raise(ArgumentError, 'only accept Integer or Float') { @ws.column_widths 2, 7, "-1" } end def test_protect_range |
