axlsx 1.1.0 → 1.2.0

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 (214) hide show
  1. data/.yardopts +5 -2
  2. data/CHANGELOG.md +78 -0
  3. data/LICENSE +1 -1
  4. data/README.md +132 -331
  5. data/Rakefile +17 -5
  6. data/examples/basic_charts.rb +54 -0
  7. data/examples/chart_colors.rb +88 -0
  8. data/examples/conditional_formatting/example_conditional_formatting.rb +72 -0
  9. data/examples/conditional_formatting/getting_barred.rb +37 -0
  10. data/examples/conditional_formatting/hitting_the_high_notes.rb +37 -0
  11. data/examples/conditional_formatting/scaled_colors.rb +39 -0
  12. data/examples/conditional_formatting/stop_and_go.rb +37 -0
  13. data/examples/data_validation.rb +50 -0
  14. data/examples/example.rb +300 -152
  15. data/examples/example.xlsx +0 -0
  16. data/examples/example_streamed.xlsx +0 -0
  17. data/examples/extractive.pdf +0 -0
  18. data/examples/extractive.rb +45 -0
  19. data/examples/no-use_autowidth.xlsx +0 -0
  20. data/examples/sample.png +0 -0
  21. data/examples/scraping_html.rb +91 -0
  22. data/examples/shared_strings_example.xlsx +0 -0
  23. data/examples/sheet_protection.rb +10 -0
  24. data/examples/sheet_view.rb +34 -0
  25. data/examples/skydrive/real_example.rb +63 -0
  26. data/examples/two_cell_anchor_image.rb +11 -0
  27. data/lib/axlsx/content_type/content_type.rb +2 -0
  28. data/lib/axlsx/content_type/default.rb +30 -15
  29. data/lib/axlsx/content_type/override.rb +29 -14
  30. data/lib/axlsx/doc_props/app.rb +161 -104
  31. data/lib/axlsx/doc_props/core.rb +9 -5
  32. data/lib/axlsx/drawing/ax_data_source.rb +26 -0
  33. data/lib/axlsx/drawing/axis.rb +106 -35
  34. data/lib/axlsx/drawing/bar_3D_chart.rb +49 -45
  35. data/lib/axlsx/drawing/bar_series.rb +25 -7
  36. data/lib/axlsx/drawing/cat_axis.rb +50 -22
  37. data/lib/axlsx/drawing/chart.rb +69 -56
  38. data/lib/axlsx/drawing/d_lbls.rb +100 -0
  39. data/lib/axlsx/drawing/drawing.rb +28 -12
  40. data/lib/axlsx/drawing/graphic_frame.rb +2 -1
  41. data/lib/axlsx/drawing/line_3D_chart.rb +3 -10
  42. data/lib/axlsx/drawing/line_series.rb +20 -4
  43. data/lib/axlsx/drawing/num_data.rb +52 -0
  44. data/lib/axlsx/drawing/num_data_source.rb +61 -0
  45. data/lib/axlsx/drawing/num_val.rb +32 -0
  46. data/lib/axlsx/drawing/pic.rb +44 -4
  47. data/lib/axlsx/drawing/pie_3D_chart.rb +10 -7
  48. data/lib/axlsx/drawing/pie_series.rb +18 -4
  49. data/lib/axlsx/drawing/scatter_chart.rb +12 -18
  50. data/lib/axlsx/drawing/scatter_series.rb +28 -2
  51. data/lib/axlsx/drawing/ser_axis.rb +1 -1
  52. data/lib/axlsx/drawing/series.rb +1 -1
  53. data/lib/axlsx/drawing/str_data.rb +42 -0
  54. data/lib/axlsx/drawing/str_val.rb +33 -0
  55. data/lib/axlsx/drawing/title.rb +21 -9
  56. data/lib/axlsx/drawing/two_cell_anchor.rb +46 -9
  57. data/lib/axlsx/drawing/view_3D.rb +44 -31
  58. data/lib/axlsx/drawing/vml_drawing.rb +42 -0
  59. data/lib/axlsx/drawing/vml_shape.rb +125 -0
  60. data/lib/axlsx/package.rb +44 -16
  61. data/lib/axlsx/rels/relationship.rb +3 -3
  62. data/lib/axlsx/rels/relationships.rb +1 -11
  63. data/lib/axlsx/stylesheet/color.rb +0 -1
  64. data/lib/axlsx/stylesheet/dxf.rb +79 -0
  65. data/lib/axlsx/stylesheet/font.rb +2 -1
  66. data/lib/axlsx/stylesheet/gradient_fill.rb +1 -1
  67. data/lib/axlsx/stylesheet/styles.rb +143 -50
  68. data/lib/axlsx/stylesheet/table_style.rb +3 -3
  69. data/lib/axlsx/stylesheet/xf.rb +2 -0
  70. data/lib/axlsx/util/constants.rb +36 -0
  71. data/lib/axlsx/util/simple_typed_list.rb +15 -21
  72. data/lib/axlsx/util/validators.rb +122 -5
  73. data/lib/axlsx/version.rb +2 -7
  74. data/lib/axlsx/workbook/defined_name.rb +174 -0
  75. data/lib/axlsx/workbook/defined_names.rb +21 -0
  76. data/lib/axlsx/workbook/shared_strings_table.rb +12 -13
  77. data/lib/axlsx/workbook/workbook.rb +71 -13
  78. data/lib/axlsx/workbook/worksheet/auto_filter.rb +34 -0
  79. data/lib/axlsx/workbook/worksheet/cell.rb +45 -36
  80. data/lib/axlsx/workbook/worksheet/cfvo.rb +62 -0
  81. data/lib/axlsx/workbook/worksheet/col.rb +17 -1
  82. data/lib/axlsx/workbook/worksheet/color_scale.rb +76 -0
  83. data/lib/axlsx/workbook/worksheet/cols.rb +20 -0
  84. data/lib/axlsx/workbook/worksheet/comment.rb +101 -0
  85. data/lib/axlsx/workbook/worksheet/comments.rb +85 -0
  86. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +82 -0
  87. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +216 -0
  88. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +25 -0
  89. data/lib/axlsx/workbook/worksheet/data_bar.rb +97 -0
  90. data/lib/axlsx/workbook/worksheet/data_validation.rb +245 -0
  91. data/lib/axlsx/workbook/worksheet/data_validations.rb +28 -0
  92. data/lib/axlsx/workbook/worksheet/dimension.rb +65 -0
  93. data/lib/axlsx/workbook/worksheet/icon_set.rb +83 -0
  94. data/lib/axlsx/workbook/worksheet/merged_cells.rb +35 -0
  95. data/lib/axlsx/workbook/worksheet/page_setup.rb +113 -0
  96. data/lib/axlsx/workbook/worksheet/pane.rb +144 -0
  97. data/lib/axlsx/workbook/worksheet/print_options.rb +63 -0
  98. data/lib/axlsx/workbook/worksheet/protected_range.rb +46 -0
  99. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +34 -0
  100. data/lib/axlsx/workbook/worksheet/row.rb +69 -12
  101. data/lib/axlsx/workbook/worksheet/selection.rb +111 -0
  102. data/lib/axlsx/workbook/worksheet/sheet_data.rb +25 -0
  103. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +24 -0
  104. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +224 -0
  105. data/lib/axlsx/workbook/worksheet/sheet_view.rb +379 -0
  106. data/lib/axlsx/workbook/worksheet/table.rb +3 -3
  107. data/lib/axlsx/workbook/worksheet/tables.rb +31 -0
  108. data/lib/axlsx/workbook/worksheet/worksheet.rb +379 -233
  109. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +57 -0
  110. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +64 -0
  111. data/lib/axlsx.rb +31 -16
  112. data/test/benchmark.rb +30 -38
  113. data/test/content_type/tc_content_type.rb +1 -6
  114. data/test/doc_props/tc_app.rb +31 -1
  115. data/test/doc_props/tc_core.rb +3 -1
  116. data/test/drawing/tc_axis.rb +46 -3
  117. data/test/drawing/tc_bar_3D_chart.rb +12 -12
  118. data/test/drawing/tc_bar_series.rb +17 -13
  119. data/test/drawing/tc_cat_axis.rb +3 -3
  120. data/test/drawing/tc_cat_axis_data.rb +23 -13
  121. data/test/drawing/tc_chart.rb +29 -11
  122. data/test/drawing/tc_d_lbls.rb +47 -0
  123. data/test/drawing/tc_data_source.rb +17 -0
  124. data/test/drawing/tc_drawing.rb +11 -5
  125. data/test/drawing/tc_hyperlink.rb +4 -5
  126. data/test/drawing/tc_line_series.rb +9 -11
  127. data/test/drawing/tc_named_axis_data.rb +27 -0
  128. data/test/drawing/tc_num_data.rb +31 -0
  129. data/test/drawing/tc_num_val.rb +29 -0
  130. data/test/drawing/tc_pic.rb +22 -2
  131. data/test/drawing/tc_pie_3D_chart.rb +4 -8
  132. data/test/drawing/tc_pie_series.rb +11 -13
  133. data/test/drawing/tc_scatter_chart.rb +6 -1
  134. data/test/drawing/tc_scatter_series.rb +6 -5
  135. data/test/drawing/tc_series.rb +1 -1
  136. data/test/drawing/tc_str_data.rb +18 -0
  137. data/test/drawing/tc_str_val.rb +21 -0
  138. data/test/drawing/tc_title.rb +16 -0
  139. data/test/drawing/tc_two_cell_anchor.rb +2 -3
  140. data/test/drawing/tc_view_3D.rb +18 -18
  141. data/test/drawing/tc_vml_drawing.rb +25 -0
  142. data/test/drawing/tc_vml_shape.rb +100 -0
  143. data/test/profile.rb +2 -1
  144. data/test/rels/tc_relationship.rb +1 -0
  145. data/test/stylesheet/tc_dxf.rb +81 -0
  146. data/test/stylesheet/tc_gradient_fill.rb +8 -0
  147. data/test/stylesheet/tc_pattern_fill.rb +7 -1
  148. data/test/stylesheet/tc_styles.rb +163 -3
  149. data/test/stylesheet/tc_table_style.rb +8 -0
  150. data/test/stylesheet/tc_table_style_element.rb +10 -1
  151. data/test/tc_helper.rb +1 -0
  152. data/test/tc_package.rb +93 -17
  153. data/test/util/tc_simple_typed_list.rb +13 -0
  154. data/test/util/tc_validators.rb +95 -9
  155. data/test/workbook/tc_defined_name.rb +41 -0
  156. data/test/workbook/tc_workbook.rb +5 -3
  157. data/test/workbook/worksheet/table/tc_table.rb +3 -11
  158. data/test/workbook/worksheet/tc_cell.rb +52 -18
  159. data/test/workbook/worksheet/tc_cfvo.rb +31 -0
  160. data/test/workbook/worksheet/tc_col.rb +9 -0
  161. data/test/workbook/worksheet/tc_color_scale.rb +29 -0
  162. data/test/workbook/worksheet/tc_comment.rb +57 -0
  163. data/test/workbook/worksheet/tc_comments.rb +57 -0
  164. data/test/workbook/worksheet/tc_conditional_formatting.rb +217 -0
  165. data/test/workbook/worksheet/tc_data_bar.rb +39 -0
  166. data/test/workbook/worksheet/tc_data_validation.rb +265 -0
  167. data/test/workbook/worksheet/tc_date_time_converter.rb +11 -5
  168. data/test/workbook/worksheet/tc_icon_set.rb +45 -0
  169. data/test/workbook/worksheet/tc_page_setup.rb +138 -0
  170. data/test/workbook/worksheet/tc_pane.rb +94 -0
  171. data/test/workbook/worksheet/tc_print_options.rb +72 -0
  172. data/test/workbook/worksheet/tc_protected_range.rb +17 -0
  173. data/test/workbook/worksheet/tc_row.rb +44 -13
  174. data/test/workbook/worksheet/tc_selection.rb +94 -0
  175. data/test/workbook/worksheet/tc_sheet_protection.rb +117 -0
  176. data/test/workbook/worksheet/tc_sheet_view.rb +214 -0
  177. data/test/workbook/worksheet/tc_worksheet.rb +147 -50
  178. metadata +216 -148
  179. data/examples/example.csv +0 -1000
  180. data/examples/example.rb~ +0 -112
  181. data/lib/axlsx/drawing/cat_axis_data.rb +0 -34
  182. data/lib/axlsx/drawing/hlink_click.rb~ +0 -0
  183. data/lib/axlsx/drawing/hyperlink.rb~ +0 -64
  184. data/lib/axlsx/drawing/named_axis_data.rb +0 -36
  185. data/lib/axlsx/drawing/picture_locking.rb~ +0 -36
  186. data/lib/axlsx/drawing/val_axis_data.rb +0 -27
  187. data/lib/axlsx/stylesheet/#num_fmt.rb# +0 -69
  188. data/lib/axlsx/util/cbf.rb +0 -333
  189. data/lib/axlsx/util/cfb.rb~ +0 -201
  190. data/lib/axlsx/util/ms_off_crypto.rb +0 -189
  191. data/lib/axlsx/util/ms_off_crypto.rb~ +0 -3
  192. data/lib/axlsx/util/ms_offcrypto.rb~ +0 -0
  193. data/lib/axlsx/util/parser.rb~ +0 -6
  194. data/lib/axlsx/util/storage.rb~ +0 -0
  195. data/lib/axlsx/workbook/shared_strings_table.rb~ +0 -69
  196. data/lib/axlsx/workbook/worksheet/col.rb~ +0 -0
  197. data/lib/axlsx/workbook/worksheet/shared_strings_table.rb~ +0 -0
  198. data/lib/axlsx/workbook/worksheet/table.rb~ +0 -97
  199. data/lib/schema/dc.xsd~ +0 -118
  200. data/lib/schema/dcterms.xsd~ +0 -331
  201. data/lib/schema/opc-coreProperties.xsd~ +0 -50
  202. data/test/#benchmark.txt# +0 -7
  203. data/test/#tc_helper.rb# +0 -3
  204. data/test/benchmark.rb~ +0 -0
  205. data/test/benchmark.txt +0 -6
  206. data/test/benchmark.txt~ +0 -6
  207. data/test/drawing/tc_val_axis_data.rb +0 -17
  208. data/test/example.csv +0 -1000
  209. data/test/example.xlsx +0 -0
  210. data/test/example_streamed.xlsx +0 -0
  211. data/test/tc_axlsx.rb~ +0 -0
  212. data/test/tc_helper.rb~ +0 -3
  213. data/test/workbook/worksheet/table/tc_table.rb~ +0 -72
  214. data/test/workbook/worksheet/tc_col.rb~ +0 -10
@@ -20,7 +20,7 @@ module Axlsx
20
20
  # @param [Regexp] regex The regular expression to evaluate
21
21
  # @param [Any] v The value to validate.
22
22
  def self.validate(name, regex, v)
23
- raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless (v.respond_to?(:=~) && v =~ regex)
23
+ raise ArgumentError, (ERR_REGEX % [v.inspect, regex.to_s]) unless (v.respond_to?(:to_s) && v.to_s.match(regex))
24
24
  end
25
25
  end
26
26
  # Validate that the class of the value provided is either an instance or the class of the allowed types and that any specified additional validation returns true.
@@ -45,6 +45,21 @@ module Axlsx
45
45
  true
46
46
  end
47
47
 
48
+
49
+ # Requires that the value can be converted to an integer
50
+ # @para, [Any] v the value to validate
51
+ # @raise [ArgumentError] raised if the value cannot be converted to an integer
52
+ def self.validate_integerish(v)
53
+ raise ArgumentError, (ERR_INTEGERISH % v.inspect) unless (v.respond_to?(:to_i) && v.to_i.is_a?(Integer))
54
+ end
55
+
56
+ # Requires that the value is between -54000000 and 54000000
57
+ # @param [Any] v The value validated
58
+ # @raise [ArgumentError] raised if the value cannot be converted to an integer between the allowed angle values for chart label rotation.
59
+ # @return [Boolean] true if the data is valid
60
+ def self.validate_angle(v)
61
+ raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v.to_i >= -5400000 && v.to_i <= 5400000)
62
+ end
48
63
  # Requires that the value is a Fixnum or Integer and is greater or equal to 0
49
64
  # @param [Any] v The value validated
50
65
  # @raise [ArgumentError] raised if the value is not a Fixnum or Integer value greater or equal to 0
@@ -87,6 +102,27 @@ module Axlsx
87
102
  DataTypeValidator.validate :float, Float, v
88
103
  end
89
104
 
105
+ # Requires that the value is a string containing a positive decimal number followed by one of the following units:
106
+ # "mm", "cm", "in", "pt", "pc", "pi"
107
+ def self.validate_number_with_unit(v)
108
+ RegexValidator.validate "number_with_unit", /\A[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)\Z/, v
109
+ end
110
+
111
+ # Requires that the value is an integer ranging from 10 to 400.
112
+ def self.validate_scale_10_400(v)
113
+ DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg >= 10 && arg <= 400 }
114
+ end
115
+
116
+ # Requires that the value is an integer ranging from 10 to 400 or 0.
117
+ def self.validate_scale_0_10_400(v)
118
+ DataTypeValidator.validate "page_scale", [Fixnum, Integer], v, lambda { |arg| arg == 0 || (arg >= 10 && arg <= 400) }
119
+ end
120
+
121
+ # Requires that the value is one of :default, :landscape, or :portrait.
122
+ def self.validate_page_orientation(v)
123
+ RestrictionValidator.validate "page_orientation", [:default, :landscape, :portrait], v
124
+ end
125
+
90
126
  # Requires that the value is valid pattern type.
91
127
  # valid pattern types must be one of :none, :solid, :mediumGray, :darkGray, :lightGray, :darkHorizontal, :darkVertical, :darkDown,
92
128
  # :darkUp, :darkGrid, :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, or :gray0625.
@@ -96,6 +132,45 @@ module Axlsx
96
132
  :darkTrellis, :lightHorizontal, :lightVertical, :lightDown, :lightUp, :lightGrid, :lightTrellis, :gray125, :gray0625], v
97
133
  end
98
134
 
135
+ # Requires that the value is one of the ST_TimePeriod types
136
+ # valid time period types are today, yesterday, tomorrow, last7Days,
137
+ # thisMonth, lastMonth, nextMonth, thisWeek, lastWeek, nextWeek
138
+ def self.validate_time_period_type(v)
139
+ RestrictionValidator.validate :time_period_type, [:today, :yesterday, :tomorrow, :last7Days, :thisMonth, :lastMonth, :nextMonth, :thisWeek, :lastWeek, :nextWeek], v
140
+ end
141
+
142
+ # Requires that the value is one of the valid ST_IconSet types
143
+ # Allowed values are: 3Arrows, 3ArrowsGray, 3Flags, 3TrafficLights1, 3TrafficLights2, 3Signs, 3Symbols, 3Symbols2, 4Arrows, 4ArrowsGray, 4RedToBlack, 4Rating, 4TrafficLights, 5Arrows, 5ArrowsGray, 5Rating, 5Quarters
144
+ def self.validate_icon_set(v)
145
+ RestrictionValidator.validate :iconSet, ["3Arrows", "3ArrowsGray", "3Flags", "3TrafficLights1", "3TrafficLights2", "3Signs", "3Symbols", "3Symbols2", "4Arrows", "4ArrowsGray", "4RedToBlack", "4Rating", "4TrafficLights", "5Arrows", "5ArrowsGray", "5Rating", "5Quarters"], v
146
+ end
147
+
148
+ # Requires that the value is valid conditional formatting type.
149
+ # valid types must be one of expression, cellIs, colorScale,
150
+ # dataBar, iconSet, top10, uniqueValues, duplicateValues,
151
+ # containsText, notContainsText, beginsWith, endsWith,
152
+ # containsBlanks, notContainsBlanks, containsErrors,
153
+ # notContainsErrors, timePeriod, aboveAverage
154
+ # @param [Any] v The value validated
155
+ def self.validate_conditional_formatting_type(v)
156
+ RestrictionValidator.validate :conditional_formatting_type, [:expression, :cellIs, :colorScale, :dataBar, :iconSet, :top10, :uniqueValues, :duplicateValues, :containsText, :notContainsText, :beginsWith, :endsWith, :containsBlanks, :notContainsBlanks, :containsErrors, :notContainsErrors, :timePeriod, :aboveAverage], v
157
+ end
158
+
159
+ # Requires thatt he value is a valid conditional formatting value object type.
160
+ # valid types must be one of num, percent, max, min, formula and percentile
161
+ def self.validate_conditional_formatting_value_object_type(v)
162
+ RestrictionValidator.validate :conditional_formatting_value_object_type, [:num, :percent, :max, :min, :formula, :percentile], v
163
+ end
164
+
165
+ # Requires that the value is valid conditional formatting operator.
166
+ # valid operators must be one of lessThan, lessThanOrEqual, equal,
167
+ # notEqual, greaterThanOrEqual, greaterThan, between, notBetween,
168
+ # containsText, notContains, beginsWith, endsWith
169
+ # @param [Any] v The value validated
170
+ def self.validate_conditional_formatting_operator(v)
171
+ RestrictionValidator.validate :conditional_formatting_type, [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween, :containsText, :notContains, :beginsWith, :endsWith], v
172
+ end
173
+
99
174
  # Requires that the value is a gradient_type.
100
175
  # valid types are :linear and :path
101
176
  # @param [Any] v The value validated
@@ -106,7 +181,7 @@ module Axlsx
106
181
  # Requires that the value is a valid scatterStyle
107
182
  # must be one of :none | :line | :lineMarker | :marker | :smooth | :smoothMarker
108
183
  # must be one of "none" | "line" | "lineMarker" | "marker" | "smooth" | "smoothMarker"
109
- # @param [Symbol|String] the value to validate
184
+ # @param [Symbol|String] v the value to validate
110
185
  def self.validate_scatter_style(v)
111
186
  Axlsx::RestrictionValidator.validate "ScatterChart.scatterStyle", [:none, :line, :lineMarker, :marker, :smooth, :smoothMarker], v.to_sym
112
187
  end
@@ -125,17 +200,17 @@ module Axlsx
125
200
  end
126
201
 
127
202
  # Requires that the value is a valid content_type
128
- # TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT are allowed
203
+ # TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, DRAWING_CT, COMMENT_CT are allowed
129
204
  # @param [Any] v The value validated
130
205
  def self.validate_content_type(v)
131
- RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT], v
206
+ RestrictionValidator.validate :content_type, [TABLE_CT, WORKBOOK_CT, APP_CT, RELS_CT, STYLES_CT, XML_CT, WORKSHEET_CT, SHARED_STRINGS_CT, CORE_CT, CHART_CT, JPEG_CT, GIF_CT, PNG_CT, DRAWING_CT, COMMENT_CT, VML_DRAWING_CT], v
132
207
  end
133
208
 
134
209
  # Requires that the value is a valid relationship_type
135
210
  # XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R, HYPERLINK_R, SHARED_STRINGS_R are allowed
136
211
  # @param [Any] v The value validated
137
212
  def self.validate_relationship_type(v)
138
- RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R, HYPERLINK_R, SHARED_STRINGS_R], v
213
+ RestrictionValidator.validate :relationship_type, [XML_NS_R, TABLE_R, WORKBOOK_R, WORKSHEET_R, APP_R, RELS_R, CORE_R, STYLES_R, CHART_R, DRAWING_R, IMAGE_R, HYPERLINK_R, SHARED_STRINGS_R, COMMENT_R, VML_DRAWING_R, COMMENT_R_NULL], v
139
214
  end
140
215
 
141
216
  # Requires that the value is a valid table element type
@@ -145,4 +220,46 @@ module Axlsx
145
220
  RestrictionValidator.validate :table_element_type, [:wholeTable, :headerRow, :totalRow, :firstColumn, :lastColumn, :firstRowStripe, :secondRowStripe, :firstColumnStripe, :secondColumnStripe, :firstHeaderCell, :lastHeaderCell, :firstTotalCell, :lastTotalCell, :firstSubtotalColumn, :secondSubtotalColumn, :thirdSubtotalColumn, :firstSubtotalRow, :secondSubtotalRow, :thirdSubtotalRow, :blankRow, :firstColumnSubheading, :secondColumnSubheading, :thirdColumnSubheading, :firstRowSubheading, :secondRowSubheading, :thirdRowSubheading, :pageFieldLabels, :pageFieldValues], v
146
221
  end
147
222
 
223
+ # Requires that the value is a valid data_validation_error_style
224
+ # :information, :stop, :warning
225
+ # @param [Any] v The value validated
226
+ def self.validate_data_validation_error_style(v)
227
+ RestrictionValidator.validate :validate_data_validation_error_style, [:information, :stop, :warning], v
228
+ end
229
+
230
+ # Requires that the value is valid data validation operator.
231
+ # valid operators must be one of lessThan, lessThanOrEqual, equal,
232
+ # notEqual, greaterThanOrEqual, greaterThan, between, notBetween
233
+ # @param [Any] v The value validated
234
+ def self.validate_data_validation_operator(v)
235
+ RestrictionValidator.validate :data_validation_operator, [:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween], v
236
+ end
237
+
238
+ # Requires that the value is valid data validation type.
239
+ # valid types must be one of custom, data, decimal, list, none, textLength, time, whole
240
+ # @param [Any] v The value validated
241
+ def self.validate_data_validation_type(v)
242
+ RestrictionValidator.validate :data_validation_type, [:custom, :data, :decimal, :list, :none, :textLength, :time, :whole], v
243
+ end
244
+
245
+ # Requires that the value is a valid sheet view type.
246
+ # valid types must be one of normal, page_break_preview, page_layout
247
+ # @param [Any] v The value validated
248
+ def self.validate_sheet_view_type(v)
249
+ RestrictionValidator.validate :sheet_view_type, [:normal, :page_break_preview, :page_layout], v
250
+ end
251
+
252
+ # Requires that the value is a valid active pane type.
253
+ # valid types must be one of bottom_left, bottom_right, top_left, top_right
254
+ # @param [Any] v The value validated
255
+ def self.validate_pane_type(v)
256
+ RestrictionValidator.validate :active_pane_type, [:bottom_left, :bottom_right, :top_left, :top_right], v
257
+ end
258
+
259
+ # Requires that the value is a valid split state type.
260
+ # valid types must be one of frozen, frozen_split, split
261
+ # @param [Any] v The value validated
262
+ def self.validate_split_state_type(v)
263
+ RestrictionValidator.validate :split_state_type, [:frozen, :frozen_split, :split], v
264
+ end
148
265
  end
data/lib/axlsx/version.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Axlsx
3
-
4
- # The version of the gem
5
- # When using bunle exec rake and referencing the gem on github or locally
6
- # it will use the gemspec, which preloads this constant for the gem's version.
7
- # We check to make sure that it has not already been loaded
8
- VERSION="1.1.0" unless defined? Axlsx::VERSION
9
-
3
+ # The current version
4
+ VERSION="1.2.0"
10
5
  end
@@ -0,0 +1,174 @@
1
+ # <definedNames>
2
+ # <definedName name="_xlnm.Print_Titles" localSheetId="0">Sheet1!$1:$1</definedName>
3
+ # </definedNames>
4
+
5
+ #<xsd:complexType name="CT_DefinedName">
6
+ # <xsd:simpleContent>
7
+ # <xsd:extension base="ST_Formula">
8
+ # <xsd:attribute name="name" type="s:ST_Xstring" use="required"/>
9
+ # <xsd:attribute name="comment" type="s:ST_Xstring" use="optional"/>
10
+ # <xsd:attribute name="customMenu" type="s:ST_Xstring" use="optional"/>
11
+ # <xsd:attribute name="description" type="s:ST_Xstring" use="optional"/>
12
+ # <xsd:attribute name="help" type="s:ST_Xstring" use="optional"/>
13
+ # <xsd:attribute name="statusBar" type="s:ST_Xstring" use="optional"/>
14
+ # <xsd:attribute name="localSheetId" type="xsd:unsignedInt" use="optional"/>
15
+ # <xsd:attribute name="hidden" type="xsd:boolean" use="optional" default="false"/>
16
+ # <xsd:attribute name="function" type="xsd:boolean" use="optional" default="false"/>
17
+ # <xsd:attribute name="vbProcedure" type="xsd:boolean" use="optional" default="false"/>
18
+ # <xsd:attribute name="xlm" type="xsd:boolean" use="optional" default="false"/>
19
+ # <xsd:attribute name="functionGroupId" type="xsd:unsignedInt" use="optional"/>
20
+ # <xsd:attribute name="shortcutKey" type="s:ST_Xstring" use="optional"/>
21
+ # <xsd:attribute name="publishToServer" type="xsd:boolean" use="optional" default="false"/>
22
+ # <xsd:attribute name="workbookParameter" type="xsd:boolean" use="optional" default="false"/>
23
+ # </xsd:extenstion>
24
+ # </xsd:simpleContent>
25
+
26
+ module Axlsx
27
+ # This element defines the defined names that are defined within this workbook.
28
+ # Defined names are descriptive text that is used to represents a cell, range of cells, formula, or constant value.
29
+ # Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30.
30
+ # A defined name in a formula can make it easier to understand the purpose of the formula.
31
+ # @example
32
+ # The formula =SUM(FirstQuarterSales) might be easier to identify than =SUM(C20:C30
33
+ #
34
+ # Names are available to any sheet.
35
+ # @example
36
+ # If the name ProjectedSales refers to the range A20:A30 on the first worksheet in a workbook,
37
+ # you can use the name ProjectedSales on any other sheet in the same workbook to refer to range A20:A30 on the first worksheet.
38
+ # Names can also be used to represent formulas or values that do not change (constants).
39
+ #
40
+ # @example
41
+ # The name SalesTax can be used to represent the sales tax amount (such as 6.2 percent) applied to sales transactions.
42
+ # You can also link to a defined name in another workbook, or define a name that refers to cells in another workbook.
43
+ #
44
+ # @example
45
+ # The formula =SUM(Sales.xls!ProjectedSales) refers to the named range ProjectedSales in the workbook named Sales.
46
+ # A compliant producer or consumer considers a defined name in the range A1-XFD1048576 to be an error.
47
+ # All other names outside this range can be defined as names and overrides a cell reference if an ambiguity exists.
48
+ #
49
+ # @example
50
+ # For clarification: LOG10 is always a cell reference, LOG10() is always formula, LOGO1000 can be a defined name that overrides a cell reference.
51
+ class DefinedName
52
+ # creates a new DefinedName.
53
+ # @param [String] formula - the formula the defined name references
54
+ # @param [Hash] options - A hash of key/value pairs that will be mapped to this instances attributes.
55
+ #
56
+ # @option [String] name - Specifies the name that appears in the user interface for the defined name.
57
+ # This attribute is required.
58
+ # The following built-in names are defined in this SpreadsheetML specification:
59
+ # Print
60
+ # _xlnm.Print_Area: this defined name specifies the workbook's print area.
61
+ # _xlnm.Print_Titles: this defined name specifies the row(s) or column(s) to repeat
62
+ # the top of each printed page.
63
+ # Filter & Advanced Filter
64
+ # _xlnm.Criteria: this defined name refers to a range containing the criteria values
65
+ # to be used in applying an advanced filter to a range of data.
66
+ # _xlnm._FilterDatabase: can be one of the following
67
+ # a. this defined name refers to a range to which an advanced filter has been
68
+ # applied. This represents the source data range, unfiltered.
69
+ # b. This defined name refers to a range to which an AutoFilter has been
70
+ # applied.
71
+ # _xlnm.Extract: this defined name refers to the range containing the filtered output
72
+ # values resulting from applying an advanced filter criteria to a source range.
73
+ # Miscellaneous
74
+ # _xlnm.Consolidate_Area: the defined name refers to a consolidation area.
75
+ # _xlnm.Database: the range specified in the defined name is from a database data source.
76
+ # _xlnm.Sheet_Title: the defined name refers to a sheet title.
77
+ # @option [String] comment - A comment to optionally associate with the name
78
+ # @option [String] custom_menu - The menu text for the defined name
79
+ # @option [String] description - An optional description for the defined name
80
+ # @option [String] help - The help topic to display for this defined name
81
+ # @option [String] status_bar - The text to display on the application status bar when this defined name has focus
82
+ # @option [String] local_sheet_id - Specifies the sheet index in this workbook where data from an external reference is displayed
83
+ # @option [Boolean] hidden - Specifies a boolean value that indicates whether the defined name is hidden in the user interface.
84
+ # @option [Boolean] function - Specifies a boolean value that indicates that the defined name refers to a user-defined function.
85
+ # This attribute is used when there is an add-in or other code project associated with the file.
86
+ # @option [Boolean] vb_proceedure - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code.
87
+ # @option [Boolean] xlm - Specifies a boolean value that indicates whether the defined name is related to an external function, command, or other executable code.
88
+ # @option [Integer] function_group_id - Specifies the function group index if the defined name refers to a function.
89
+ # The function group defines the general category for the function.
90
+ # This attribute is used when there is an add-in or other code project associated with the file.
91
+ # See Open Office XML Part 1 for more info.
92
+ # @option [String] short_cut_key - Specifies the keyboard shortcut for the defined name.
93
+ # @option [Boolean] publish_to_server - Specifies a boolean value that indicates whether the defined name is included in the
94
+ # version of the workbook that is published to or rendered on a Web or application server.
95
+ # @option [Boolean] workbook_parameter - Specifies a boolean value that indicates that the name is used as a workbook parameter on a
96
+ # version of the workbook that is published to or rendered on a Web or application server.
97
+ def initialize(formula, options={})
98
+ @formula = formula
99
+ options.each do |o|
100
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
101
+ end
102
+ end
103
+ attr_reader :local_sheet_id
104
+
105
+ # The local sheet index (0-based)
106
+ # @param [Integer] value the unsinged integer index of the sheet this defined_name applies to.
107
+ def local_sheet_id=(value)
108
+ Axlsx::validate_unsigned_int(value)
109
+ @local_sheet_id = value
110
+ end
111
+
112
+ # string attributes that will be added when this class is evaluated
113
+ STRING_ATTRIBUTES = [:short_cut_key, :status_bar, :help, :description, :custom_menu, :comment]
114
+
115
+ # boolean attributes that will be added when this class is evaluated
116
+ BOOLEAN_ATTRIBUTES = [:workbook_parameter, :publish_to_server, :xlm, :vb_proceedure, :function, :hidden]
117
+
118
+ # Dynamically create string attribute accessors
119
+ STRING_ATTRIBUTES.each do |attr|
120
+ class_eval %{
121
+ # The #{attr} attribute reader
122
+ # @return [String]
123
+ attr_reader :#{attr}
124
+
125
+ # The #{attr} writer
126
+ # @param [String] value The value to assign to #{attr}
127
+ # @return [String]
128
+ def #{attr}=(value)
129
+ Axlsx::validate_string(value)
130
+ @#{attr}= value
131
+ end
132
+ }
133
+ end
134
+
135
+ # Dynamically create boolean attribute accessors
136
+ BOOLEAN_ATTRIBUTES.each do |attr|
137
+ class_eval %{
138
+ # The #{attr} attribute reader
139
+ # @return [Boolean]
140
+ attr_reader :#{attr}
141
+
142
+ # The #{attr} writer
143
+ # @param [Boolean] value The value to assign to #{attr}
144
+ # @return [Boolean]
145
+ def #{attr}=(value)
146
+ Axlsx::validate_boolean(value)
147
+ @#{attr} = value
148
+ end
149
+ }
150
+ end
151
+
152
+ attr_reader :name
153
+ # The name of this defined name. Please refer to the class documentation for more information
154
+ def name=(value)
155
+ Axlsx::RestrictionValidator.validate 'DefinedName.name', %w(_xlnm.Print_Area _xlnm.Print_Titles _xlnm.Criteria _xlnm._FilterDatabase _xlnm.Extract _xlnm.Consolidate_Area _xlnm.Database _xlnm.Sheet_Title), value
156
+ @name = value
157
+ end
158
+
159
+ # The formula this defined name references
160
+ attr_reader :formula
161
+
162
+ def to_xml_string(str='')
163
+ raise ArgumentError, 'you must specify the name for this defined name. Please read the documentation for Axlsx::DefinedName for more details' unless name
164
+ str << '<definedName'
165
+ instance_values.each do |name, value|
166
+ unless name == 'formula'
167
+ str << ' ' << Axlsx::camel(name, false) << "='#{value}'"
168
+ end
169
+ end
170
+ str << '>' << @formula
171
+ str << '</definedName>'
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,21 @@
1
+ module Axlsx
2
+ # a simple types list of DefinedName objects
3
+ class DefinedNames < SimpleTypedList
4
+
5
+ # creates the DefinedNames object
6
+ def initialize
7
+ super DefinedName
8
+ end
9
+
10
+ # Serialize to xml
11
+ # @param [String] str
12
+ # @return [String]
13
+ def to_xml_string(str = '')
14
+ return if @list.empty?
15
+ str << "<definedNames>"
16
+ each { |defined_name| defined_name.to_xml_string(str) }
17
+ str << '</definedNames>'
18
+ end
19
+ end
20
+ end
21
+
@@ -29,11 +29,12 @@ module Axlsx
29
29
  # Creates a new Shared Strings Table agains an array of cells
30
30
  # @param [Array] cells This is an array of all of the cells in the workbook
31
31
  def initialize(cells)
32
- cells = cells.flatten.reject { |c| c.type != :string || c.value.nil? || c.value.start_with?('=') }
33
- @count = cells.size
34
- @unique_cells = []
32
+ @index = 0
33
+ @unique_cells = {}
35
34
  @shared_xml_string = ""
36
- resolve(cells)
35
+ shareable_cells = cells.flatten.select{ |cell| cell.plain_string? }
36
+ @count = shareable_cells.size
37
+ resolve(shareable_cells)
37
38
  end
38
39
 
39
40
  # Serializes the object
@@ -52,16 +53,14 @@ module Axlsx
52
53
  # @return [Array] unique cells
53
54
  def resolve(cells)
54
55
  cells.each do |cell|
55
- cell_hash = cell.shareable_hash
56
- index = @unique_cells.index do |item|
57
- item == cell_hash
58
- end
59
- if index == nil
60
- cell.send :ssti=, @unique_cells.size
61
- @shared_xml_string << '<si>' << cell.run_xml_string << '</si>'
62
- @unique_cells << cell_hash
63
- else
56
+ cell_hash = cell.value
57
+ if index = @unique_cells[cell_hash]
64
58
  cell.send :ssti=, index
59
+ else
60
+ cell.send :ssti=, @index
61
+ @shared_xml_string << '<si>' << cell.run_xml_string << '</si>'
62
+ @unique_cells[cell_hash] = @index
63
+ @index += 1
65
64
  end
66
65
  end
67
66
  end
@@ -1,15 +1,43 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Axlsx
3
-
3
+ require 'axlsx/workbook/worksheet/auto_filter.rb'
4
4
  require 'axlsx/workbook/worksheet/date_time_converter.rb'
5
+ require 'axlsx/workbook/worksheet/protected_range.rb'
6
+ require 'axlsx/workbook/worksheet/protected_ranges.rb'
5
7
  require 'axlsx/workbook/worksheet/cell.rb'
6
8
  require 'axlsx/workbook/worksheet/page_margins.rb'
9
+ require 'axlsx/workbook/worksheet/page_setup.rb'
10
+ require 'axlsx/workbook/worksheet/print_options.rb'
11
+ require 'axlsx/workbook/worksheet/cfvo.rb'
12
+ require 'axlsx/workbook/worksheet/color_scale.rb'
13
+ require 'axlsx/workbook/worksheet/data_bar.rb'
14
+ require 'axlsx/workbook/worksheet/icon_set.rb'
15
+ require 'axlsx/workbook/worksheet/conditional_formatting.rb'
16
+ require 'axlsx/workbook/worksheet/conditional_formatting_rule.rb'
17
+ require 'axlsx/workbook/worksheet/conditional_formattings.rb'
7
18
  require 'axlsx/workbook/worksheet/row.rb'
8
19
  require 'axlsx/workbook/worksheet/col.rb'
20
+ require 'axlsx/workbook/worksheet/cols.rb'
21
+ require 'axlsx/workbook/worksheet/comments.rb'
22
+ require 'axlsx/workbook/worksheet/comment.rb'
23
+ require 'axlsx/workbook/worksheet/merged_cells.rb'
24
+ require 'axlsx/workbook/worksheet/sheet_protection.rb'
25
+ require 'axlsx/workbook/worksheet/sheet_pr.rb'
26
+ require 'axlsx/workbook/worksheet/dimension.rb'
27
+ require 'axlsx/workbook/worksheet/sheet_data.rb'
28
+ require 'axlsx/workbook/worksheet/worksheet_drawing.rb'
29
+ require 'axlsx/workbook/worksheet/worksheet_comments.rb'
9
30
  require 'axlsx/workbook/worksheet/worksheet.rb'
10
31
  require 'axlsx/workbook/shared_strings_table.rb'
32
+ require 'axlsx/workbook/defined_name.rb'
33
+ require 'axlsx/workbook/defined_names.rb'
11
34
  require 'axlsx/workbook/worksheet/table.rb'
12
-
35
+ require 'axlsx/workbook/worksheet/tables.rb'
36
+ require 'axlsx/workbook/worksheet/data_validation.rb'
37
+ require 'axlsx/workbook/worksheet/data_validations.rb'
38
+ require 'axlsx/workbook/worksheet/sheet_view.rb'
39
+ require 'axlsx/workbook/worksheet/pane.rb'
40
+ require 'axlsx/workbook/worksheet/selection.rb'
13
41
  # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
14
42
  # The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
15
43
  #
@@ -76,6 +104,9 @@ require 'axlsx/workbook/worksheet/table.rb'
76
104
  # @return [SimpleTypedList]
77
105
  attr_reader :drawings
78
106
 
107
+ # pretty sure this two are always empty and can be removed.
108
+
109
+
79
110
  # A colllection of tables associated with this workbook
80
111
  # @note The recommended way to manage drawings is Worksheet#add_table
81
112
  # @see Worksheet#add_table
@@ -84,6 +115,23 @@ require 'axlsx/workbook/worksheet/table.rb'
84
115
  attr_reader :tables
85
116
 
86
117
 
118
+ # A collection of defined names for this workbook
119
+ # @note The recommended way to manage defined names is Workbook#add_defined_name
120
+ # @see DefinedName
121
+ # @return [DefinedNames]
122
+ def defined_names
123
+ @defined_names ||= DefinedNames.new
124
+ end
125
+
126
+ # A collection of comments associated with this workbook
127
+ # @note The recommended way to manage comments is WOrksheet#add_comment
128
+ # @see Worksheet#add_comment
129
+ # @see Comment
130
+ # @return [Comments]
131
+ def comments
132
+ worksheets.map { |sheet| sheet.comments }.compact
133
+ end
134
+
87
135
  # The styles associated with this workbook
88
136
  # @note The recommended way to manage styles is Styles#add_style
89
137
  # @see Style#add_style
@@ -117,7 +165,11 @@ require 'axlsx/workbook/worksheet/table.rb'
117
165
  @drawings = SimpleTypedList.new Drawing
118
166
  @charts = SimpleTypedList.new Chart
119
167
  @images = SimpleTypedList.new Pic
168
+ # Are these even used????? Check package serialization parts
120
169
  @tables = SimpleTypedList.new Table
170
+ @comments = SimpleTypedList.new Comments
171
+
172
+
121
173
  @use_autowidth = true
122
174
 
123
175
  self.date1904= !options[:date1904].nil? && options[:date1904]
@@ -140,12 +192,14 @@ require 'axlsx/workbook/worksheet/table.rb'
140
192
  def self.date1904() @@date1904; end
141
193
 
142
194
  # Indicates if the workbook should use autowidths or not.
143
- # this must be set before instantiating a worksheet to avoid Rmagix inclusion
195
+ # @note This gem no longer depends on RMagick for autowidth
196
+ # calculation. Thus the performance benefits of turning this off are
197
+ # marginal unless you are creating a very large sheet.
144
198
  # @return [Boolean]
145
199
  def use_autowidth() @use_autowidth; end
146
200
 
147
201
  # see @use_autowidth
148
- def use_autowidth=(v) Axlsx::validate_boolean v; @use_autowidth = v; end
202
+ def use_autowidth=(v=true) Axlsx::validate_boolean v; @use_autowidth = v; end
149
203
 
150
204
  # Adds a worksheet to this workbook
151
205
  # @return [Worksheet]
@@ -158,6 +212,14 @@ require 'axlsx/workbook/worksheet/table.rb'
158
212
  worksheet
159
213
  end
160
214
 
215
+ # Adds a defined name to this workbook
216
+ # @return [DefinedName]
217
+ # @param [String] formula @see DefinedName
218
+ # @param [Hash] options @see DefinedName
219
+ def add_defined_name(formula, options)
220
+ defined_names << DefinedName.new(formula, options)
221
+ end
222
+
161
223
  # The workbook relationships. This is managed automatically by the workbook
162
224
  # @return [Relationships]
163
225
  def relationships
@@ -199,17 +261,13 @@ require 'axlsx/workbook/worksheet/table.rb'
199
261
  str << '<workbookPr date1904="' << @@date1904.to_s << '"/>'
200
262
  str << '<sheets>'
201
263
  @worksheets.each_with_index do |sheet, index|
202
- str << '<sheet name="' << sheet.name << '" sheetId="' << (index+1).to_s << '" r:id="' << sheet.rId << '"/>'
203
- end
204
- str << '</sheets>'
205
- str << '<definedNames>'
206
- @worksheets.each_with_index do |sheet, index|
207
- if sheet.auto_filter
208
- str << '<definedName name="_xlnm._FilterDatabase" localSheetId="' << index.to_s << '" hidden="1">'
209
- str << sheet.abs_auto_filter << '</definedName>'
264
+ str << '<sheet name="' << sheet.name << '" sheetId="' << (index+1).to_s << '" r:id="' << sheet.rId << '"/>'
265
+ if defined_name = sheet.auto_filter.defined_name
266
+ add_defined_name defined_name, :name => '_xlnm._FilterDatabase', :local_sheet_id => index, :hidden => 1
210
267
  end
211
268
  end
212
- str << '</definedNames>'
269
+ str << '</sheets>'
270
+ defined_names.to_xml_string(str)
213
271
  str << '</workbook>'
214
272
  end
215
273
 
@@ -0,0 +1,34 @@
1
+ module Axlsx
2
+
3
+ #This class represents an auto filter range in a worksheet
4
+ class AutoFilter
5
+
6
+ # creates a new Autofilter object
7
+ # @param [Worksheet] worksheet
8
+ def initialize(worksheet)
9
+ raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
10
+ @worksheet = worksheet
11
+ end
12
+
13
+ attr_reader :worksheet
14
+
15
+ # The range the autofilter should be applied to.
16
+ # This should be a string like 'A1:B8'
17
+ # @return [String]
18
+ attr_accessor :range
19
+
20
+ # the formula for the defined name required for this auto filter
21
+ # @return [String]
22
+ def defined_name
23
+ return unless range
24
+ Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name)})
25
+ end
26
+
27
+ # serialize the object
28
+ # @return [String]
29
+ def to_xml_string(str='')
30
+ str << "<autoFilter ref='#{range}'></autoFilter>"
31
+ end
32
+
33
+ end
34
+ end