caxlsx 2.0.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +41 -33
  4. data/Rakefile +9 -11
  5. data/examples/auto_filter.rb +10 -1
  6. data/examples/conditional_formatting/example_conditional_formatting.rb +18 -3
  7. data/examples/data_validation.rb +57 -40
  8. data/examples/example.rb +115 -7
  9. data/examples/merge_cells.rb +17 -0
  10. data/examples/no_grid_with_borders.rb +18 -0
  11. data/examples/pivot_test.rb +63 -0
  12. data/examples/split.rb +16 -0
  13. data/lib/axlsx.rb +34 -15
  14. data/lib/axlsx/content_type/abstract_content_type.rb +1 -1
  15. data/lib/axlsx/content_type/content_type.rb +1 -1
  16. data/lib/axlsx/doc_props/app.rb +1 -1
  17. data/lib/axlsx/doc_props/core.rb +5 -5
  18. data/lib/axlsx/drawing/area_chart.rb +99 -0
  19. data/lib/axlsx/drawing/area_series.rb +110 -0
  20. data/lib/axlsx/drawing/axes.rb +1 -1
  21. data/lib/axlsx/drawing/axis.rb +12 -9
  22. data/lib/axlsx/drawing/bar_3D_chart.rb +13 -13
  23. data/lib/axlsx/drawing/bar_chart.rb +143 -0
  24. data/lib/axlsx/drawing/bar_series.rb +9 -9
  25. data/lib/axlsx/drawing/bubble_chart.rb +59 -0
  26. data/lib/axlsx/drawing/bubble_series.rb +63 -0
  27. data/lib/axlsx/drawing/cat_axis.rb +5 -5
  28. data/lib/axlsx/drawing/chart.rb +52 -8
  29. data/lib/axlsx/drawing/d_lbls.rb +3 -3
  30. data/lib/axlsx/drawing/drawing.rb +6 -1
  31. data/lib/axlsx/drawing/graphic_frame.rb +3 -3
  32. data/lib/axlsx/drawing/hyperlink.rb +1 -3
  33. data/lib/axlsx/drawing/line_3D_chart.rb +2 -2
  34. data/lib/axlsx/drawing/line_chart.rb +10 -10
  35. data/lib/axlsx/drawing/line_series.rb +32 -3
  36. data/lib/axlsx/drawing/marker.rb +1 -1
  37. data/lib/axlsx/drawing/num_data.rb +4 -4
  38. data/lib/axlsx/drawing/num_data_source.rb +6 -6
  39. data/lib/axlsx/drawing/num_val.rb +3 -1
  40. data/lib/axlsx/drawing/one_cell_anchor.rb +3 -2
  41. data/lib/axlsx/drawing/pic.rb +25 -19
  42. data/lib/axlsx/drawing/picture_locking.rb +1 -3
  43. data/lib/axlsx/drawing/pie_3D_chart.rb +5 -6
  44. data/lib/axlsx/drawing/pie_series.rb +6 -6
  45. data/lib/axlsx/drawing/scaling.rb +6 -6
  46. data/lib/axlsx/drawing/scatter_chart.rb +10 -10
  47. data/lib/axlsx/drawing/scatter_series.rb +40 -7
  48. data/lib/axlsx/drawing/ser_axis.rb +2 -2
  49. data/lib/axlsx/drawing/series.rb +3 -3
  50. data/lib/axlsx/drawing/series_title.rb +2 -2
  51. data/lib/axlsx/drawing/str_data.rb +3 -3
  52. data/lib/axlsx/drawing/str_val.rb +3 -1
  53. data/lib/axlsx/drawing/title.rb +22 -4
  54. data/lib/axlsx/drawing/two_cell_anchor.rb +6 -1
  55. data/lib/axlsx/drawing/val_axis.rb +1 -1
  56. data/lib/axlsx/drawing/view_3D.rb +2 -2
  57. data/lib/axlsx/drawing/vml_drawing.rb +1 -1
  58. data/lib/axlsx/package.rb +33 -31
  59. data/lib/axlsx/rels/relationship.rb +1 -1
  60. data/lib/axlsx/rels/relationships.rb +7 -4
  61. data/lib/axlsx/stylesheet/border_pr.rb +2 -2
  62. data/lib/axlsx/stylesheet/cell_alignment.rb +1 -3
  63. data/lib/axlsx/stylesheet/cell_protection.rb +1 -3
  64. data/lib/axlsx/stylesheet/cell_style.rb +1 -3
  65. data/lib/axlsx/stylesheet/color.rb +1 -3
  66. data/lib/axlsx/stylesheet/font.rb +1 -1
  67. data/lib/axlsx/stylesheet/gradient_stop.rb +1 -1
  68. data/lib/axlsx/stylesheet/num_fmt.rb +10 -3
  69. data/lib/axlsx/stylesheet/pattern_fill.rb +1 -1
  70. data/lib/axlsx/stylesheet/styles.rb +7 -7
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -3
  72. data/lib/axlsx/util/accessors.rb +6 -6
  73. data/lib/axlsx/util/constants.rb +107 -99
  74. data/lib/axlsx/util/mime_type_utils.rb +11 -0
  75. data/lib/axlsx/util/options_parser.rb +2 -1
  76. data/lib/axlsx/util/parser.rb +4 -4
  77. data/lib/axlsx/util/serialized_attributes.rb +16 -6
  78. data/lib/axlsx/util/simple_typed_list.rb +28 -52
  79. data/lib/axlsx/util/storage.rb +4 -4
  80. data/lib/axlsx/util/validators.rb +29 -17
  81. data/lib/axlsx/version.rb +1 -1
  82. data/lib/axlsx/workbook/defined_name.rb +11 -12
  83. data/lib/axlsx/workbook/defined_names.rb +2 -2
  84. data/lib/axlsx/workbook/shared_strings_table.rb +5 -5
  85. data/lib/axlsx/workbook/workbook.rb +36 -11
  86. data/lib/axlsx/workbook/workbook_view.rb +80 -0
  87. data/lib/axlsx/workbook/workbook_views.rb +22 -0
  88. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +2 -2
  89. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/break.rb +1 -3
  91. data/lib/axlsx/workbook/worksheet/cell.rb +136 -74
  92. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +63 -43
  93. data/lib/axlsx/workbook/worksheet/cfvo.rb +1 -3
  94. data/lib/axlsx/workbook/worksheet/cfvos.rb +4 -1
  95. data/lib/axlsx/workbook/worksheet/col.rb +7 -10
  96. data/lib/axlsx/workbook/worksheet/col_breaks.rb +2 -2
  97. data/lib/axlsx/workbook/worksheet/cols.rb +5 -2
  98. data/lib/axlsx/workbook/worksheet/comment.rb +5 -6
  99. data/lib/axlsx/workbook/worksheet/comments.rb +9 -12
  100. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +1 -1
  101. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +1 -1
  102. data/lib/axlsx/workbook/worksheet/data_bar.rb +4 -6
  103. data/lib/axlsx/workbook/worksheet/data_validation.rb +6 -4
  104. data/lib/axlsx/workbook/worksheet/dimension.rb +2 -2
  105. data/lib/axlsx/workbook/worksheet/header_footer.rb +6 -8
  106. data/lib/axlsx/workbook/worksheet/icon_set.rb +3 -5
  107. data/lib/axlsx/workbook/worksheet/merged_cells.rb +4 -2
  108. data/lib/axlsx/workbook/worksheet/outline_pr.rb +33 -0
  109. data/lib/axlsx/workbook/worksheet/page_margins.rb +1 -3
  110. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -1
  111. data/lib/axlsx/workbook/worksheet/page_setup.rb +21 -23
  112. data/lib/axlsx/workbook/worksheet/pane.rb +1 -3
  113. data/lib/axlsx/workbook/worksheet/pivot_table.rb +44 -28
  114. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +4 -4
  115. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -3
  116. data/lib/axlsx/workbook/worksheet/protected_range.rb +1 -3
  117. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +5 -2
  118. data/lib/axlsx/workbook/worksheet/rich_text.rb +55 -0
  119. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +250 -0
  120. data/lib/axlsx/workbook/worksheet/row.rb +40 -51
  121. data/lib/axlsx/workbook/worksheet/row_breaks.rb +2 -2
  122. data/lib/axlsx/workbook/worksheet/selection.rb +1 -3
  123. data/lib/axlsx/workbook/worksheet/sheet_data.rb +3 -1
  124. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +21 -3
  125. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -3
  126. data/lib/axlsx/workbook/worksheet/table.rb +6 -6
  127. data/lib/axlsx/workbook/worksheet/table_style_info.rb +1 -3
  128. data/lib/axlsx/workbook/worksheet/tables.rb +4 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet.rb +64 -78
  130. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +10 -10
  131. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +3 -3
  132. data/test/drawing/tc_area_chart.rb +39 -0
  133. data/test/drawing/tc_area_series.rb +71 -0
  134. data/test/drawing/tc_axis.rb +27 -0
  135. data/test/drawing/tc_bar_chart.rb +71 -0
  136. data/test/drawing/tc_bubble_chart.rb +44 -0
  137. data/test/drawing/tc_bubble_series.rb +21 -0
  138. data/test/drawing/tc_chart.rb +23 -10
  139. data/test/drawing/tc_data_source.rb +6 -0
  140. data/test/drawing/tc_drawing.rb +2 -2
  141. data/test/drawing/tc_line_chart.rb +5 -5
  142. data/test/drawing/tc_line_series.rb +47 -6
  143. data/test/drawing/tc_pic.rb +11 -15
  144. data/test/drawing/tc_scatter_series.rb +36 -1
  145. data/test/drawing/tc_str_val.rb +9 -0
  146. data/test/drawing/tc_title.rb +5 -0
  147. data/test/stylesheet/tc_styles.rb +2 -2
  148. data/test/tc_axlsx.rb +31 -0
  149. data/test/tc_helper.rb +2 -0
  150. data/test/tc_package.rb +19 -1
  151. data/test/util/tc_mime_type_utils.rb +13 -0
  152. data/test/util/tc_simple_typed_list.rb +2 -3
  153. data/test/util/tc_validators.rb +34 -10
  154. data/test/workbook/tc_defined_name.rb +12 -4
  155. data/test/workbook/tc_shared_strings_table.rb +16 -1
  156. data/test/workbook/tc_workbook.rb +38 -3
  157. data/test/workbook/tc_workbook_view.rb +50 -0
  158. data/test/workbook/worksheet/auto_filter/tc_filters.rb +1 -1
  159. data/test/workbook/worksheet/tc_break.rb +1 -1
  160. data/test/workbook/worksheet/tc_cell.rb +76 -8
  161. data/test/workbook/worksheet/tc_col.rb +2 -2
  162. data/test/workbook/worksheet/tc_conditional_formatting.rb +2 -2
  163. data/test/workbook/worksheet/tc_data_bar.rb +1 -1
  164. data/test/workbook/worksheet/tc_data_validation.rb +11 -11
  165. data/test/workbook/worksheet/tc_header_footer.rb +2 -2
  166. data/test/workbook/worksheet/tc_icon_set.rb +1 -1
  167. data/test/workbook/worksheet/tc_outline_pr.rb +19 -0
  168. data/test/workbook/worksheet/tc_page_setup.rb +3 -3
  169. data/test/workbook/worksheet/tc_pivot_table.rb +21 -6
  170. data/test/workbook/worksheet/tc_print_options.rb +1 -1
  171. data/test/workbook/worksheet/tc_rich_text.rb +44 -0
  172. data/test/workbook/worksheet/tc_rich_text_run.rb +172 -0
  173. data/test/workbook/worksheet/tc_row.rb +7 -2
  174. data/test/workbook/worksheet/tc_sheet_calc_pr.rb +1 -1
  175. data/test/workbook/worksheet/tc_sheet_format_pr.rb +4 -4
  176. data/test/workbook/worksheet/tc_sheet_pr.rb +26 -4
  177. data/test/workbook/worksheet/tc_sheet_protection.rb +5 -5
  178. data/test/workbook/worksheet/tc_sheet_view.rb +4 -4
  179. data/test/workbook/worksheet/tc_table.rb +2 -3
  180. data/test/workbook/worksheet/tc_worksheet.rb +99 -45
  181. metadata +89 -16
@@ -109,7 +109,7 @@ class TestHeaderFooter < Test::Unit::TestCase
109
109
  )
110
110
 
111
111
  doc = Nokogiri::XML.parse(@hf.to_xml_string)
112
- assert_equal(1, doc.xpath(".//headerFooter[@differentFirst='true'][@differentOddEven='true']").size)
112
+ assert_equal(1, doc.xpath(".//headerFooter[@differentFirst=1][@differentOddEven=1]").size)
113
113
 
114
114
  assert_equal(1, doc.xpath(".//headerFooter/oddHeader").size)
115
115
  assert_equal('oh', doc.xpath(".//headerFooter/oddHeader").text)
@@ -134,7 +134,7 @@ class TestHeaderFooter < Test::Unit::TestCase
134
134
  )
135
135
 
136
136
  doc = Nokogiri::XML.parse(@hf.to_xml_string)
137
- assert_equal(1, doc.xpath(".//headerFooter[@differentOddEven='false']").size)
137
+ assert_equal(1, doc.xpath(".//headerFooter[@differentOddEven=0]").size)
138
138
  assert_equal(0, doc.xpath(".//headerFooter[@differentFirst]").size)
139
139
 
140
140
  assert_equal(1, doc.xpath(".//headerFooter/oddHeader").size)
@@ -38,7 +38,7 @@ class TestIconSet < Test::Unit::TestCase
38
38
 
39
39
  def test_to_xml_string
40
40
  doc = Nokogiri::XML.parse(@icon_set.to_xml_string)
41
- assert_equal(doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent='true'][@reverse='false'][@showValue='true']").size, 1)
41
+ assert_equal(doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size, 1)
42
42
  assert_equal(doc.xpath(".//iconSet//cfvo").size, 3)
43
43
  end
44
44
 
@@ -0,0 +1,19 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class TestOutlinePr < Test::Unit::TestCase
4
+ def setup
5
+ @outline_pr = Axlsx::OutlinePr.new(:summary_below => false, :summary_right => true, :apply_styles => false)
6
+ end
7
+
8
+ def test_summary_below
9
+ assert_equal false, @outline_pr.summary_below
10
+ end
11
+
12
+ def test_summary_right
13
+ assert_equal true, @outline_pr.summary_right
14
+ end
15
+
16
+ def test_apply_styles
17
+ assert_equal false, @outline_pr.apply_styles
18
+ end
19
+ end
@@ -63,7 +63,7 @@ class TestPageSetup < Test::Unit::TestCase
63
63
  assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil)
64
64
  assert(@ps.fit_to_page? == false)
65
65
  end
66
-
66
+
67
67
  def test_with_height_fit_to_page?
68
68
  assert(@ps.fit_to_width == nil && @ps.fit_to_height == nil)
69
69
  @ps.set(:fit_to_height => 1)
@@ -131,9 +131,9 @@ class TestPageSetup < Test::Unit::TestCase
131
131
 
132
132
  def test_fit_to
133
133
  fits = @ps.fit_to(:width => 1)
134
- assert_equal([1, 9999], fits)
134
+ assert_equal([1, 999], fits)
135
135
  fits = @ps.fit_to :height => 1
136
- assert_equal(fits, [9999,1])
136
+ assert_equal(fits, [999 ,1])
137
137
  fits = @ps.fit_to :height => 7, :width => 2
138
138
  assert_equal(fits, [2, 7])
139
139
  assert_raise(ArgumentError) { puts @ps.fit_to(:width => true)}
@@ -67,6 +67,26 @@ class TestPivotTable < Test::Unit::TestCase
67
67
  assert_equal([{:ref=>"Sales", :subtotal => 'average'}], pivot_table.data)
68
68
  end
69
69
 
70
+ def test_add_pivot_table_with_style_info
71
+ style_info_data = { :name=>"PivotStyleMedium9", :showRowHeaders=>"1", :showLastColumn=>"0"}
72
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:style_info=>style_info_data}) do |pt|
73
+ pt.rows = ['Year', 'Month']
74
+ pt.columns = ['Type']
75
+ pt.data = ['Sales']
76
+ pt.pages = ['Region']
77
+ end
78
+ assert_equal(style_info_data, pivot_table.style_info)
79
+ shared_test_pivot_table_xml_validity(pivot_table)
80
+ end
81
+
82
+ def test_add_pivot_table_with_row_without_subtotals
83
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5', {:no_subtotals_on_headers=>['Year']}) do |pt|
84
+ pt.data = ['Sales']
85
+ pt.rows = ['Year','Month']
86
+ end
87
+ assert_equal(['Year'], pivot_table.no_subtotals_on_headers)
88
+ end
89
+
70
90
  def test_header_indices
71
91
  pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5')
72
92
  assert_equal(0, pivot_table.header_index_of('Year' ))
@@ -97,12 +117,7 @@ class TestPivotTable < Test::Unit::TestCase
97
117
  end
98
118
 
99
119
  def test_to_xml_string
100
- pivot_table = @ws.add_pivot_table('G5:G6', 'A1:D5')
101
- shared_test_pivot_table_xml_validity(pivot_table)
102
- end
103
-
104
- def test_to_xml_string_with_configuration
105
- pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5') do |pt|
120
+ pivot_table = @ws.add_pivot_table('G5:G6', 'A1:E5', {:no_subtotals_on_headers=>['Year']}) do |pt|
106
121
  pt.rows = ['Year', 'Month']
107
122
  pt.columns = ['Type']
108
123
  pt.data = ['Sales']
@@ -42,7 +42,7 @@ class TestPrintOptions < Test::Unit::TestCase
42
42
  def test_to_xml
43
43
  @po.set(:grid_lines => true, :headings => true, :horizontal_centered => true, :vertical_centered => true)
44
44
  doc = Nokogiri::XML.parse(@po.to_xml_string)
45
- assert_equal(1, doc.xpath(".//printOptions[@gridLines='true'][@headings='true'][@horizontalCentered='true'][@verticalCentered='true']").size)
45
+ assert_equal(1, doc.xpath(".//printOptions[@gridLines=1][@headings=1][@horizontalCentered=1][@verticalCentered=1]").size)
46
46
  end
47
47
 
48
48
  def test_grid_lines
@@ -0,0 +1,44 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class RichText < Test::Unit::TestCase
4
+ def setup
5
+ p = Axlsx::Package.new
6
+ @ws = p.workbook.add_worksheet :name => "hmmmz"
7
+ p.workbook.styles.add_style :sz => 20
8
+ @rt = Axlsx::RichText.new
9
+ b = true
10
+ (0..26).each do |r|
11
+ @rt.add_run "run #{r}, ", :b => (b=!b), :i => !b
12
+ end
13
+ @row = @ws.add_row [@rt]
14
+ @c = @row.first
15
+ end
16
+
17
+ def test_initialize
18
+ assert_equal(@c.value, @rt)
19
+ rt_direct = Axlsx::RichText.new('hi', :i => true)
20
+ rt_indirect = Axlsx::RichText.new()
21
+ rt_indirect.add_run('hi', :i => true)
22
+ assert_equal(rt_direct.runs.length, 1)
23
+ assert_equal(rt_indirect.runs.length, 1)
24
+ row = @ws.add_row [rt_direct, rt_indirect]
25
+ assert_equal(row[0].to_xml_string(0,0), row[1].to_xml_string(0,0))
26
+ end
27
+
28
+ def test_textruns
29
+ runs = @rt.runs
30
+ assert_equal(runs.length, 27)
31
+ assert_equal(runs.first.b, false)
32
+ assert_equal(runs.first.i, true)
33
+ assert_equal(runs[1].b, true)
34
+ assert_equal(runs[1].i, false)
35
+ end
36
+
37
+ def test_implicit_richtext
38
+ rt = Axlsx::RichText.new('a', :b => true)
39
+ row_rt = @ws.add_row [rt]
40
+ row_imp = @ws.add_row ['a']
41
+ row_imp[0].b = true
42
+ assert_equal(row_rt[0].to_xml_string(0,0), row_imp[0].to_xml_string(0,0))
43
+ end
44
+ end
@@ -0,0 +1,172 @@
1
+ require 'tc_helper.rb'
2
+
3
+ class RichTextRun < Test::Unit::TestCase
4
+ def setup
5
+ @p = Axlsx::Package.new
6
+ @ws = @p.workbook.add_worksheet :name => "hmmmz"
7
+ @p.workbook.styles.add_style :sz => 20
8
+ @rtr = Axlsx::RichTextRun.new('hihihi', b: true, i: false)
9
+ @rtr2 = Axlsx::RichTextRun.new('hihi2hi2', b: false, i: true)
10
+ @rt = Axlsx::RichText.new
11
+ @rt.runs << @rtr
12
+ @rt.runs << @rtr2
13
+ @row = @ws.add_row [@rt]
14
+ @c = @row.first
15
+ end
16
+
17
+ def test_initialize
18
+ assert_equal(@rtr.value, 'hihihi')
19
+ assert_equal(@rtr.b, true)
20
+ assert_equal(@rtr.i, false)
21
+ end
22
+
23
+ def test_font_size_with_custom_style_and_no_sz
24
+ @c.style = @c.row.worksheet.workbook.styles.add_style :bg_color => 'FF00FF'
25
+ sz = @rtr.send(:font_size)
26
+ assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz * 1.5)
27
+ sz = @rtr2.send(:font_size)
28
+ assert_equal(sz, @c.row.worksheet.workbook.styles.fonts.first.sz)
29
+ end
30
+
31
+ def test_font_size_with_bolding
32
+ @c.style = @c.row.worksheet.workbook.styles.add_style :b => true
33
+ assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @rtr.send(:font_size))
34
+ assert_equal(@c.row.worksheet.workbook.styles.fonts.first.sz * 1.5, @rtr2.send(:font_size)) # is this the correct behaviour?
35
+ end
36
+
37
+ def test_font_size_with_custom_sz
38
+ @c.style = @c.row.worksheet.workbook.styles.add_style :sz => 52
39
+ sz = @rtr.send(:font_size)
40
+ assert_equal(sz, 52 * 1.5)
41
+ sz2 = @rtr2.send(:font_size)
42
+ assert_equal(sz2, 52)
43
+ end
44
+
45
+ def test_rtr_with_sz
46
+ @rtr.sz = 25
47
+ assert_equal(25, @rtr.send(:font_size))
48
+ end
49
+
50
+ def test_color
51
+ assert_raise(ArgumentError) { @rtr.color = -1.1 }
52
+ assert_nothing_raised { @rtr.color = "FF00FF00" }
53
+ assert_equal(@rtr.color.rgb, "FF00FF00")
54
+ end
55
+
56
+ def test_scheme
57
+ assert_raise(ArgumentError) { @rtr.scheme = -1.1 }
58
+ assert_nothing_raised { @rtr.scheme = :major }
59
+ assert_equal(@rtr.scheme, :major)
60
+ end
61
+
62
+ def test_vertAlign
63
+ assert_raise(ArgumentError) { @rtr.vertAlign = -1.1 }
64
+ assert_nothing_raised { @rtr.vertAlign = :baseline }
65
+ assert_equal(@rtr.vertAlign, :baseline)
66
+ end
67
+
68
+ def test_sz
69
+ assert_raise(ArgumentError) { @rtr.sz = -1.1 }
70
+ assert_nothing_raised { @rtr.sz = 12 }
71
+ assert_equal(@rtr.sz, 12)
72
+ end
73
+
74
+ def test_extend
75
+ assert_raise(ArgumentError) { @rtr.extend = -1.1 }
76
+ assert_nothing_raised { @rtr.extend = false }
77
+ assert_equal(@rtr.extend, false)
78
+ end
79
+
80
+ def test_condense
81
+ assert_raise(ArgumentError) { @rtr.condense = -1.1 }
82
+ assert_nothing_raised { @rtr.condense = false }
83
+ assert_equal(@rtr.condense, false)
84
+ end
85
+
86
+ def test_shadow
87
+ assert_raise(ArgumentError) { @rtr.shadow = -1.1 }
88
+ assert_nothing_raised { @rtr.shadow = false }
89
+ assert_equal(@rtr.shadow, false)
90
+ end
91
+
92
+ def test_outline
93
+ assert_raise(ArgumentError) { @rtr.outline = -1.1 }
94
+ assert_nothing_raised { @rtr.outline = false }
95
+ assert_equal(@rtr.outline, false)
96
+ end
97
+
98
+ def test_strike
99
+ assert_raise(ArgumentError) { @rtr.strike = -1.1 }
100
+ assert_nothing_raised { @rtr.strike = false }
101
+ assert_equal(@rtr.strike, false)
102
+ end
103
+
104
+ def test_u
105
+ @c.type = :string
106
+ assert_raise(ArgumentError) { @c.u = -1.1 }
107
+ assert_nothing_raised { @c.u = :single }
108
+ assert_equal(@c.u, :single)
109
+ doc = Nokogiri::XML(@c.to_xml_string(1,1))
110
+ assert(doc.xpath('//u[@val="single"]'))
111
+ end
112
+
113
+ def test_i
114
+ assert_raise(ArgumentError) { @c.i = -1.1 }
115
+ assert_nothing_raised { @c.i = false }
116
+ assert_equal(@c.i, false)
117
+ end
118
+
119
+ def test_rFont
120
+ assert_raise(ArgumentError) { @c.font_name = -1.1 }
121
+ assert_nothing_raised { @c.font_name = "Arial" }
122
+ assert_equal(@c.font_name, "Arial")
123
+ end
124
+
125
+ def test_charset
126
+ assert_raise(ArgumentError) { @c.charset = -1.1 }
127
+ assert_nothing_raised { @c.charset = 1 }
128
+ assert_equal(@c.charset, 1)
129
+ end
130
+
131
+ def test_family
132
+ assert_raise(ArgumentError) { @rtr.family = 0 }
133
+ assert_nothing_raised { @rtr.family = 1 }
134
+ assert_equal(@rtr.family, 1)
135
+ end
136
+
137
+ def test_b
138
+ assert_raise(ArgumentError) { @c.b = -1.1 }
139
+ assert_nothing_raised { @c.b = false }
140
+ assert_equal(@c.b, false)
141
+ end
142
+
143
+ def test_multiline_autowidth
144
+ wrap = @p.workbook.styles.add_style({:alignment => {:wrap_text => true}})
145
+ awtr = Axlsx::RichTextRun.new('I\'m bold' + "\n", :b => true)
146
+ rt = Axlsx::RichText.new
147
+ rt.runs << awtr
148
+ @ws.add_row [rt], :style => wrap
149
+ ar = [0]
150
+ awtr.autowidth(ar)
151
+ assert_equal(ar.length, 2)
152
+ assert_equal(ar.last, 0)
153
+ end
154
+
155
+ def test_to_xml
156
+ schema = Nokogiri::XML::Schema(File.open(Axlsx::SML_XSD))
157
+ doc = Nokogiri::XML(@ws.to_xml_string)
158
+ errors = []
159
+ schema.validate(doc).each do |error|
160
+ puts error.message
161
+ errors.push error
162
+ end
163
+ assert(errors.empty?, "error free validation")
164
+
165
+ assert(doc.xpath('//rPr/b[@val=1]'))
166
+ assert(doc.xpath('//rPr/i[@val=0]'))
167
+ assert(doc.xpath('//rPr/b[@val=0]'))
168
+ assert(doc.xpath('//rPr/i[@val=1]'))
169
+ assert(doc.xpath('//is//t[contains(text(), "hihihi")]'))
170
+ assert(doc.xpath('//is//t[contains(text(), "hihi2hi2")]'))
171
+ end
172
+ end
@@ -27,9 +27,14 @@ class TestRow < Test::Unit::TestCase
27
27
  r.cells.each { |c| assert_equal(c.style,1) }
28
28
  end
29
29
 
30
+ def test_color
31
+ r = @ws.add_row([1,2,3,4,5])
32
+ r.color = "FF00FF00"
33
+ r.cells.each { |c| assert_equal(c.color.rgb, "FF00FF00") }
34
+ end
30
35
 
31
36
  def test_index
32
- assert_equal(@row.index, @row.worksheet.rows.index(@row))
37
+ assert_equal(@row.row_index, @row.worksheet.rows.index(@row))
33
38
  end
34
39
 
35
40
  def test_add_cell
@@ -111,7 +116,7 @@ class TestRow < Test::Unit::TestCase
111
116
  @row.add_cell 1
112
117
  @row.height = 20
113
118
  r_s_xml = Nokogiri::XML(@row.to_xml_string(0, ''))
114
- assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight='true']").size, 1)
119
+ assert_equal(r_s_xml.xpath(".//row[@r=1][@ht=20][@customHeight=1]").size, 1)
115
120
  end
116
121
 
117
122
  end
@@ -13,6 +13,6 @@ class TestSheetCalcPr < Test::Unit::TestCase
13
13
 
14
14
  def test_to_xml_string
15
15
  doc = Nokogiri::XML(@sheet_calc_pr.to_xml_string)
16
- assert_equal 1, doc.xpath('//sheetCalcPr[@fullCalcOnLoad="false"]').size
16
+ assert_equal 1, doc.xpath('//sheetCalcPr[@fullCalcOnLoad=0]').size
17
17
  end
18
18
  end
@@ -74,13 +74,13 @@ class TestSheetFormatPr < Test::Unit::TestCase
74
74
 
75
75
  def test_to_xml_string
76
76
  doc = Nokogiri::XML(@sheet_format_pr.to_xml_string)
77
- assert doc.xpath("sheetFormatPr[@thickBottom='true']")
77
+ assert doc.xpath("sheetFormatPr[@thickBottom=1]")
78
78
  assert doc.xpath("sheetFormatPr[@baseColWidth=5]")
79
79
  assert doc.xpath("sheetFormatPr[@default_col_width=7.2]")
80
80
  assert doc.xpath("sheetFormatPr[@default_row_height=5.2]")
81
- assert doc.xpath("sheetFormatPr[@custom_height='true']")
82
- assert doc.xpath("sheetFormatPr[@zero_height='false']")
83
- assert doc.xpath("sheetFormatPr[@thick_top='true']")
81
+ assert doc.xpath("sheetFormatPr[@custom_height=1]")
82
+ assert doc.xpath("sheetFormatPr[@zero_height=0]")
83
+ assert doc.xpath("sheetFormatPr[@thick_top=1]")
84
84
  assert doc.xpath("sheetFormatPr[@outline_level_row=0]")
85
85
  assert doc.xpath("sheetFormatPr[@outline_level_col=0]")
86
86
  end
@@ -5,23 +5,45 @@ class TestSheetPr < Test::Unit::TestCase
5
5
 
6
6
  def setup
7
7
  worksheet = Axlsx::Package.new.workbook.add_worksheet
8
- @options = {
8
+ @options = {
9
9
  :sync_horizontal => false,
10
10
  :sync_vertical => false,
11
- :transtion_evaluation => true,
11
+ :transition_evaluation => true,
12
12
  :transition_entry => true,
13
13
  :published => false,
14
14
  :filter_mode => true,
15
15
  :enable_format_conditions_calculation => false,
16
16
  :code_name => '007',
17
- :sync_ref => 'foo'
17
+ :sync_ref => 'foo',
18
+ :tab_color => 'FFFF6666'
18
19
  }
19
20
  @sheet_pr = Axlsx::SheetPr.new(worksheet, @options)
20
21
  end
21
22
 
22
23
  def test_initialization
23
24
  @options.each do |key, value|
24
- assert_equal value, @sheet_pr.send(key)
25
+ if key==:tab_color
26
+ stored_value = @sheet_pr.send(key)
27
+ assert_equal Axlsx::Color, stored_value.class
28
+ assert_equal value, stored_value.rgb
29
+ else
30
+ assert_equal value, @sheet_pr.send(key)
31
+ end
25
32
  end
26
33
  end
34
+
35
+ def test_to_xml_string
36
+ doc = Nokogiri::XML(@sheet_pr.to_xml_string)
37
+ assert_equal(doc.xpath("//sheetPr[@syncHorizontal='0']").size, 1)
38
+ assert_equal(doc.xpath("//sheetPr[@syncVertical='0']").size, 1)
39
+ assert_equal(doc.xpath("//sheetPr[@transitionEvaluation='1']").size, 1)
40
+ assert_equal(doc.xpath("//sheetPr[@transitionEntry='1']").size, 1)
41
+ assert_equal(doc.xpath("//sheetPr[@published='0']").size, 1)
42
+ assert_equal(doc.xpath("//sheetPr[@filterMode='1']").size, 1)
43
+ assert_equal(doc.xpath("//sheetPr[@enableFormatConditionsCalculation='0']").size, 1)
44
+ assert_equal(doc.xpath("//sheetPr[@codeName='007']").size, 1)
45
+ assert_equal(doc.xpath("//sheetPr[@syncRef='foo']").size, 1)
46
+ assert_equal(doc.xpath("//sheetPr/tabColor[@rgb='FFFF6666']").size, 1)
47
+ assert_equal(doc.xpath("//sheetPr/pageSetUpPr[@fitToPage='0']").size, 1)
48
+ end
27
49
  end
@@ -2,9 +2,9 @@
2
2
  require 'tc_helper.rb'
3
3
 
4
4
  # <xsd:complexType name="CT_SheetProtection">
5
- # <xsd:attribute name="sheet" type="xsd:boolean" use="optional" default="false"/>
6
- # <xsd:attribute name="objects" type="xsd:boolean" use="optional" default="false"/>
7
- # <xsd:attribute name="scenarios" type="xsd:boolean" use="optional" default="false"/>
5
+ # <xsd:attribute name="sheet" type="xsd:boolean" use="optional" default=0/>
6
+ # <xsd:attribute name="objects" type="xsd:boolean" use="optional" default=0/>
7
+ # <xsd:attribute name="scenarios" type="xsd:boolean" use="optional" default=0/>
8
8
  # <xsd:attribute name="formatCells" type="xsd:boolean" use="optional" default="true"/>
9
9
  # <xsd:attribute name="formatColumns" type="xsd:boolean" use="optional" default="true"/>
10
10
  # <xsd:attribute name="formatRows" type="xsd:boolean" use="optional" default="true"/>
@@ -13,11 +13,11 @@ require 'tc_helper.rb'
13
13
  # <xsd:attribute name="insertHyperlinks" type="xsd:boolean" use="optional" default="true"/>
14
14
  # <xsd:attribute name="deleteColumns" type="xsd:boolean" use="optional" default="true"/>
15
15
  # <xsd:attribute name="deleteRows" type="xsd:boolean" use="optional" default="true"/>
16
- # <xsd:attribute name="selectLockedCells" type="xsd:boolean" use="optional" default="false"/>
16
+ # <xsd:attribute name="selectLockedCells" type="xsd:boolean" use="optional" default=0/>
17
17
  # <xsd:attribute name="sort" type="xsd:boolean" use="optional" default="true"/>
18
18
  # <xsd:attribute name="autoFilter" type="xsd:boolean" use="optional" default="true"/>
19
19
  # <xsd:attribute name="pivotTables" type="xsd:boolean" use="optional" default="true"/>
20
- # <xsd:attribute name="selectUnlockedCells" type="xsd:boolean" use="optional" default="false"/>
20
+ # <xsd:attribute name="selectUnlockedCells" type="xsd:boolean" use="optional" default=0/>
21
21
  # <xsd:attribute name="password" type="xsd:string" use="optional" default="nil"/>
22
22
  # </xsd:complexType>
23
23