axlsx 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/README.md +18 -7
  2. data/examples/conditional_formatting/example_conditional_formatting.rb +72 -0
  3. data/examples/conditional_formatting/getting_barred.rb +37 -0
  4. data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
  5. data/examples/conditional_formatting/scaled_colors.rb +39 -0
  6. data/examples/conditional_formatting/stop_and_go.rb +37 -0
  7. data/examples/example.rb +6 -2
  8. data/examples/{real_example.rb → skydrive/real_example.rb} +0 -0
  9. data/lib/axlsx.rb +1 -1
  10. data/lib/axlsx/drawing/axis.rb +16 -0
  11. data/lib/axlsx/stylesheet/dxf.rb +79 -0
  12. data/lib/axlsx/stylesheet/font.rb +2 -1
  13. data/lib/axlsx/stylesheet/styles.rb +141 -50
  14. data/lib/axlsx/stylesheet/xf.rb +2 -0
  15. data/lib/axlsx/util/constants.rb +8 -0
  16. data/lib/axlsx/util/validators.rb +44 -0
  17. data/lib/axlsx/version.rb +1 -1
  18. data/lib/axlsx/workbook/workbook.rb +6 -0
  19. data/lib/axlsx/workbook/worksheet/cfvo.rb +62 -0
  20. data/lib/axlsx/workbook/worksheet/cfvo.rb~ +0 -0
  21. data/lib/axlsx/workbook/worksheet/color_scale.rb +76 -0
  22. data/lib/axlsx/workbook/worksheet/color_scale.rb~ +46 -0
  23. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
  24. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +216 -0
  25. data/lib/axlsx/workbook/worksheet/data_bar.rb +97 -0
  26. data/lib/axlsx/workbook/worksheet/data_bar.rb~ +0 -0
  27. data/lib/axlsx/workbook/worksheet/icon_set.rb +83 -0
  28. data/lib/axlsx/workbook/worksheet/icon_set.rb~ +95 -0
  29. data/lib/axlsx/workbook/worksheet/row.rb +2 -0
  30. data/lib/axlsx/workbook/worksheet/worksheet.rb +25 -3
  31. data/test/drawing/tc_axis.rb +8 -0
  32. data/test/stylesheet/tc_dxf.rb +81 -0
  33. data/test/stylesheet/tc_styles.rb +148 -2
  34. data/test/workbook/worksheet/tc_cfvo.rb +31 -0
  35. data/test/workbook/worksheet/tc_cfvo.rb~ +20 -0
  36. data/test/workbook/worksheet/tc_color_scale.rb +29 -0
  37. data/test/workbook/worksheet/tc_color_scale.rb~ +0 -0
  38. data/test/workbook/worksheet/tc_conditional_formatting.rb +173 -0
  39. data/test/workbook/worksheet/tc_data_bar.rb +39 -0
  40. data/test/workbook/worksheet/tc_data_bar.rb~ +0 -0
  41. data/test/workbook/worksheet/tc_icon_set.rb +45 -0
  42. data/test/workbook/worksheet/tc_icon_set.rb~ +0 -0
  43. data/test/workbook/worksheet/tc_row.rb +9 -2
  44. metadata +45 -27
  45. data/examples/axlsx.xlsx +0 -0
  46. data/examples/example.xlsx +0 -0
  47. data/examples/example_streamed.xlsx +0 -0
  48. data/examples/no-use_autowidth.xlsx +0 -0
  49. data/examples/shared_strings_example.xlsx +0 -0
  50. data/lib/axlsx/util/doc/_index.html +0 -84
  51. data/lib/axlsx/util/doc/class_list.html +0 -47
  52. data/lib/axlsx/util/doc/css/common.css +0 -1
  53. data/lib/axlsx/util/doc/css/full_list.css +0 -55
  54. data/lib/axlsx/util/doc/css/style.css +0 -322
  55. data/lib/axlsx/util/doc/file_list.html +0 -46
  56. data/lib/axlsx/util/doc/frames.html +0 -13
  57. data/lib/axlsx/util/doc/index.html +0 -84
  58. data/lib/axlsx/util/doc/js/app.js +0 -205
  59. data/lib/axlsx/util/doc/js/full_list.js +0 -173
  60. data/lib/axlsx/util/doc/js/jquery.js +0 -16
  61. data/lib/axlsx/util/doc/method_list.html +0 -46
  62. data/lib/axlsx/util/doc/top-level-namespace.html +0 -95
@@ -0,0 +1,95 @@
1
+ module Axlsx
2
+ # Conditional Format Rule data bar object
3
+ # Describes a data bar conditional formatting rule.
4
+
5
+ # @note The recommended way to manage these rules is via Worksheet#add_conditional_formatting
6
+ # @see Worksheet#add_conditional_formatting
7
+ # @see ConditionalFormattingRule#initialize
8
+ class DataBar
9
+ CHILD_ELEMENTS = [:value_objects]
10
+
11
+ # minLength attribute
12
+ # The minimum length of the data bar, as a percentage of the cell width.
13
+ # The default value is 10
14
+ # @return [Integer]
15
+ attr_reader :minLength
16
+
17
+ # maxLength attribute
18
+ # The maximum length of the data bar, as a percentage of the cell width.
19
+ # The default value is 90
20
+ # @return [Integer]
21
+ attr_reader :maxLength
22
+
23
+ # maxLength attribute
24
+ # Indicates whether to show the values of the cells on which this data bar is applied.
25
+ # The default value is true
26
+ # @return [Boolean]
27
+ attr_reader :showValue
28
+
29
+ # A simple typed list of cfvos
30
+ # @return [SimpleTypedList]
31
+ # @see Cfvo
32
+ attr_reader :value_objects
33
+
34
+ # color
35
+ # the color object used in the data bar formatting
36
+ # @return [Color]
37
+ def color
38
+ @color ||= Color.new :rgb => "FF0000FF"
39
+ end
40
+
41
+ # Creates a new data bar conditional formatting object
42
+ # @option options [Integer] minLength
43
+ # @option options [Integer] maxLength
44
+ # @option options [Boolean] showValue
45
+ # @option options [String] color - the rbg value used to color the bars
46
+ def initialize(options = {})
47
+ @minLength = 10
48
+ @maxLength = 90
49
+ @showValue = true
50
+ initialize_value_objects
51
+ options.each do |o|
52
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
53
+ end
54
+ yield self if block_given?
55
+ end
56
+
57
+ # @see minLength
58
+ def minLength=(v); Axlsx.validate_unsigned_int(v); @minLength = v end
59
+ # @see maxLength
60
+ def maxLength=(v); Axlsx.validate_unsigned_int(v); @maxLength = v end
61
+
62
+ # @see showValue
63
+ def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
64
+
65
+ # Sets the color for the data bars.
66
+ # @param [Color|String] The color object, or rgb string value to apply
67
+ def color=(v)
68
+ @color = v if v.is_a? Color
69
+ self.color.rgb = v if v.is_a? String
70
+ @color
71
+ end
72
+
73
+ # Serialize this object to an xml string
74
+ # @param [String] str
75
+ # @return [String]
76
+ def to_xml_string(str="")
77
+ str << '<dataBar '
78
+ str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
79
+ str << '>'
80
+ @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
81
+ self.color.to_xml_string(str)
82
+ str << '</dataBar>'
83
+ end
84
+
85
+ private
86
+
87
+ # Initalize the simple typed list of value objects
88
+ # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
89
+ def initialize_value_objects
90
+ @value_objects = SimpleTypedList.new Cfvo
91
+ @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
92
+ @value_objects.lock
93
+ end
94
+ end
95
+ end
@@ -132,6 +132,8 @@ module Axlsx
132
132
  cell_type = types.is_a?(Array)? types[index] : types
133
133
  options[:type] = cell_type if cell_type
134
134
  Cell.new(self, value, options)
135
+ options.delete(:style)
136
+ options.delete(:type)
135
137
  end
136
138
  end
137
139
  end
@@ -101,6 +101,7 @@ module Axlsx
101
101
  @drawing = @page_margins = @auto_filter = nil
102
102
  @merged_cells = []
103
103
  @auto_fit_data = []
104
+ @conditional_formattings = []
104
105
 
105
106
  @selected = false
106
107
  @show_gridlines = true
@@ -123,6 +124,22 @@ module Axlsx
123
124
  rows.flatten
124
125
  end
125
126
 
127
+ # Add conditional formatting to this worksheet.
128
+ #
129
+ # @param [String] cells The range to apply the formatting to
130
+ # @param [Array|Hash] rules An array of hashes (or just one) to create Conditional formatting rules from.
131
+ # @example This would format column A whenever it is FALSE.
132
+ # # for a longer example, see examples/example_conditional_formatting.rb (link below)
133
+ # worksheet.add_conditional_formatting( "A1:A1048576", { :type => :cellIs, :operator => :equal, :formula => "FALSE", :dxfId => 1, :priority => 1 }
134
+ #
135
+ # @see ConditionalFormattingRule#initialize
136
+ # @see file:examples/example_conditional_formatting.rb
137
+ def add_conditional_formatting(cells, rules)
138
+ cf = ConditionalFormatting.new( :sqref => cells )
139
+ cf.add_rules rules
140
+ @conditional_formattings << cf
141
+ end
142
+
126
143
  # Creates merge information for this worksheet.
127
144
  # Cells can be merged by calling the merge_cells method on a worksheet.
128
145
  # @example This would merge the three cells C1..E1 #
@@ -411,6 +428,9 @@ module Axlsx
411
428
  unless @tables.empty?
412
429
  str.concat "<tableParts count='%s'>%s</tableParts>" % [@tables.size, @tables.reduce('') { |memo, obj| memo += "<tablePart r:id='%s'/>" % obj.rId }]
413
430
  end
431
+ @conditional_formattings.each do |cf|
432
+ str.concat cf.to_xml_string
433
+ end
414
434
  str + '</worksheet>'
415
435
  end
416
436
 
@@ -476,10 +496,12 @@ module Axlsx
476
496
  end
477
497
 
478
498
 
479
- # If you *REALLY* want to know what this does, check the spec for how column width is specified.
499
+ # This is still not perfect...
500
+ # - scaling is not linear as font sizes increst
501
+ # - different fonts have different mdw and char widths
480
502
  def calculate_width(text, sz)
481
- mdw = 1.78 #magic numbers ftw! This is the widest width of 0..9 in the "standard" font (arial@10px)
482
- font_scale = sz/10.0
503
+ mdw = 1.78 #This is the widest width of 0..9 in arial@10px)
504
+ font_scale = (sz/10.0).to_f
483
505
  ((text.count(Worksheet.thin_chars) * mdw + 5) / mdw * 256) / 256.0 * font_scale
484
506
  end
485
507
  end
@@ -21,6 +21,14 @@ class TestAxis < Test::Unit::TestCase
21
21
  assert_nothing_raised("accepts valid axis position") { @axis.axPos = :r }
22
22
  end
23
23
 
24
+ def test_label_rotation
25
+ assert_raise(ArgumentError, "requires valid angle") { @axis.label_rotation = :nowhere }
26
+ assert_raise(ArgumentError, "requires valid angle") { @axis.label_rotation = 91 }
27
+ assert_raise(ArgumentError, "requires valid angle") { @axis.label_rotation = -91 }
28
+ assert_nothing_raised("accepts valid angle") { @axis.label_rotation = 45 }
29
+ assert_equal(@axis.label_rotation, 45 * 60000)
30
+ end
31
+
24
32
  def test_tick_label_position
25
33
  assert_raise(ArgumentError, "requires valid tick label position") { @axis.tickLblPos = :nowhere }
26
34
  assert_nothing_raised("accepts valid tick label position") { @axis.tickLblPos = :high }
@@ -0,0 +1,81 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestDxf < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @item = Axlsx::Dxf.new
7
+ @styles = Axlsx::Styles.new
8
+ end
9
+
10
+ def teardown
11
+ end
12
+
13
+ def test_initialiation
14
+ assert_equal(@item.alignment, nil)
15
+ assert_equal(@item.protection, nil)
16
+ assert_equal(@item.numFmt, nil)
17
+ assert_equal(@item.font, nil)
18
+ assert_equal(@item.fill, nil)
19
+ assert_equal(@item.border, nil)
20
+ end
21
+
22
+ def test_alignment
23
+ assert_raise(ArgumentError) { @item.alignment = -1.1 }
24
+ assert_nothing_raised { @item.alignment = Axlsx::CellAlignment.new }
25
+ assert(@item.alignment.is_a?(Axlsx::CellAlignment))
26
+ end
27
+
28
+ def test_protection
29
+ assert_raise(ArgumentError) { @item.protection = -1.1 }
30
+ assert_nothing_raised { @item.protection = Axlsx::CellProtection.new }
31
+ assert(@item.protection.is_a?(Axlsx::CellProtection))
32
+ end
33
+
34
+ def test_numFmt
35
+ assert_raise(ArgumentError) { @item.numFmt = 1 }
36
+ assert_nothing_raised { @item.numFmt = Axlsx::NumFmt.new }
37
+ assert @item.numFmt.is_a? Axlsx::NumFmt
38
+ end
39
+
40
+ def test_fill
41
+ assert_raise(ArgumentError) { @item.fill = 1 }
42
+ assert_nothing_raised { @item.fill = Axlsx::Fill.new(Axlsx::PatternFill.new(:patternType =>:solid, :fgColor=> Axlsx::Color.new(:rgb => "FF000000"))) }
43
+ assert @item.fill.is_a? Axlsx::Fill
44
+ end
45
+
46
+ def test_font
47
+ assert_raise(ArgumentError) { @item.font = 1 }
48
+ assert_nothing_raised { @item.font = Axlsx::Font.new }
49
+ assert @item.font.is_a? Axlsx::Font
50
+ end
51
+
52
+ def test_border
53
+ assert_raise(ArgumentError) { @item.border = 1 }
54
+ assert_nothing_raised { @item.border = Axlsx::Border.new }
55
+ assert @item.border.is_a? Axlsx::Border
56
+ end
57
+
58
+ def test_to_xml
59
+ @item.border = Axlsx::Border.new
60
+ doc = Nokogiri::XML.parse(@item.to_xml_string)
61
+ assert_equal(1, doc.xpath(".//dxf//border").size)
62
+ assert_equal(0, doc.xpath(".//dxf//font").size)
63
+ end
64
+
65
+ def test_many_options_xml
66
+ @item.border = Axlsx::Border.new
67
+ @item.alignment = Axlsx::CellAlignment.new
68
+ @item.fill = Axlsx::Fill.new(Axlsx::PatternFill.new(:patternType =>:solid, :fgColor=> Axlsx::Color.new(:rgb => "FF000000")))
69
+ @item.font = Axlsx::Font.new
70
+ @item.protection = Axlsx::CellProtection.new
71
+ @item.numFmt = Axlsx::NumFmt.new
72
+
73
+ doc = Nokogiri::XML.parse(@item.to_xml_string)
74
+ assert_equal(1, doc.xpath(".//dxf//fill//patternFill[@patternType='solid']//fgColor[@rgb='FF000000']").size)
75
+ assert_equal(1, doc.xpath(".//dxf//font").size)
76
+ assert_equal(1, doc.xpath(".//dxf//protection").size)
77
+ assert_equal(1, doc.xpath(".//dxf//numFmt[@numFmtId='0'][@formatCode='']").size)
78
+ assert_equal(1, doc.xpath(".//dxf//alignment").size)
79
+ assert_equal(1, doc.xpath(".//dxf//border").size)
80
+ end
81
+ end
@@ -41,6 +41,111 @@ class TestStyles < Test::Unit::TestCase
41
41
  assert_equal options[:border][:color], "FF000000", 'color is stil in option'
42
42
  end
43
43
 
44
+ def test_parse_num_fmt
45
+ f_code = {:format_code => "YYYY/MM"}
46
+ num_fmt = {:num_fmt => 5}
47
+ both = { :format_code => "#000", :num_fmt => 0 }
48
+ assert_equal(@styles.parse_num_fmt_options, nil, 'noop if neither :format_code or :num_fmt exist')
49
+ max = @styles.numFmts.map{ |nf| nf.numFmtId }.max
50
+ @styles.parse_num_fmt_options(f_code)
51
+ assert_equal(@styles.numFmts.last.numFmtId, max + 1, "new numfmts gets next available id")
52
+ assert(@styles.parse_num_fmt_options(num_fmt).is_a?(Integer), "Should return the provided num_fmt if not dxf")
53
+ assert(@styles.parse_num_fmt_options(num_fmt.merge({:type => :dxf})).is_a?(Axlsx::NumFmt), "Makes a new NumFmt if dxf")
54
+ end
55
+
56
+ def test_parse_border_options_hash_required_keys
57
+ assert_raise(ArgumentError, "Require color key") { @styles.parse_border_options(:border => { :style => :thin }) }
58
+ assert_raise(ArgumentError, "Require style key") { @styles.parse_border_options(:border => { :color => "FF0d0d0d" }) }
59
+ assert_nothing_raised { @styles.parse_border_options(:border => { :style => :thin, :color => "FF000000"} ) }
60
+ end
61
+
62
+ def test_parse_border_basic_options
63
+ b_opts = {:border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } }
64
+ b = @styles.parse_border_options b_opts
65
+ assert(b.is_a? Integer)
66
+ assert_equal(@styles.parse_border_options(b_opts.merge({:type => :dxf})).class,Axlsx::Border)
67
+ assert(@styles.borders.last.diagonalUp == 1, "border options are passed in to the initializer")
68
+ end
69
+
70
+ def test_parse_border_options_edges
71
+ b_opts = {:border => { :diagonalUp => 1, :edges => [:left, :right], :color => "FFDADADA", :style => :thick } }
72
+ @styles.parse_border_options b_opts
73
+ b = @styles.borders.last
74
+ left = b.prs.select { |bpr| bpr.name == :left }[0]
75
+ right = b.prs.select { |bpr| bpr.name == :right }[0]
76
+ top = b.prs.select { |bpr| bpr.name == :top }[0]
77
+ bottom = b.prs.select { |bpr| bpr.name == :bottom }[0]
78
+ assert_equal(top, nil, "unspecified top edge should not be created")
79
+ assert_equal(bottom, nil, "unspecified bottom edge should not be created")
80
+ assert(left.is_a?(Axlsx::BorderPr), "specified left edge is set")
81
+ assert(right.is_a?(Axlsx::BorderPr), "specified right edge is set")
82
+ assert_equal(left.style,right.style, "edge parts have the same style")
83
+ assert_equal(left.style, :thick, "the style is THICK")
84
+ assert_equal(right.color.rgb,left.color.rgb, "edge parts are colors are the same")
85
+ assert_equal(right.color.rgb,"FFDADADA", "edge color rgb is correct")
86
+ end
87
+
88
+ def test_parse_border_options_noop
89
+ assert_equal(@styles.parse_border_options({}), nil, "noop if the border key is not in options")
90
+ end
91
+
92
+ def test_parse_border_options_integer_xf
93
+ assert_equal(@styles.parse_border_options(:border => 1), 1)
94
+ assert_raise(ArgumentError, "unknown border index") {@styles.parse_border_options(:border => 100) }
95
+ end
96
+
97
+ def test_parse_border_options_integer_dxf
98
+ b_opts = { :border => { :edges => [:left, :right], :color => "FFFFFFFF", :style=> :thick } }
99
+ b = @styles.parse_border_options(b_opts)
100
+ b2 = @styles.parse_border_options(:border => b, :type => :dxf)
101
+ assert(b2.is_a?(Axlsx::Border), "Cloned existing border object")
102
+ end
103
+
104
+ def test_parse_alignment_options
105
+ assert_equal(@styles.parse_alignment_options {}, nil, "noop if :alignment is not set")
106
+ assert(@styles.parse_alignment_options(:alignment => {}).is_a?(Axlsx::CellAlignment))
107
+ end
108
+
109
+ def test_parse_font_options
110
+ options = {
111
+ :fg_color => "FF050505",
112
+ :sz => 20,
113
+ :b => 1,
114
+ :i => 1,
115
+ :u => 1,
116
+ :strike => 1,
117
+ :outline => 1,
118
+ :shadow => 1,
119
+ :charset => 9,
120
+ :family => 1,
121
+ :font_name => "woot font"
122
+ }
123
+ assert_equal(@styles.parse_font_options {}, nil, "noop if no font keys are set")
124
+ assert_equal(@styles.parse_font_options(:b=>1).class, Fixnum, "return index of font if not :dxf type")
125
+ assert_equal(@styles.parse_font_options(:b=>1, :type => :dxf).class, Axlsx::Font, "return font object if :dxf type")
126
+
127
+ f = @styles.parse_font_options(options.merge(:type => :dxf))
128
+ color = options.delete(:fg_color)
129
+ options[:name] = options.delete(:font_name)
130
+ options.each do |key, value|
131
+ assert_equal(f.send(key), value, "assert that #{key} was parsed")
132
+ end
133
+ assert_equal(f.color.rgb, color)
134
+ end
135
+
136
+ def test_parse_fill_options
137
+ assert_equal(@styles.parse_fill_options {}, nil, "noop if no fill keys are set")
138
+ assert_equal(@styles.parse_fill_options(:bg_color => "DE").class, Fixnum, "return index of fill if not :dxf type")
139
+ assert_equal(@styles.parse_fill_options(:bg_color => "DE", :type => :dxf).class, Axlsx::Fill, "return fill object if :dxf type")
140
+ f = @styles.parse_fill_options(:bg_color => "DE", :type => :dxf)
141
+ assert(f.fill_type.fgColor.rgb == "FFDEDEDE")
142
+ end
143
+
144
+ def test_parse_protection_options
145
+ assert_equal(@styles.parse_protection_options {}, nil, "noop if no protection keys are set")
146
+ assert_equal(@styles.parse_protection_options(:hidden => 1).class, Axlsx::CellProtection, "creates a new cell protection object")
147
+ end
148
+
44
149
  def test_add_style
45
150
  fill_count = @styles.fills.size
46
151
  font_count = @styles.fonts.size
@@ -68,10 +173,51 @@ class TestStyles < Test::Unit::TestCase
68
173
  assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 2 }
69
174
 
70
175
 
71
- assert_equal(xf.applyProtection, 1, "protection applied")
176
+ assert_equal(xf.applyProtection, true, "protection applied")
72
177
  assert_equal(xf.applyBorder, true, "border applied")
73
- assert_equal(xf.applyNumberFormat, true, "number format applied")
178
+ assert_equal(xf.applyNumberFormat,true, "number format applied")
74
179
  assert_equal(xf.applyAlignment, true, "alignment applied")
75
180
  end
76
181
 
182
+ def test_basic_add_style_dxf
183
+ border_count = @styles.borders.size
184
+ s = @styles.add_style :border => {:style => :thin, :color => "FFFF0000"}, :type => :dxf
185
+ assert_equal(@styles.borders.size, border_count, "styles borders not affected")
186
+ assert_equal(@styles.dxfs.last.border.prs.last.color.rgb, "FFFF0000")
187
+ assert_raise(ArgumentError) { @styles.add_style :border => {:color => "FFFF0000"}, :type => :dxf }
188
+ assert_equal @styles.borders.last.prs.size, 4
189
+ end
190
+
191
+ def test_add_style_dxf
192
+ fill_count = @styles.fills.size
193
+ font_count = @styles.fonts.size
194
+ dxf_count = @styles.dxfs.size
195
+
196
+ style = @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf
197
+ assert_equal(@styles.dxfs.size, dxf_count+1)
198
+ assert_equal(0, style, "returns the zero-based dxfId")
199
+
200
+ dxf = @styles.dxfs.last
201
+ assert_equal(@styles.dxfs.last.fill.fill_type.fgColor.rgb, "FF000000", "fill created with color")
202
+
203
+ assert_equal(font_count, (@styles.fonts.size), "font not created under styles")
204
+ assert_equal(fill_count, (@styles.fills.size), "fill not created under styles")
205
+
206
+ assert(dxf.border.is_a?(Axlsx::Border), "border is set")
207
+ assert_equal(nil, dxf.numFmt, "number format is not set")
208
+
209
+ assert(dxf.alignment.is_a?(Axlsx::CellAlignment), "alignment was created")
210
+ assert_equal(dxf.alignment.horizontal, :left, "horizontal alignment applied")
211
+ assert_equal(dxf.protection.hidden, true, "hidden protection set")
212
+ assert_equal(dxf.protection.locked, true, "cell locking set")
213
+ assert_raise(ArgumentError, "should reject invalid borderId") { @styles.add_style :border => 3 }
214
+ end
215
+
216
+ def test_multiple_dxf
217
+ # add a second style
218
+ style = @styles.add_style :bg_color=>"00000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf
219
+ assert_equal(0, style, "returns the first dxfId")
220
+ style = @styles.add_style :bg_color=>"FF000000", :fg_color=>"FFFFFFFF", :sz=>13, :alignment=>{:horizontal=>:left}, :border=>{:style => :thin, :color => "FFFF0000"}, :hidden=>true, :locked=>true, :type => :dxf
221
+ assert_equal(1, style, "returns the second dxfId")
222
+ end
77
223
  end
@@ -0,0 +1,31 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestCfvo < Test::Unit::TestCase
4
+ def setup
5
+ @cfvo = Axlsx::Cfvo.new(:val => "0", :type => :min)
6
+ end
7
+
8
+ def test_val
9
+ assert_nothing_raised { @cfvo.val = "abc" }
10
+ assert_equal(@cfvo.val, "abc")
11
+ end
12
+
13
+ def test_type
14
+ assert_raise(ArgumentError) { @cfvo.type = :invalid_type }
15
+ assert_nothing_raised { @cfvo.type = :max }
16
+ assert_equal(@cfvo.type, :max)
17
+ end
18
+
19
+ def test_gte
20
+ assert_raise(ArgumentError) { @cfvo.gte = :bob }
21
+ assert_equal(@cfvo.gte, true)
22
+ assert_nothing_raised { @cfvo.gte = false }
23
+ assert_equal(@cfvo.gte, false)
24
+ end
25
+
26
+ def test_to_xml_string
27
+ doc = Nokogiri::XML.parse(@cfvo.to_xml_string)
28
+ assert doc.xpath(".//cfvo[@type='min'][@val=0][@gte=true]")
29
+ end
30
+
31
+ end