caxlsx 3.3.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/README.md +24 -5
  4. data/Rakefile +0 -1
  5. data/lib/axlsx/content_type/abstract_content_type.rb +2 -5
  6. data/lib/axlsx/content_type/content_type.rb +0 -4
  7. data/lib/axlsx/content_type/default.rb +1 -5
  8. data/lib/axlsx/content_type/override.rb +0 -4
  9. data/lib/axlsx/doc_props/app.rb +1 -6
  10. data/lib/axlsx/doc_props/core.rb +1 -6
  11. data/lib/axlsx/drawing/area_chart.rb +3 -6
  12. data/lib/axlsx/drawing/area_series.rb +1 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -6
  14. data/lib/axlsx/drawing/axes.rb +5 -6
  15. data/lib/axlsx/drawing/axis.rb +7 -12
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +7 -10
  17. data/lib/axlsx/drawing/bar_chart.rb +6 -9
  18. data/lib/axlsx/drawing/bar_series.rb +2 -8
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -5
  20. data/lib/axlsx/drawing/bubble_series.rb +3 -6
  21. data/lib/axlsx/drawing/cat_axis.rb +2 -7
  22. data/lib/axlsx/drawing/chart.rb +7 -12
  23. data/lib/axlsx/drawing/d_lbls.rb +23 -22
  24. data/lib/axlsx/drawing/drawing.rb +4 -8
  25. data/lib/axlsx/drawing/graphic_frame.rb +0 -3
  26. data/lib/axlsx/drawing/hyperlink.rb +4 -7
  27. data/lib/axlsx/drawing/line_3D_chart.rb +10 -14
  28. data/lib/axlsx/drawing/line_chart.rb +3 -6
  29. data/lib/axlsx/drawing/line_series.rb +1 -4
  30. data/lib/axlsx/drawing/marker.rb +5 -9
  31. data/lib/axlsx/drawing/num_data.rb +4 -9
  32. data/lib/axlsx/drawing/num_data_source.rb +3 -7
  33. data/lib/axlsx/drawing/num_val.rb +2 -5
  34. data/lib/axlsx/drawing/one_cell_anchor.rb +4 -6
  35. data/lib/axlsx/drawing/pic.rb +46 -13
  36. data/lib/axlsx/drawing/picture_locking.rb +3 -6
  37. data/lib/axlsx/drawing/pie_3D_chart.rb +2 -7
  38. data/lib/axlsx/drawing/pie_series.rb +1 -6
  39. data/lib/axlsx/drawing/scaling.rb +2 -5
  40. data/lib/axlsx/drawing/scatter_chart.rb +2 -5
  41. data/lib/axlsx/drawing/scatter_series.rb +2 -5
  42. data/lib/axlsx/drawing/ser_axis.rb +2 -6
  43. data/lib/axlsx/drawing/series.rb +3 -5
  44. data/lib/axlsx/drawing/series_title.rb +0 -2
  45. data/lib/axlsx/drawing/str_data.rb +3 -8
  46. data/lib/axlsx/drawing/str_val.rb +2 -5
  47. data/lib/axlsx/drawing/title.rb +12 -15
  48. data/lib/axlsx/drawing/two_cell_anchor.rb +5 -7
  49. data/lib/axlsx/drawing/val_axis.rb +1 -4
  50. data/lib/axlsx/drawing/view_3D.rb +24 -24
  51. data/lib/axlsx/drawing/vml_drawing.rb +2 -5
  52. data/lib/axlsx/drawing/vml_shape.rb +4 -7
  53. data/lib/axlsx/package.rb +35 -36
  54. data/lib/axlsx/rels/relationship.rb +21 -24
  55. data/lib/axlsx/rels/relationships.rb +3 -6
  56. data/lib/axlsx/stylesheet/border.rb +1 -4
  57. data/lib/axlsx/stylesheet/border_pr.rb +3 -5
  58. data/lib/axlsx/stylesheet/cell_alignment.rb +2 -10
  59. data/lib/axlsx/stylesheet/cell_protection.rb +1 -4
  60. data/lib/axlsx/stylesheet/cell_style.rb +3 -7
  61. data/lib/axlsx/stylesheet/color.rb +6 -5
  62. data/lib/axlsx/stylesheet/dxf.rb +2 -6
  63. data/lib/axlsx/stylesheet/fill.rb +0 -4
  64. data/lib/axlsx/stylesheet/font.rb +7 -6
  65. data/lib/axlsx/stylesheet/gradient_fill.rb +4 -6
  66. data/lib/axlsx/stylesheet/gradient_stop.rb +2 -3
  67. data/lib/axlsx/stylesheet/num_fmt.rb +1 -4
  68. data/lib/axlsx/stylesheet/pattern_fill.rb +3 -5
  69. data/lib/axlsx/stylesheet/styles.rb +53 -45
  70. data/lib/axlsx/stylesheet/table_style.rb +5 -8
  71. data/lib/axlsx/stylesheet/table_style_element.rb +1 -4
  72. data/lib/axlsx/stylesheet/table_styles.rb +3 -7
  73. data/lib/axlsx/stylesheet/xf.rb +3 -6
  74. data/lib/axlsx/util/accessors.rb +2 -4
  75. data/lib/axlsx/util/constants.rb +3 -5
  76. data/lib/axlsx/util/mime_type_utils.rb +13 -0
  77. data/lib/axlsx/util/options_parser.rb +1 -2
  78. data/lib/axlsx/util/serialized_attributes.rb +4 -5
  79. data/lib/axlsx/util/simple_typed_list.rb +18 -17
  80. data/lib/axlsx/util/storage.rb +32 -36
  81. data/lib/axlsx/util/validators.rb +7 -4
  82. data/lib/axlsx/util/zip_command.rb +0 -2
  83. data/lib/axlsx/version.rb +1 -2
  84. data/lib/axlsx/workbook/defined_name.rb +6 -5
  85. data/lib/axlsx/workbook/defined_names.rb +1 -2
  86. data/lib/axlsx/workbook/shared_strings_table.rb +3 -6
  87. data/lib/axlsx/workbook/workbook.rb +96 -91
  88. data/lib/axlsx/workbook/workbook_view.rb +5 -10
  89. data/lib/axlsx/workbook/workbook_views.rb +1 -3
  90. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +9 -8
  91. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +6 -6
  92. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +13 -14
  93. data/lib/axlsx/workbook/worksheet/border_creator.rb +29 -26
  94. data/lib/axlsx/workbook/worksheet/break.rb +2 -5
  95. data/lib/axlsx/workbook/worksheet/cell.rb +46 -26
  96. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +11 -11
  97. data/lib/axlsx/workbook/worksheet/cfvo.rb +2 -2
  98. data/lib/axlsx/workbook/worksheet/cfvos.rb +3 -5
  99. data/lib/axlsx/workbook/worksheet/col.rb +4 -7
  100. data/lib/axlsx/workbook/worksheet/col_breaks.rb +4 -5
  101. data/lib/axlsx/workbook/worksheet/color_scale.rb +10 -12
  102. data/lib/axlsx/workbook/worksheet/cols.rb +6 -6
  103. data/lib/axlsx/workbook/worksheet/comment.rb +4 -5
  104. data/lib/axlsx/workbook/worksheet/comments.rb +6 -10
  105. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +4 -5
  106. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +2 -6
  107. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +2 -4
  108. data/lib/axlsx/workbook/worksheet/data_bar.rb +20 -22
  109. data/lib/axlsx/workbook/worksheet/data_validation.rb +4 -5
  110. data/lib/axlsx/workbook/worksheet/data_validations.rb +2 -5
  111. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +1 -3
  112. data/lib/axlsx/workbook/worksheet/dimension.rb +5 -4
  113. data/lib/axlsx/workbook/worksheet/header_footer.rb +0 -1
  114. data/lib/axlsx/workbook/worksheet/icon_set.rb +2 -3
  115. data/lib/axlsx/workbook/worksheet/merged_cells.rb +8 -8
  116. data/lib/axlsx/workbook/worksheet/outline_pr.rb +0 -1
  117. data/lib/axlsx/workbook/worksheet/page_margins.rb +2 -2
  118. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -3
  119. data/lib/axlsx/workbook/worksheet/page_setup.rb +117 -120
  120. data/lib/axlsx/workbook/worksheet/pane.rb +16 -17
  121. data/lib/axlsx/workbook/worksheet/pivot_table.rb +8 -11
  122. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +8 -11
  123. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +3 -4
  124. data/lib/axlsx/workbook/worksheet/print_options.rb +0 -1
  125. data/lib/axlsx/workbook/worksheet/protected_range.rb +4 -5
  126. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +9 -9
  127. data/lib/axlsx/workbook/worksheet/rich_text.rb +4 -6
  128. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +21 -5
  129. data/lib/axlsx/workbook/worksheet/row.rb +24 -15
  130. data/lib/axlsx/workbook/worksheet/row_breaks.rb +3 -4
  131. data/lib/axlsx/workbook/worksheet/selection.rb +7 -9
  132. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +5 -6
  133. data/lib/axlsx/workbook/worksheet/sheet_data.rb +4 -6
  134. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +18 -18
  135. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +4 -4
  136. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +12 -13
  137. data/lib/axlsx/workbook/worksheet/sheet_view.rb +35 -42
  138. data/lib/axlsx/workbook/worksheet/table.rb +7 -9
  139. data/lib/axlsx/workbook/worksheet/table_style_info.rb +2 -3
  140. data/lib/axlsx/workbook/worksheet/tables.rb +4 -4
  141. data/lib/axlsx/workbook/worksheet/worksheet.rb +63 -35
  142. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +6 -6
  143. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +3 -2
  144. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +5 -6
  145. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +4 -4
  146. data/lib/axlsx.rb +23 -9
  147. data/lib/caxlsx.rb +0 -1
  148. metadata +3 -3
@@ -1,65 +1,63 @@
1
- # -*- coding: utf-8 -*-
2
1
  module Axlsx
3
- require 'axlsx/workbook/worksheet/sheet_calc_pr.rb'
4
- require 'axlsx/workbook/worksheet/auto_filter/auto_filter.rb'
5
- require 'axlsx/workbook/worksheet/date_time_converter.rb'
6
- require 'axlsx/workbook/worksheet/protected_range.rb'
7
- require 'axlsx/workbook/worksheet/protected_ranges.rb'
8
- require 'axlsx/workbook/worksheet/rich_text_run'
9
- require 'axlsx/workbook/worksheet/rich_text'
10
- require 'axlsx/workbook/worksheet/cell_serializer.rb'
11
- require 'axlsx/workbook/worksheet/cell.rb'
12
- require 'axlsx/workbook/worksheet/page_margins.rb'
13
- require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
14
- require 'axlsx/workbook/worksheet/outline_pr.rb'
15
- require 'axlsx/workbook/worksheet/page_setup.rb'
16
- require 'axlsx/workbook/worksheet/header_footer.rb'
17
- require 'axlsx/workbook/worksheet/print_options.rb'
18
- require 'axlsx/workbook/worksheet/cfvo.rb'
19
- require 'axlsx/workbook/worksheet/cfvos.rb'
20
- require 'axlsx/workbook/worksheet/color_scale.rb'
21
- require 'axlsx/workbook/worksheet/data_bar.rb'
22
- require 'axlsx/workbook/worksheet/icon_set.rb'
23
- require 'axlsx/workbook/worksheet/conditional_formatting.rb'
24
- require 'axlsx/workbook/worksheet/conditional_formatting_rule.rb'
25
- require 'axlsx/workbook/worksheet/conditional_formattings.rb'
26
- require 'axlsx/workbook/worksheet/row.rb'
27
- require 'axlsx/workbook/worksheet/col.rb'
28
- require 'axlsx/workbook/worksheet/cols.rb'
29
- require 'axlsx/workbook/worksheet/comments.rb'
30
- require 'axlsx/workbook/worksheet/comment.rb'
31
- require 'axlsx/workbook/worksheet/merged_cells.rb'
32
- require 'axlsx/workbook/worksheet/sheet_protection.rb'
33
- require 'axlsx/workbook/worksheet/sheet_pr.rb'
34
- require 'axlsx/workbook/worksheet/dimension.rb'
35
- require 'axlsx/workbook/worksheet/sheet_data.rb'
36
- require 'axlsx/workbook/worksheet/worksheet_drawing.rb'
37
- require 'axlsx/workbook/worksheet/worksheet_comments.rb'
38
- require 'axlsx/workbook/worksheet/worksheet_hyperlink'
39
- require 'axlsx/workbook/worksheet/worksheet_hyperlinks'
40
- require 'axlsx/workbook/worksheet/break'
41
- require 'axlsx/workbook/worksheet/row_breaks'
42
- require 'axlsx/workbook/worksheet/col_breaks'
43
- require 'axlsx/workbook/workbook_view'
44
- require 'axlsx/workbook/workbook_views'
45
-
46
-
47
- require 'axlsx/workbook/worksheet/worksheet.rb'
48
- require 'axlsx/workbook/shared_strings_table.rb'
49
- require 'axlsx/workbook/defined_name.rb'
50
- require 'axlsx/workbook/defined_names.rb'
51
- require 'axlsx/workbook/worksheet/table_style_info.rb'
52
- require 'axlsx/workbook/worksheet/table.rb'
53
- require 'axlsx/workbook/worksheet/tables.rb'
54
- require 'axlsx/workbook/worksheet/pivot_table_cache_definition.rb'
55
- require 'axlsx/workbook/worksheet/pivot_table.rb'
56
- require 'axlsx/workbook/worksheet/pivot_tables.rb'
57
- require 'axlsx/workbook/worksheet/data_validation.rb'
58
- require 'axlsx/workbook/worksheet/data_validations.rb'
59
- require 'axlsx/workbook/worksheet/sheet_view.rb'
60
- require 'axlsx/workbook/worksheet/sheet_format_pr.rb'
61
- require 'axlsx/workbook/worksheet/pane.rb'
62
- require 'axlsx/workbook/worksheet/selection.rb'
2
+ require 'axlsx/workbook/worksheet/sheet_calc_pr.rb'
3
+ require 'axlsx/workbook/worksheet/auto_filter/auto_filter.rb'
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'
7
+ require 'axlsx/workbook/worksheet/rich_text_run'
8
+ require 'axlsx/workbook/worksheet/rich_text'
9
+ require 'axlsx/workbook/worksheet/cell_serializer.rb'
10
+ require 'axlsx/workbook/worksheet/cell.rb'
11
+ require 'axlsx/workbook/worksheet/page_margins.rb'
12
+ require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
13
+ require 'axlsx/workbook/worksheet/outline_pr.rb'
14
+ require 'axlsx/workbook/worksheet/page_setup.rb'
15
+ require 'axlsx/workbook/worksheet/header_footer.rb'
16
+ require 'axlsx/workbook/worksheet/print_options.rb'
17
+ require 'axlsx/workbook/worksheet/cfvo.rb'
18
+ require 'axlsx/workbook/worksheet/cfvos.rb'
19
+ require 'axlsx/workbook/worksheet/color_scale.rb'
20
+ require 'axlsx/workbook/worksheet/data_bar.rb'
21
+ require 'axlsx/workbook/worksheet/icon_set.rb'
22
+ require 'axlsx/workbook/worksheet/conditional_formatting.rb'
23
+ require 'axlsx/workbook/worksheet/conditional_formatting_rule.rb'
24
+ require 'axlsx/workbook/worksheet/conditional_formattings.rb'
25
+ require 'axlsx/workbook/worksheet/row.rb'
26
+ require 'axlsx/workbook/worksheet/col.rb'
27
+ require 'axlsx/workbook/worksheet/cols.rb'
28
+ require 'axlsx/workbook/worksheet/comments.rb'
29
+ require 'axlsx/workbook/worksheet/comment.rb'
30
+ require 'axlsx/workbook/worksheet/merged_cells.rb'
31
+ require 'axlsx/workbook/worksheet/sheet_protection.rb'
32
+ require 'axlsx/workbook/worksheet/sheet_pr.rb'
33
+ require 'axlsx/workbook/worksheet/dimension.rb'
34
+ require 'axlsx/workbook/worksheet/sheet_data.rb'
35
+ require 'axlsx/workbook/worksheet/worksheet_drawing.rb'
36
+ require 'axlsx/workbook/worksheet/worksheet_comments.rb'
37
+ require 'axlsx/workbook/worksheet/worksheet_hyperlink'
38
+ require 'axlsx/workbook/worksheet/worksheet_hyperlinks'
39
+ require 'axlsx/workbook/worksheet/break'
40
+ require 'axlsx/workbook/worksheet/row_breaks'
41
+ require 'axlsx/workbook/worksheet/col_breaks'
42
+ require 'axlsx/workbook/workbook_view'
43
+ require 'axlsx/workbook/workbook_views'
44
+ require 'axlsx/workbook/worksheet/worksheet.rb'
45
+ require 'axlsx/workbook/shared_strings_table.rb'
46
+ require 'axlsx/workbook/defined_name.rb'
47
+ require 'axlsx/workbook/defined_names.rb'
48
+ require 'axlsx/workbook/worksheet/table_style_info.rb'
49
+ require 'axlsx/workbook/worksheet/table.rb'
50
+ require 'axlsx/workbook/worksheet/tables.rb'
51
+ require 'axlsx/workbook/worksheet/pivot_table_cache_definition.rb'
52
+ require 'axlsx/workbook/worksheet/pivot_table.rb'
53
+ require 'axlsx/workbook/worksheet/pivot_tables.rb'
54
+ require 'axlsx/workbook/worksheet/data_validation.rb'
55
+ require 'axlsx/workbook/worksheet/data_validations.rb'
56
+ require 'axlsx/workbook/worksheet/sheet_view.rb'
57
+ require 'axlsx/workbook/worksheet/sheet_format_pr.rb'
58
+ require 'axlsx/workbook/worksheet/pane.rb'
59
+ require 'axlsx/workbook/worksheet/selection.rb'
60
+
63
61
  # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
64
62
  # The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
65
63
  #
@@ -84,7 +82,6 @@ require 'axlsx/workbook/worksheet/selection.rb'
84
82
  #
85
83
  # *workbookPr is only supported to the extend of date1904
86
84
  class Workbook
87
-
88
85
  BOLD_FONT_MULTIPLIER = 1.5
89
86
  FONT_SCALE_DIVISOR = 10.0
90
87
 
@@ -109,29 +106,28 @@ require 'axlsx/workbook/worksheet/selection.rb'
109
106
  @is_reversed = v
110
107
  end
111
108
 
112
-
113
- # A collection of worksheets associated with this workbook.
109
+ # A collection of worksheets associated with this workbook.
114
110
  # @note The recommended way to manage worksheets is add_worksheet
115
111
  # @see Workbook#add_worksheet
116
112
  # @see Worksheet
117
113
  # @return [SimpleTypedList]
118
114
  attr_reader :worksheets
119
115
 
120
- # A colllection of charts associated with this workbook
116
+ # A collection of charts associated with this workbook
121
117
  # @note The recommended way to manage charts is Worksheet#add_chart
122
118
  # @see Worksheet#add_chart
123
119
  # @see Chart
124
120
  # @return [SimpleTypedList]
125
121
  attr_reader :charts
126
122
 
127
- # A colllection of images associated with this workbook
123
+ # A collection of images associated with this workbook
128
124
  # @note The recommended way to manage images is Worksheet#add_image
129
125
  # @see Worksheet#add_image
130
126
  # @see Pic
131
127
  # @return [SimpleTypedList]
132
128
  attr_reader :images
133
129
 
134
- # A colllection of drawings associated with this workbook
130
+ # A collection of drawings associated with this workbook
135
131
  # @note The recommended way to manage drawings is Worksheet#add_chart
136
132
  # @see Worksheet#add_chart
137
133
  # @see Drawing
@@ -140,15 +136,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
140
136
 
141
137
  # pretty sure this two are always empty and can be removed.
142
138
 
143
-
144
- # A colllection of tables associated with this workbook
139
+ # A collection of tables associated with this workbook
145
140
  # @note The recommended way to manage drawings is Worksheet#add_table
146
141
  # @see Worksheet#add_table
147
142
  # @see Table
148
143
  # @return [SimpleTypedList]
149
144
  attr_reader :tables
150
145
 
151
- # A colllection of pivot tables associated with this workbook
146
+ # A collection of pivot tables associated with this workbook
152
147
  # @note The recommended way to manage drawings is Worksheet#add_table
153
148
  # @see Worksheet#add_table
154
149
  # @see Table
@@ -217,11 +212,9 @@ require 'axlsx/workbook/worksheet/selection.rb'
217
212
  self.styles_applied = true
218
213
  end
219
214
 
220
-
221
215
  # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
222
216
  @@date1904 = false
223
217
 
224
-
225
218
  # A quick helper to retrive a worksheet by name
226
219
  # @param [String] name The name of the sheet you are looking for
227
220
  # @return [Worksheet] The sheet found, or nil
@@ -230,10 +223,10 @@ require 'axlsx/workbook/worksheet/selection.rb'
230
223
  @worksheets[index] if index
231
224
  end
232
225
 
233
- # Creates a new Workbook
234
- # The recomended way to work with workbooks is via Package#workbook
235
- # @option options [Boolean] date1904. If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
236
- def initialize(options={})
226
+ # Creates a new Workbook.
227
+ # The recommended way to work with workbooks is via Package#workbook.
228
+ # @option options [Boolean] date1904 If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
229
+ def initialize(options = {})
237
230
  @styles = Styles.new
238
231
  @worksheets = SimpleTypedList.new Worksheet
239
232
  @drawings = SimpleTypedList.new Drawing
@@ -243,13 +236,12 @@ require 'axlsx/workbook/worksheet/selection.rb'
243
236
  @tables = SimpleTypedList.new Table
244
237
  @pivot_tables = SimpleTypedList.new PivotTable
245
238
  @comments = SimpleTypedList.new Comments
246
-
247
-
248
239
  @use_autowidth = true
249
240
  @bold_font_multiplier = BOLD_FONT_MULTIPLIER
250
241
  @font_scale_divisor = FONT_SCALE_DIVISOR
251
242
 
252
- self.date1904= !options[:date1904].nil? && options[:date1904]
243
+ self.escape_formulas = options[:escape_formulas].nil? ? Axlsx.escape_formulas : options[:escape_formulas]
244
+ self.date1904 = !options[:date1904].nil? && options[:date1904]
253
245
  yield self if block_given?
254
246
  end
255
247
 
@@ -268,6 +260,19 @@ require 'axlsx/workbook/worksheet/selection.rb'
268
260
  # @return [Boolean]
269
261
  def self.date1904() @@date1904; end
270
262
 
263
+ # Whether to treat values starting with an equals sign as formulas or as literal strings.
264
+ # Allowing user-generated data to be interpreted as formulas is a security risk.
265
+ # See https://www.owasp.org/index.php/CSV_Injection for details.
266
+ # @return [Boolean]
267
+ attr_reader :escape_formulas
268
+
269
+ # Sets whether to treat values starting with an equals sign as formulas or as literal strings.
270
+ # @param [Boolean] value The value to set.
271
+ def escape_formulas=(value)
272
+ Axlsx.validate_boolean(value)
273
+ @escape_formulas = value
274
+ end
275
+
271
276
  # Indicates if the workbook should use autowidths or not.
272
277
  # @note This gem no longer depends on RMagick for autowidth
273
278
  # calculation. Thus the performance benefits of turning this off are
@@ -276,7 +281,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
276
281
  def use_autowidth() @use_autowidth; end
277
282
 
278
283
  # see @use_autowidth
279
- def use_autowidth=(v=true) Axlsx::validate_boolean v; @use_autowidth = v; end
284
+ def use_autowidth=(v = true) Axlsx::validate_boolean v; @use_autowidth = v; end
280
285
 
281
286
  # Font size of bold fonts is multiplied with this
282
287
  # Used for automatic calculation of cell widths with bold text
@@ -306,7 +311,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
306
311
  # @param [Hash] options Options to pass into the worksheed during initialization.
307
312
  # @option options [String] name The name of the worksheet
308
313
  # @option options [Hash] page_margins The page margins for the worksheet
309
- def insert_worksheet(index=0, options={})
314
+ def insert_worksheet(index = 0, options = {})
310
315
  worksheet = Worksheet.new(self, options)
311
316
  @worksheets.delete_at(@worksheets.size - 1)
312
317
  @worksheets.insert(index, worksheet)
@@ -320,7 +325,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
320
325
  # @option options [String] name The name of the worksheet.
321
326
  # @option options [Hash] page_margins The page margins for the worksheet.
322
327
  # @see Worksheet#initialize
323
- def add_worksheet(options={})
328
+ def add_worksheet(options = {})
324
329
  worksheet = Worksheet.new(self, options)
325
330
  yield worksheet if block_given?
326
331
  worksheet
@@ -330,7 +335,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
330
335
  # @return WorkbookViews
331
336
  # @option options [Hash] options passed into the added WorkbookView
332
337
  # @see WorkbookView#initialize
333
- def add_view(options={})
338
+ def add_view(options = {})
334
339
  views << WorkbookView.new(options)
335
340
  end
336
341
 
@@ -347,14 +352,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
347
352
  def relationships
348
353
  r = Relationships.new
349
354
  @worksheets.each do |sheet|
350
- r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN % (r.size+1))
355
+ r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN % (r.size + 1))
351
356
  end
352
357
  pivot_tables.each_with_index do |pivot_table, index|
353
- r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN % (index+1))
358
+ r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, PIVOT_TABLE_CACHE_DEFINITION_PN % (index + 1))
354
359
  end
355
- r << Relationship.new(self, STYLES_R, STYLES_PN)
360
+ r << Relationship.new(self, STYLES_R, STYLES_PN)
356
361
  if use_shared_strings
357
- r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN)
362
+ r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN)
358
363
  end
359
364
  r
360
365
  end
@@ -380,7 +385,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
380
385
  # @param [Symbol] space must be one of :preserve or :default
381
386
  def xml_space=(space)
382
387
  Axlsx::RestrictionValidator.validate(:xml_space, [:preserve, :default], space)
383
- @xml_space = space;
388
+ @xml_space = space
384
389
  end
385
390
 
386
391
  # returns a range of cells in a worksheet
@@ -391,13 +396,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
391
396
  sheet_name = cell_def.split('!')[0] if cell_def.match('!')
392
397
  worksheet = self.worksheets.select { |s| s.name == sheet_name }.first
393
398
  raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet)
394
- worksheet[cell_def.gsub(/.+!/,"")]
399
+
400
+ worksheet[cell_def.gsub(/.+!/, "")]
395
401
  end
396
402
 
397
403
  # Serialize the workbook
398
404
  # @param [String] str
399
405
  # @return [String]
400
- def to_xml_string(str='')
406
+ def to_xml_string(str = '')
401
407
  add_worksheet(name: 'Sheet1') unless worksheets.size > 0
402
408
  str << '<?xml version="1.0" encoding="UTF-8"?>'
403
409
  str << ('<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">')
@@ -420,6 +426,5 @@ require 'axlsx/workbook/worksheet/selection.rb'
420
426
  end
421
427
  str << '</workbook>'
422
428
  end
423
-
424
429
  end
425
430
  end
@@ -19,19 +19,16 @@
19
19
  # </xsd:complexType>
20
20
 
21
21
  module Axlsx
22
-
23
22
  # A BookView defines the display properties for a workbook.
24
23
  # Units for window widths and other dimensions are expressed in twips.
25
24
  # Twip measurements are portable between different display resolutions.
26
25
  # The formula is (screen pixels) * (20 * 72) / (logical device dpi),
27
26
  # where the logical device dpi can be different for x and y coordinates.
28
27
  class WorkbookView
29
-
30
28
  include Axlsx::SerializedAttributes
31
29
  include Axlsx::OptionsParser
32
30
  include Axlsx::Accessors
33
31
 
34
-
35
32
  # Creates a new BookView object
36
33
  # @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
37
34
  # @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible.
@@ -47,16 +44,15 @@ module Axlsx
47
44
  # @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips.
48
45
  # @option [Integer] window_height Specifies the height of the workbook window. The unit of measurement for this value is twips.
49
46
  # @option [Boolean] auto_filter_date_grouping Specifies a boolean value that indicates whether to group dates when presenting the user with filtering options in the user interface.
50
- def initialize(options={})
47
+ def initialize(options = {})
51
48
  parse_options options
52
49
  yield self if block_given?
53
50
  end
54
51
 
55
-
56
52
  unsigned_int_attr_accessor :x_window, :y_window, :window_width, :window_height,
57
53
  :tab_ratio, :first_sheet, :active_tab
58
54
 
59
- validated_attr_accessor [:visibility], :validate_view_visibility
55
+ validated_attr_accessor [:visibility], :validate_view_visibility
60
56
 
61
57
  serializable_attributes :visibility, :minimized,
62
58
  :show_horizontal_scroll, :show_vertical_scroll,
@@ -67,14 +63,13 @@ module Axlsx
67
63
  boolean_attr_accessor :minimized, :show_horizontal_scroll, :show_vertical_scroll,
68
64
  :show_sheet_tabs, :auto_filter_date_grouping
69
65
 
70
-
71
66
  # Serialize the WorkbookView
72
67
  # @param [String] str
73
68
  # @return [String]
74
69
  def to_xml_string(str = '')
75
- str << '<workbookView '
76
- serialized_attributes str
77
- str << '></workbookView>'
70
+ str << '<workbookView '
71
+ serialized_attributes str
72
+ str << '></workbookView>'
78
73
  end
79
74
  end
80
75
  end
@@ -1,7 +1,6 @@
1
1
  module Axlsx
2
2
  # a simple types list of BookView objects
3
3
  class WorkbookViews < SimpleTypedList
4
-
5
4
  # creates the book views object
6
5
  def initialize
7
6
  super WorkbookView
@@ -12,11 +11,10 @@ module Axlsx
12
11
  # @return [String]
13
12
  def to_xml_string(str = '')
14
13
  return if empty?
14
+
15
15
  str << "<bookViews>"
16
16
  each { |view| view.to_xml_string(str) }
17
17
  str << '</bookViews>'
18
18
  end
19
19
  end
20
20
  end
21
-
22
-
@@ -1,16 +1,14 @@
1
-
2
1
  require 'axlsx/workbook/worksheet/auto_filter/filter_column.rb'
3
2
  require 'axlsx/workbook/worksheet/auto_filter/filters.rb'
4
3
 
5
4
  module Axlsx
6
-
7
- #This class represents an auto filter range in a worksheet
5
+ # This class represents an auto filter range in a worksheet
8
6
  class AutoFilter
9
-
10
7
  # creates a new Autofilter object
11
8
  # @param [Worksheet] worksheet
12
9
  def initialize(worksheet)
13
10
  raise ArgumentError, 'you must provide a worksheet' unless worksheet.is_a?(Worksheet)
11
+
14
12
  @worksheet = worksheet
15
13
  end
16
14
 
@@ -27,7 +25,8 @@ module Axlsx
27
25
  # @return [String]
28
26
  def defined_name
29
27
  return unless range
30
- Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name)})
28
+
29
+ Axlsx.cell_range(range.split(':').collect { |name| worksheet.name_to_cell(name) })
31
30
  end
32
31
 
33
32
  # A collection of filterColumns for this auto_filter
@@ -54,24 +53,26 @@ module Axlsx
54
53
  start_point = Axlsx::name_to_indices(first_cell)
55
54
  end_point = Axlsx::name_to_indices(last_cell)
56
55
  # The +1 is so we skip the header row with the filter drop downs
57
- rows = worksheet.rows[(start_point.last+1)..end_point.last] || []
56
+ rows = worksheet.rows[(start_point.last + 1)..end_point.last] || []
58
57
 
59
58
  column_offset = start_point.first
60
59
  columns.each do |column|
61
60
  rows.each do |row|
62
61
  next if row.hidden
62
+
63
63
  column.apply(row, column_offset)
64
64
  end
65
65
  end
66
66
  end
67
+
67
68
  # serialize the object
68
69
  # @return [String]
69
- def to_xml_string(str='')
70
+ def to_xml_string(str = '')
70
71
  return unless range
72
+
71
73
  str << "<autoFilter ref='#{range}'>"
72
74
  columns.each { |filter_column| filter_column.to_xml_string(str) }
73
75
  str << "</autoFilter>"
74
76
  end
75
-
76
77
  end
77
78
  end
@@ -4,7 +4,6 @@ module Axlsx
4
4
  # If a column in the AutoFilter range has no criteria specified,
5
5
  # then there is no corresponding filterColumn collection expressed for that column.
6
6
  class FilterColumn
7
-
8
7
  include Axlsx::OptionsParser
9
8
  include Axlsx::SerializedAttributes
10
9
 
@@ -17,7 +16,7 @@ module Axlsx
17
16
  # @option [Boolean] show_button @see show_button
18
17
  def initialize(col_id, filter_type, options = {})
19
18
  RestrictionValidator.validate 'FilterColumn.filter', FILTERS, filter_type
20
- #Axlsx::validate_unsigned_int(col_id)
19
+ # Axlsx::validate_unsigned_int(col_id)
21
20
  self.col_id = col_id
22
21
  parse_options options
23
22
  @filter = Axlsx.const_get(Axlsx.camel(filter_type)).new(options)
@@ -27,7 +26,7 @@ module Axlsx
27
26
  serializable_attributes :col_id, :hidden_button, :show_button
28
27
 
29
28
  # Allowed filters
30
- FILTERS = [:filters] #, :top10, :custom_filters, :dynamic_filters, :color_filters, :icon_filters]
29
+ FILTERS = [:filters] # , :top10, :custom_filters, :dynamic_filters, :color_filters, :icon_filters]
31
30
 
32
31
  # Zero-based index indicating the AutoFilter column to which this filter information applies.
33
32
  # @return [Integer]
@@ -52,7 +51,7 @@ module Axlsx
52
51
  end
53
52
 
54
53
  # Sets the col_id attribute for this filter column.
55
- # @param [Integer | Cell] column_index The zero based index of the column to which this filter applies.
54
+ # @param [Integer | Cell] column_index The zero based index of the column to which this filter applies.
56
55
  # When you specify a cell, the column index will be read off the cell
57
56
  # @return [Integer]
58
57
  def col_id=(column_index)
@@ -65,8 +64,9 @@ module Axlsx
65
64
  # @param [Array] row A row from a worksheet that needs to be
66
65
  # filtered.
67
66
  def apply(row, offset)
68
- row.hidden = @filter.apply(row.cells[offset+col_id.to_i])
67
+ row.hidden = @filter.apply(row.cells[offset + col_id.to_i])
69
68
  end
69
+
70
70
  # @param [Boolean] hidden Flag indicating whether the AutoFilter button for this column is hidden.
71
71
  # @return [Boolean]
72
72
  def hidden_button=(hidden)
@@ -85,7 +85,7 @@ module Axlsx
85
85
  end
86
86
 
87
87
  # Serialize the object to xml
88
- def to_xml_string(str='')
88
+ def to_xml_string(str = '')
89
89
  str << "<filterColumn #{serialized_attributes}>"
90
90
  @filter.to_xml_string(str)
91
91
  str << "</filterColumn>"
@@ -1,6 +1,5 @@
1
1
  module Axlsx
2
-
3
- # When multiple values are chosen to filter by, or when a group of date values are chosen to filter by,
2
+ # When multiple values are chosen to filter by, or when a group of date values are chosen to filter by,
4
3
  # this object groups those criteria together.
5
4
  class Filters
6
5
  include Axlsx::OptionsParser
@@ -16,7 +15,7 @@ module Axlsx
16
15
  # @note The recommended way to interact with filter objects is via AutoFilter#add_column
17
16
  # @example
18
17
  # ws.auto_filter.add_column(0, :filters, :blank => true, :calendar_type => 'japan', :filter_items => [100, 'a'])
19
- def initialize(options={})
18
+ def initialize(options = {})
20
19
  parse_options options
21
20
  end
22
21
 
@@ -29,7 +28,7 @@ module Axlsx
29
28
  # @return [Boolean]
30
29
  attr_reader :blank
31
30
 
32
- # Calendar type for date grouped items.
31
+ # Calendar type for date grouped items.
33
32
  # Used to interpret the values in dateGroupItem.
34
33
  # This is the calendar type used to evaluate all dates in the filter column,
35
34
  # even when those dates are not using the same calendar system / date formatting.
@@ -42,6 +41,7 @@ module Axlsx
42
41
  # TODO implement this for date filters as well!
43
42
  def apply(cell)
44
43
  return false unless cell
44
+
45
45
  filter_items.each do |filter|
46
46
  return false if cell.value == filter.val
47
47
  end
@@ -76,12 +76,12 @@ module Axlsx
76
76
  # Serialize the object to xml
77
77
  def to_xml_string(str = '')
78
78
  str << "<filters #{serialized_attributes}>"
79
- filter_items.each { |filter| filter.to_xml_string(str) }
79
+ filter_items.each { |filter| filter.to_xml_string(str) }
80
80
  date_group_items.each { |date_group_item| date_group_item.to_xml_string(str) }
81
81
  str << '</filters>'
82
82
  end
83
83
 
84
- # not entirely happy with this.
84
+ # not entirely happy with this.
85
85
  # filter_items should be a simple typed list that overrides << etc
86
86
  # to create Filter objects from the inserted values. However this
87
87
  # is most likely so rarely used...(really? do you know that?)
@@ -98,13 +98,13 @@ module Axlsx
98
98
  def date_group_items=(options)
99
99
  options.each do |date_group|
100
100
  raise ArgumentError, "date_group_items should be an array of hashes specifying the options for each date_group_item" unless date_group.is_a?(Hash)
101
+
101
102
  date_group_items << DateGroupItem.new(date_group)
102
103
  end
103
104
  end
104
105
 
105
106
  # This class expresses a filter criteria value.
106
107
  class Filter
107
-
108
108
  # Creates a new filter value object
109
109
  # @param [Any] value The value of the filter. This is not restricted, but
110
110
  # will be serialized via to_s so if you are passing an object
@@ -113,8 +113,7 @@ module Axlsx
113
113
  @val = value
114
114
  end
115
115
 
116
-
117
- #Filter value used in the criteria.
116
+ # Filter value used in the criteria.
118
117
  attr_accessor :val
119
118
 
120
119
  # Serializes the filter value object
@@ -124,7 +123,6 @@ module Axlsx
124
123
  end
125
124
  end
126
125
 
127
-
128
126
  # This collection is used to express a group of dates or times which are
129
127
  # used in an AutoFilter criteria. Values are always written in the calendar
130
128
  # type of the first date encountered in the filter range, so that all
@@ -132,7 +130,7 @@ module Axlsx
132
130
  # types, can be correctly compared for the purposes of filtering.
133
131
  class DateGroupItem
134
132
  include Axlsx::OptionsParser
135
- include Axlsx::SerializedAttributes
133
+ include Axlsx::SerializedAttributes
136
134
 
137
135
  # Creates a new DateGroupItem
138
136
  # @param [Hash] options A hash of options to use when
@@ -145,9 +143,10 @@ include Axlsx::SerializedAttributes
145
143
  # @option [Integer] hour @see hour
146
144
  # @option [Integer] minute @see minute
147
145
  # @option [Integer] second @see second
148
- def initialize(options={})
149
- raise ArgumentError, "You must specify a year for date time grouping" unless options[:year]
146
+ def initialize(options = {})
147
+ raise ArgumentError, "You must specify a year for date time grouping" unless options[:year]
150
148
  raise ArgumentError, "You must specify a date_time_grouping when creating a DateGroupItem for auto filter" unless options[:date_time_grouping]
149
+
151
150
  parse_options options
152
151
  end
153
152
 
@@ -200,7 +199,7 @@ include Axlsx::SerializedAttributes
200
199
  end
201
200
 
202
201
  # The day value for the date group item
203
- # This must be between 1 and 31
202
+ # This must be between 1 and 31
204
203
  # @note no attempt is made to ensure the date value is valid for any given month
205
204
  def day=(value)
206
205
  RangeValidator.validate "DateGroupItem.day", 0, 31, value