diff options
| author | Randy Morgan <[email protected]> | 2012-11-08 08:10:36 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2012-11-08 08:10:36 +0900 |
| commit | d18170cd86810a6210905b7ab8ed104b6103d877 (patch) | |
| tree | 7ffabea376a31095025241ef818131be87943f77 | |
| parent | 887734c808438f30f419c5c26598e2f42ee01242 (diff) | |
| download | caxlsx-d18170cd86810a6210905b7ab8ed104b6103d877.tar.gz caxlsx-d18170cd86810a6210905b7ab8ed104b6103d877.zip | |
fixed cell text run validation for u and family
| -rwxr-xr-x | examples/example.rb | 9 | ||||
| -rw-r--r-- | lib/axlsx/util/validators.rb | 7 | ||||
| -rw-r--r-- | lib/axlsx/version.rb | 2 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 41 | ||||
| -rw-r--r-- | test/util/tc_validators.rb | 14 | ||||
| -rw-r--r-- | test/workbook/worksheet/tc_cell.rb | 16 |
6 files changed, 79 insertions, 10 deletions
diff --git a/examples/example.rb b/examples/example.rb index d85ba27f..54d467f3 100755 --- a/examples/example.rb +++ b/examples/example.rb @@ -88,7 +88,14 @@ if examples.include? :cell_style_override sheet.add_row ['col 1', 'col 2', 'col 3', 'col 4'], :sz => 16 sheet.add_row [1, 2, 3, "=SUM(A2:C2)"] - + sheet.add_row %w(u shadow sz b i strike outline) + sheet.rows.last.cells[0].u = :double + sheet.rows.last.cells[1].shadow = true + sheet.rows.last.cells[2].sz = 20 + sheet.rows.last.cells[3].b = true + sheet.rows.last.cells[4].i = true + sheet.rows.last.cells[5].strike = true + sheet.rows.last.cells[6].outline = 1 # You can also apply cell style overrides to a range of cells sheet["A1:D1"].each { |c| c.color = "FF0000" } sheet['A1:D2'].each { |c| c.style = Axlsx::STYLE_THIN_BORDER } diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb index 9c1ec741..55a49e72 100644 --- a/lib/axlsx/util/validators.rb +++ b/lib/axlsx/util/validators.rb @@ -140,7 +140,14 @@ module Axlsx def self.validate_page_orientation(v) RestrictionValidator.validate "page_orientation", [:default, :landscape, :portrait], v end + # Requires that the value is one of :none, :single, :double, :singleAccounting, :doubleAccounting + def self.validate_cell_u(v) + RestrictionValidator.validate "cell run style u", [:none, :single, :double, :singleAccounting, :doubleAccounting], v + end + def self.validate_family(v) + RestrictionValidator.validate "cell run style family", 1..5, v + end # Requires that the value is valid pattern type. # valid pattern types must be one of :none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown, # :darkUp, :darkGrid, :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, or :gray0625. diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb index a90ea6d7..fafa5118 100644 --- a/lib/axlsx/version.rb +++ b/lib/axlsx/version.rb @@ -1,5 +1,5 @@ module Axlsx # The current version - VERSION = "1.3.2" + VERSION = "1.3.3" end diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index 86e61d9d..439ac65a 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -112,16 +112,43 @@ module Axlsx def font_name=(v) set_run_style :validate_string, :font_name, v; end # The inline charset property for the cell + # As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following: + # 0  ANSI_CHARSET + # 1 DEFAULT_CHARSET + # 2 SYMBOL_CHARSET + # 77 MAC_CHARSET + # 128 SHIFTJIS_CHARSET + # 129  HANGUL_CHARSET + # 130  JOHAB_CHARSET + # 134  GB2312_CHARSET + # 136  CHINESEBIG5_CHARSET + # 161  GREEK_CHARSET + # 162  TURKISH_CHARSET + # 163  VIETNAMESE_CHARSET + # 177  HEBREW_CHARSET + # 178  ARABIC_CHARSET + # 186  BALTIC_CHARSET + # 204  RUSSIAN_CHARSET + # 222  THAI_CHARSET + # 238  EASTEUROPE_CHARSET + # 255  OEM_CHARSET # @return [String] attr_reader :charset # @see charset def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end # The inline family property for the cell - # @return [String] + # @return [Integer] + # 1 Roman + # 2 Swiss + # 3 Modern + # 4 Script + # 5 Decorative attr_reader :family # @see family - def family=(v) set_run_style :validate_string, :family, v; end + def family=(v) + set_run_style :validate_family, :family, v.to_i + end # The inline bold property for the cell # @return [Boolean] @@ -165,11 +192,17 @@ module Axlsx # @see extend def extend=(v) set_run_style :validate_boolean, :extend, v; end - # The inline underline property for the cell + # The inline underline property for the cell. + # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true # @return [Boolean] + # @return [String] + # @note true is for backwards compatability and is reassigned to :single attr_reader :u # @see u - def u=(v) set_run_style :validate_boolean, :u, v; end + def u=(v) + v = :single if (v == true || v == 1 || v == :true || v == 'true') + set_run_style :validate_cell_u, :u, v + end # The inline color property for the cell # @return [Color] diff --git a/test/util/tc_validators.rb b/test/util/tc_validators.rb index 1c3e173c..de896f3d 100644 --- a/test/util/tc_validators.rb +++ b/test/util/tc_validators.rb @@ -159,6 +159,20 @@ class TestValidators < Test::Unit::TestCase assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 } end + def test_validate_family + assert_raise(ArgumentError) { Axlsx.validate_family 0 } + (1..5).each do |item| + assert_nothing_raised { Axlsx.validate_family item } + end + end + + def test_validate_u + assert_raise(ArgumentError) { Axlsx.validate_cell_u :hoge } + [:none, :single, :double, :singleAccounting, :doubleAccounting].each do |sym| + assert_nothing_raised { Axlsx.validate_cell_u sym } + end + end + def test_range_validation # exclusive assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) } diff --git a/test/workbook/worksheet/tc_cell.rb b/test/workbook/worksheet/tc_cell.rb index 0b332d86..b237077c 100644 --- a/test/workbook/worksheet/tc_cell.rb +++ b/test/workbook/worksheet/tc_cell.rb @@ -162,9 +162,12 @@ class TestCell < Test::Unit::TestCase end def test_u + @c.type = :string assert_raise(ArgumentError) { @c.u = -1.1 } - assert_nothing_raised { @c.u = false } - assert_equal(@c.u, false) + assert_nothing_raised { @c.u = :single } + assert_equal(@c.u, :single) + doc = Nokogiri::XML(@c.to_xml_string(1,1)) + assert(doc.xpath('//u[@val="single"]')) end def test_i @@ -187,8 +190,8 @@ class TestCell < Test::Unit::TestCase def test_family assert_raise(ArgumentError) { @c.family = -1.1 } - assert_nothing_raised { @c.family = "Who knows!" } - assert_equal(@c.family, "Who knows!") + assert_nothing_raised { @c.family = 5 } + assert_equal(@c.family, 5) end def test_b @@ -251,6 +254,8 @@ class TestCell < Test::Unit::TestCase end def test_to_xml_string_with_run + # Actually quite a number of similar run styles + # but the processing should be the same @c.b = true @c.type = :string @c.value = "a" @@ -259,6 +264,7 @@ class TestCell < Test::Unit::TestCase c_xml = Nokogiri::XML(@c.to_xml_string(1,1)) assert(c_xml.xpath("//b")) end + def test_to_xml_string_formula p = Axlsx::Package.new ws = p.workbook.add_worksheet do |sheet| @@ -285,6 +291,7 @@ class TestCell < Test::Unit::TestCase sz = @c.send(:font_size) assert_equal(sz, 52) end + def test_cell_with_sz @c.sz = 25 @@ -293,6 +300,7 @@ class TestCell < Test::Unit::TestCase 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)"] + @ws.rows.last.cells[5].u = true schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD)) doc = Nokogiri::XML(@ws.to_xml_string) errors = [] |
