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
@@ -3,43 +3,32 @@ module Axlsx
3
3
  # The Cell Serializer class contains the logic for serializing cells based on their type.
4
4
  class CellSerializer
5
5
  class << self
6
-
7
-
8
6
  # Calls the proper serialization method based on type.
9
7
  # @param [Integer] row_index The index of the cell's row
10
8
  # @param [Integer] column_index The index of the cell's column
11
9
  # @param [String] str The string to apend serialization to.
12
10
  # @return [String]
13
11
  def to_xml_string(row_index, column_index, cell, str='')
14
- str << '<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" '
12
+ str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ')
15
13
  return str << '/>' if cell.value.nil?
16
- method = (cell.type.to_s << '_type_serialization').to_sym
14
+ method = cell.type
17
15
  self.send(method, cell, str)
18
16
  str << '</c>'
19
- end
20
-
17
+ end
21
18
 
22
19
  # builds an xml text run based on this cells attributes.
23
20
  # @param [String] str The string instance this run will be concated to.
24
21
  # @return [String]
25
22
  def run_xml_string(cell, str = '')
26
23
  if cell.is_text_run?
27
- data = cell.instance_values.reject{|key, value| value == nil || key == 'value' || key == 'type' }
28
- keys = data.keys & Cell::INLINE_STYLES
29
- str << "<r><rPr>"
30
- keys.each do |key|
31
- case key
32
- when 'font_name'
33
- str << "<rFont val='"<< cell.font_name << "'/>"
34
- when 'color'
35
- str << data[key].to_xml_string
36
- else
37
- str << "<" << key.to_s << " val='" << data[key].to_s << "'/>"
38
- end
39
- end
40
- str << "</rPr>" << "<t>" << cell.value.to_s << "</t></r>"
24
+ valid = RichTextRun::INLINE_STYLES - [:value, :type]
25
+ data = Hash[cell.instance_values.map{ |k, v| [k.to_sym, v] }]
26
+ data = data.select { |key, value| valid.include?(key) && !value.nil? }
27
+ RichText.new(cell.value.to_s, data).to_xml_string(str)
28
+ elsif cell.contains_rich_text?
29
+ cell.value.to_xml_string(str)
41
30
  else
42
- str << "<t>" << cell.value.to_s << "</t>"
31
+ str << ('<t>' << cell.clean_value << '</t>')
43
32
  end
44
33
  str
45
34
  end
@@ -48,16 +37,15 @@ module Axlsx
48
37
  # @param [Cell] cell The cell that is being serialized
49
38
  # @param [String] str The string the serialized content will be appended to.
50
39
  # @return [String]
51
- def iso_8601_type_serialization(cell, str='')
40
+ def iso_8601(cell, str='')
52
41
  value_serialization 'd', cell.value, str
53
42
  end
54
43
 
55
-
56
44
  # serializes cells that are type date
57
45
  # @param [Cell] cell The cell that is being serialized
58
46
  # @param [String] str The string the serialized content will be appended to.
59
47
  # @return [String]
60
- def date_type_serialization(cell, str='')
48
+ def date(cell, str='')
61
49
  value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str
62
50
  end
63
51
 
@@ -65,7 +53,7 @@ module Axlsx
65
53
  # @param [Cell] cell The cell that is being serialized
66
54
  # @param [String] str The string the serialized content will be appended to.
67
55
  # @return [String]
68
- def time_type_serialization(cell, str='')
56
+ def time(cell, str='')
69
57
  value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str
70
58
  end
71
59
 
@@ -73,7 +61,7 @@ module Axlsx
73
61
  # @param [Cell] cell The cell that is being serialized
74
62
  # @param [String] str The string the serialized content will be appended to.
75
63
  # @return [String]
76
- def boolean_type_serialization(cell, str='')
64
+ def boolean(cell, str='')
77
65
  value_serialization 'b', cell.value.to_s, str
78
66
  end
79
67
 
@@ -81,26 +69,34 @@ module Axlsx
81
69
  # @param [Cell] cell The cell that is being serialized
82
70
  # @param [String] str The string the serialized content will be appended to.
83
71
  # @return [String]
84
- def float_type_serialization(cell, str='')
85
- numeric_type_serialization cell, str
72
+ def float(cell, str='')
73
+ numeric cell, str
86
74
  end
87
75
 
88
76
  # Serializes cells that are type integer
89
77
  # @param [Cell] cell The cell that is being serialized
90
78
  # @param [String] str The string the serialized content will be appended to.
91
79
  # @return [String]
92
- def integer_type_serialization(cell, str = '')
93
- numeric_type_serialization cell, str
80
+ def integer(cell, str = '')
81
+ numeric cell, str
94
82
  end
95
83
 
96
-
97
84
  # Serializes cells that are type formula
98
85
  # @param [Cell] cell The cell that is being serialized
99
86
  # @param [String] str The string the serialized content will be appended to.
100
87
  # @return [String]
101
88
  def formula_serialization(cell, str='')
102
- str << 't="str">' << '<f>' << cell.value.to_s.sub('=', '') << '</f>'
103
- str << '<v>' << cell.formula_value.to_s << '</v>' unless cell.formula_value.nil?
89
+ str << ('t="str"><f>' << cell.clean_value.to_s.sub('=', '') << '</f>')
90
+ str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
91
+ end
92
+
93
+ # Serializes cells that are type array formula
94
+ # @param [Cell] cell The cell that is being serialized
95
+ # @param [String] str The string the serialized content will be appended to.
96
+ # @return [String]
97
+ def array_formula_serialization(cell, str='')
98
+ str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.sub('{=', '').sub(/}$/, '') << '</f>')
99
+ str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil?
104
100
  end
105
101
 
106
102
  # Serializes cells that are type inline_string
@@ -108,7 +104,7 @@ module Axlsx
108
104
  # @param [String] str The string the serialized content will be appended to.
109
105
  # @return [String]
110
106
  def inline_string_serialization(cell, str = '')
111
- str << 't="inlineStr">' << '<is>'
107
+ str << 't="inlineStr"><is>'
112
108
  run_xml_string cell, str
113
109
  str << '</is>'
114
110
  end
@@ -117,28 +113,52 @@ module Axlsx
117
113
  # @param [Cell] cell The cell that is being serialized
118
114
  # @param [String] str The string the serialized content will be appended to.
119
115
  # @return [String]
120
- def string_type_serialization(cell, str='')
121
- if cell.is_formula?
116
+ def string(cell, str='')
117
+ if cell.is_array_formula?
118
+ array_formula_serialization cell, str
119
+ elsif cell.is_formula?
122
120
  formula_serialization cell, str
123
121
  elsif !cell.ssti.nil?
124
- value_serialization 's', cell.ssti.to_s, str
122
+ value_serialization 's', cell.ssti, str
125
123
  else
126
124
  inline_string_serialization cell, str
127
125
  end
128
126
  end
129
127
 
128
+ # Serializes cells that are of the type richtext
129
+ # @param [Cell] cell The cell that is being serialized
130
+ # @param [String] str The string the serialized content will be appended to.
131
+ # @return [String]
132
+ def richtext(cell, str)
133
+ if cell.ssti.nil?
134
+ inline_string_serialization cell, str
135
+ else
136
+ value_serialization 's', cell.ssti, str
137
+ end
138
+ end
139
+
140
+ # Serializes cells that are of the type text
141
+ # @param [Cell] cell The cell that is being serialized
142
+ # @param [String] str The string the serialized content will be appended to.
143
+ # @return [String]
144
+ def text(cell, str)
145
+ if cell.ssti.nil?
146
+ inline_string_serialization cell, str
147
+ else
148
+ value_serialization 's', cell.ssti, str
149
+ end
150
+ end
151
+
130
152
  private
131
153
 
132
- def numeric_type_serialization(cell, str = '')
133
- value_serialization 'n', cell.value.to_s, str
154
+ def numeric(cell, str = '')
155
+ value_serialization 'n', cell.value, str
134
156
  end
135
157
 
136
158
  def value_serialization(serialization_type, serialization_value, str = '')
137
- str << 't="' << serialization_type << '"' if serialization_type
138
- str << '><v>' << serialization_value << '</v>'
159
+ str << ('t="' << serialization_type.to_s << '"') if serialization_type
160
+ str << ('><v>' << serialization_value.to_s << '</v>')
139
161
  end
140
-
141
-
142
162
  end
143
163
  end
144
164
  end
@@ -54,9 +54,7 @@ module Axlsx
54
54
  # @param [String] str
55
55
  # @return [String]
56
56
  def to_xml_string(str = '')
57
- str << '<cfvo '
58
- serialized_attributes str
59
- str << ' />'
57
+ serialized_tag('cfvo', str)
60
58
  end
61
59
  end
62
60
  end
@@ -8,8 +8,11 @@ module Axlsx
8
8
  super(Cfvo)
9
9
  end
10
10
 
11
+ # Serialize the Cfvo object
12
+ # @param [String] str
13
+ # @return [String]
11
14
  def to_xml_string(str='')
12
- @list.each { |cfvo| cfvo.to_xml_string(str) }
15
+ each { |cfvo| cfvo.to_xml_string(str) }
13
16
  end
14
17
  end
15
18
  end
@@ -122,22 +122,19 @@ module Axlsx
122
122
  # @param [Boolean] use_autowidth If this is false, the cell's
123
123
  # autowidth value will be ignored.
124
124
  def update_width(cell, fixed_width=nil, use_autowidth=true)
125
- if fixed_width.is_a? Numeric
126
- self.width = fixed_width
127
- elsif use_autowidth
128
- cell_width = cell.autowidth
129
- self.width = cell_width unless (width || 0) > (cell_width || 0)
130
- #self.width = [width || 0, cell.autowidth || 0].max
131
- end
125
+ if fixed_width.is_a? Numeric
126
+ self.width = fixed_width
127
+ elsif use_autowidth
128
+ cell_width = cell.autowidth
129
+ self.width = cell_width unless (width || 0) > (cell_width || 0)
130
+ end
132
131
  end
133
132
 
134
133
  # Serialize this columns data to an xml string
135
134
  # @param [String] str
136
135
  # @return [String]
137
136
  def to_xml_string(str = '')
138
- str << '<col '
139
- serialized_attributes str
140
- str << '/>'
137
+ serialized_tag('col', str)
141
138
  end
142
139
 
143
140
  end
@@ -16,7 +16,7 @@ module Axlsx
16
16
  # Break will be passed to the created break object.
17
17
  # @see Break
18
18
  def add_break(options)
19
- @list << Break.new(options.merge(:max => 1048575, :man => true))
19
+ self << Break.new(options.merge(:max => 1048575, :man => true))
20
20
  last
21
21
  end
22
22
 
@@ -27,7 +27,7 @@ module Axlsx
27
27
  # </colBreaks>
28
28
  def to_xml_string(str='')
29
29
  return if empty?
30
- str << '<colBreaks count="' << @list.size.to_s << '" manualBreakCount="' << @list.size.to_s << '">'
30
+ str << ('<colBreaks count="' << size.to_s << '" manualBreakCount="' << size.to_s << '">')
31
31
  each { |brk| brk.to_xml_string(str) }
32
32
  str << '</colBreaks>'
33
33
  end
@@ -1,6 +1,6 @@
1
1
  module Axlsx
2
2
 
3
- # The cols class manages the col object used to manage column widths.
3
+ # The cols class manages the col object used to manage column widths.
4
4
  # This is where the magic happens with autowidth
5
5
  class Cols < SimpleTypedList
6
6
 
@@ -10,11 +10,14 @@ module Axlsx
10
10
  @worksheet = worksheet
11
11
  end
12
12
 
13
+ # Serialize the Cols object
14
+ # @param [String] str
15
+ # @return [String]
13
16
  def to_xml_string(str = '')
14
17
  return if empty?
15
18
  str << '<cols>'
16
19
  each { |item| item.to_xml_string(str) }
17
- str << '</cols>'
20
+ str << '</cols>'
18
21
  end
19
22
  end
20
23
  end
@@ -24,11 +24,10 @@ module Axlsx
24
24
  string_attr_accessor :text, :author
25
25
  boolean_attr_accessor :visible
26
26
 
27
- # The owning Comments object
27
+ # The owning Comments object
28
28
  # @return [Comments]
29
29
  attr_reader :comments
30
30
 
31
-
32
31
  # The string based cell position reference (e.g. 'A1') that determines the positioning of this comment
33
32
  # @return [String|Cell]
34
33
  attr_reader :ref
@@ -53,7 +52,7 @@ module Axlsx
53
52
 
54
53
  # @see ref
55
54
  def ref=(v)
56
- Axlsx::DataTypeValidator.validate "Comment.ref", [String, Cell], v
55
+ Axlsx::DataTypeValidator.validate :comment_ref, [String, Cell], v
57
56
  @ref = v if v.is_a?(String)
58
57
  @ref = v.r if v.is_a?(Cell)
59
58
  end
@@ -63,15 +62,15 @@ module Axlsx
63
62
  # @return [String]
64
63
  def to_xml_string(str = "")
65
64
  author = @comments.authors[author_index]
66
- str << '<comment ref="' << ref << '" authorId="' << author_index.to_s << '">'
65
+ str << ('<comment ref="' << ref << '" authorId="' << author_index.to_s << '">')
67
66
  str << '<text>'
68
67
  unless author.to_s == ""
69
68
  str << '<r><rPr><b/><color indexed="81"/></rPr>'
70
- str << "<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>"
69
+ str << ("<t>" << ::CGI.escapeHTML(author.to_s) << ":\n</t></r>")
71
70
  end
72
71
  str << '<r>'
73
72
  str << '<rPr><color indexed="81"/></rPr>'
74
- str << '<t>' << ::CGI.escapeHTML(text) << '</t></r></text>'
73
+ str << ('<t>' << ::CGI.escapeHTML(text) << '</t></r></text>')
75
74
  str << '</comment>'
76
75
  end
77
76
 
@@ -42,23 +42,22 @@ module Axlsx
42
42
  raise ArgumentError, "Comment require an author" unless options[:author]
43
43
  raise ArgumentError, "Comment requires text" unless options[:text]
44
44
  raise ArgumentError, "Comment requires ref" unless options[:ref]
45
- @list << Comment.new(self, options)
46
- yield @list.last if block_given?
47
- @list.last
45
+ self << Comment.new(self, options)
46
+ yield last if block_given?
47
+ last
48
48
  end
49
49
 
50
50
  # A sorted list of the unique authors in the contained comments
51
51
  # @return [Array]
52
52
  def authors
53
- @list.map { |comment| comment.author.to_s }.uniq.sort
53
+ map { |comment| comment.author.to_s }.uniq.sort
54
54
  end
55
55
 
56
56
  # The relationships required by this object
57
57
  # @return [Array]
58
58
  def relationships
59
59
  [Relationship.new(self, VML_DRAWING_R, "../#{vml_drawing.pn}"),
60
- Relationship.new(self, COMMENT_R, "../#{pn}"),
61
- Relationship.new(self, COMMENT_R_NULL, "NULL")]
60
+ Relationship.new(self, COMMENT_R, "../#{pn}")]
62
61
  end
63
62
 
64
63
  # serialize the object
@@ -66,14 +65,12 @@ module Axlsx
66
65
  # @return [String]
67
66
  def to_xml_string(str="")
68
67
  str << '<?xml version="1.0" encoding="UTF-8"?>'
69
- str << '<comments xmlns="' << XML_NS << '">'
70
- str << '<authors>'
68
+ str << ('<comments xmlns="' << XML_NS << '"><authors>')
71
69
  authors.each do |author|
72
- str << '<author>' << author.to_s << '</author>'
70
+ str << ('<author>' << author.to_s << '</author>')
73
71
  end
74
- str << '</authors>'
75
- str << '<commentList>'
76
- @list.each do |comment|
72
+ str << '</authors><commentList>'
73
+ each do |comment|
77
74
  comment.to_xml_string str
78
75
  end
79
76
  str << '</commentList></comments>'
@@ -74,7 +74,7 @@ module Axlsx
74
74
  # @param [String] str
75
75
  # @return [String]
76
76
  def to_xml_string(str = '')
77
- str << '<conditionalFormatting sqref="' << sqref << '">'
77
+ str << ('<conditionalFormatting sqref="' << sqref << '">')
78
78
  str << rules.collect{ |rule| rule.to_xml_string }.join(' ')
79
79
  str << '</conditionalFormatting>'
80
80
  end
@@ -210,7 +210,7 @@ module Axlsx
210
210
  str << '<cfRule '
211
211
  serialized_attributes str
212
212
  str << '>'
213
- str << '<formula>' << [*self.formula].join('</formula><formula>') << '</formula>' if @formula
213
+ str << ('<formula>' << [*self.formula].join('</formula><formula>') << '</formula>') if @formula
214
214
  @color_scale.to_xml_string(str) if @color_scale && @type == :colorScale
215
215
  @data_bar.to_xml_string(str) if @data_bar && @type == :dataBar
216
216
  @icon_set.to_xml_string(str) if @icon_set && @type == :iconSet
@@ -107,12 +107,10 @@ module Axlsx
107
107
  # @param [String] str
108
108
  # @return [String]
109
109
  def to_xml_string(str="")
110
- str << '<dataBar '
111
- serialized_attributes str
112
- str << '>'
113
- value_objects.to_xml_string(str)
114
- self.color.to_xml_string(str)
115
- str << '</dataBar>'
110
+ serialized_tag('dataBar', str) do
111
+ value_objects.to_xml_string(str)
112
+ self.color.to_xml_string(str)
113
+ end
116
114
  end
117
115
 
118
116
  private
@@ -33,7 +33,7 @@ module Axlsx
33
33
  end
34
34
 
35
35
  # instance values that must be serialized as their own elements - e.g. not attributes.
36
- CHILD_ELEMENTS = [:formula1, :formula2]
36
+ CHILD_ELEMENTS = [:formula1, :formula2].freeze
37
37
 
38
38
  # Formula1
39
39
  # Available for type whole, decimal, date, time, textLength, list, custom
@@ -216,10 +216,12 @@ module Axlsx
216
216
  valid_attributes = get_valid_attributes
217
217
 
218
218
  str << '<dataValidation '
219
- str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' if (valid_attributes.include?(key.to_sym) and not CHILD_ELEMENTS.include?(key.to_sym)) }.join(' ')
219
+ str << instance_values.map do |key, value|
220
+ '' << key << '="' << Axlsx.booleanize(value).to_s << '"' if (valid_attributes.include?(key.to_sym) && !CHILD_ELEMENTS.include?(key.to_sym))
221
+ end.join(' ')
220
222
  str << '>'
221
- str << '<formula1>' << self.formula1 << '</formula1>' if @formula1 and valid_attributes.include?(:formula1)
222
- str << '<formula2>' << self.formula2 << '</formula2>' if @formula2 and valid_attributes.include?(:formula2)
223
+ str << ('<formula1>' << self.formula1 << '</formula1>') if @formula1 and valid_attributes.include?(:formula1)
224
+ str << ('<formula2>' << self.formula2 << '</formula2>') if @formula2 and valid_attributes.include?(:formula2)
223
225
  str << '</dataValidation>'
224
226
  end
225
227