caxlsx 3.3.0 → 4.5.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 (155) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +87 -11
  3. data/README.md +43 -16
  4. data/Rakefile +5 -11
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +15 -10
  7. data/lib/axlsx/content_type/content_type.rb +8 -10
  8. data/lib/axlsx/content_type/default.rb +7 -6
  9. data/lib/axlsx/content_type/override.rb +6 -5
  10. data/lib/axlsx/doc_props/app.rb +96 -32
  11. data/lib/axlsx/doc_props/core.rb +9 -12
  12. data/lib/axlsx/drawing/area_chart.rb +16 -17
  13. data/lib/axlsx/drawing/area_series.rb +23 -18
  14. data/lib/axlsx/drawing/ax_data_source.rb +4 -7
  15. data/lib/axlsx/drawing/axes.rb +11 -10
  16. data/lib/axlsx/drawing/axis.rb +83 -36
  17. data/lib/axlsx/drawing/bar_3D_chart.rb +30 -21
  18. data/lib/axlsx/drawing/bar_chart.rb +29 -20
  19. data/lib/axlsx/drawing/bar_series.rb +23 -18
  20. data/lib/axlsx/drawing/bubble_chart.rb +9 -10
  21. data/lib/axlsx/drawing/bubble_series.rb +11 -12
  22. data/lib/axlsx/drawing/cat_axis.rb +38 -28
  23. data/lib/axlsx/drawing/chart.rb +52 -30
  24. data/lib/axlsx/drawing/d_lbls.rb +36 -32
  25. data/lib/axlsx/drawing/drawing.rb +61 -62
  26. data/lib/axlsx/drawing/graphic_frame.rb +6 -7
  27. data/lib/axlsx/drawing/hyperlink.rb +22 -14
  28. data/lib/axlsx/drawing/line_3D_chart.rb +15 -17
  29. data/lib/axlsx/drawing/line_chart.rb +16 -17
  30. data/lib/axlsx/drawing/line_series.rb +23 -18
  31. data/lib/axlsx/drawing/marker.rb +29 -16
  32. data/lib/axlsx/drawing/num_data.rb +13 -16
  33. data/lib/axlsx/drawing/num_data_source.rb +11 -13
  34. data/lib/axlsx/drawing/num_val.rb +10 -11
  35. data/lib/axlsx/drawing/one_cell_anchor.rb +16 -10
  36. data/lib/axlsx/drawing/pic.rb +68 -24
  37. data/lib/axlsx/drawing/picture_locking.rb +6 -7
  38. data/lib/axlsx/drawing/pie_3D_chart.rb +9 -12
  39. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  40. data/lib/axlsx/drawing/pie_series.rb +26 -17
  41. data/lib/axlsx/drawing/scaling.rb +26 -13
  42. data/lib/axlsx/drawing/scatter_chart.rb +10 -11
  43. data/lib/axlsx/drawing/scatter_series.rb +17 -18
  44. data/lib/axlsx/drawing/ser_axis.rb +22 -19
  45. data/lib/axlsx/drawing/series.rb +14 -8
  46. data/lib/axlsx/drawing/series_title.rb +6 -6
  47. data/lib/axlsx/drawing/str_data.rb +10 -13
  48. data/lib/axlsx/drawing/str_val.rb +8 -9
  49. data/lib/axlsx/drawing/title.rb +23 -27
  50. data/lib/axlsx/drawing/two_cell_anchor.rb +9 -9
  51. data/lib/axlsx/drawing/val_axis.rb +7 -8
  52. data/lib/axlsx/drawing/view_3D.rb +38 -30
  53. data/lib/axlsx/drawing/vml_drawing.rb +19 -20
  54. data/lib/axlsx/drawing/vml_shape.rb +25 -26
  55. data/lib/axlsx/package.rb +134 -99
  56. data/lib/axlsx/rels/relationship.rb +42 -30
  57. data/lib/axlsx/rels/relationships.rb +9 -10
  58. data/lib/axlsx/stylesheet/border.rb +16 -8
  59. data/lib/axlsx/stylesheet/border_pr.rb +24 -12
  60. data/lib/axlsx/stylesheet/cell_alignment.rb +44 -21
  61. data/lib/axlsx/stylesheet/cell_protection.rb +13 -7
  62. data/lib/axlsx/stylesheet/cell_style.rb +36 -15
  63. data/lib/axlsx/stylesheet/color.rb +23 -14
  64. data/lib/axlsx/stylesheet/dxf.rb +36 -15
  65. data/lib/axlsx/stylesheet/fill.rb +7 -6
  66. data/lib/axlsx/stylesheet/font.rb +71 -22
  67. data/lib/axlsx/stylesheet/gradient_fill.rb +16 -10
  68. data/lib/axlsx/stylesheet/gradient_stop.rb +14 -6
  69. data/lib/axlsx/stylesheet/num_fmt.rb +15 -14
  70. data/lib/axlsx/stylesheet/pattern_fill.rb +20 -8
  71. data/lib/axlsx/stylesheet/styles.rb +167 -118
  72. data/lib/axlsx/stylesheet/table_style.rb +20 -10
  73. data/lib/axlsx/stylesheet/table_style_element.rb +16 -8
  74. data/lib/axlsx/stylesheet/table_styles.rb +16 -11
  75. data/lib/axlsx/stylesheet/theme.rb +163 -0
  76. data/lib/axlsx/stylesheet/xf.rb +78 -25
  77. data/lib/axlsx/util/accessors.rb +13 -11
  78. data/lib/axlsx/util/buffered_zip_output_stream.rb +64 -0
  79. data/lib/axlsx/util/constants.rb +133 -110
  80. data/lib/axlsx/util/mime_type_utils.rb +75 -5
  81. data/lib/axlsx/util/options_parser.rb +4 -3
  82. data/lib/axlsx/util/serialized_attributes.rb +47 -23
  83. data/lib/axlsx/util/simple_typed_list.rb +77 -64
  84. data/lib/axlsx/util/storage.rb +38 -41
  85. data/lib/axlsx/util/uri_utils.rb +70 -0
  86. data/lib/axlsx/util/validators.rb +111 -48
  87. data/lib/axlsx/util/zip_command.rb +10 -12
  88. data/lib/axlsx/version.rb +3 -2
  89. data/lib/axlsx/workbook/defined_name.rb +13 -9
  90. data/lib/axlsx/workbook/defined_names.rb +5 -4
  91. data/lib/axlsx/workbook/shared_strings_table.rb +13 -14
  92. data/lib/axlsx/workbook/workbook.rb +152 -120
  93. data/lib/axlsx/workbook/workbook_view.rb +9 -12
  94. data/lib/axlsx/workbook/workbook_views.rb +5 -5
  95. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +87 -15
  96. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +16 -10
  97. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +28 -25
  98. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +51 -0
  99. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +54 -0
  100. data/lib/axlsx/workbook/worksheet/border_creator.rb +34 -29
  101. data/lib/axlsx/workbook/worksheet/break.rb +4 -5
  102. data/lib/axlsx/workbook/worksheet/cell.rb +125 -78
  103. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +33 -29
  104. data/lib/axlsx/workbook/worksheet/cfvo.rb +13 -5
  105. data/lib/axlsx/workbook/worksheet/cfvos.rb +5 -5
  106. data/lib/axlsx/workbook/worksheet/col.rb +32 -19
  107. data/lib/axlsx/workbook/worksheet/col_breaks.rb +9 -8
  108. data/lib/axlsx/workbook/worksheet/color_scale.rb +16 -16
  109. data/lib/axlsx/workbook/worksheet/cols.rb +10 -8
  110. data/lib/axlsx/workbook/worksheet/comment.rb +14 -13
  111. data/lib/axlsx/workbook/worksheet/comments.rb +11 -13
  112. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +19 -9
  113. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +75 -22
  114. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +8 -8
  115. data/lib/axlsx/workbook/worksheet/data_bar.rb +29 -30
  116. data/lib/axlsx/workbook/worksheet/data_validation.rb +73 -33
  117. data/lib/axlsx/workbook/worksheet/data_validations.rb +8 -9
  118. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +8 -8
  119. data/lib/axlsx/workbook/worksheet/dimension.rb +10 -7
  120. data/lib/axlsx/workbook/worksheet/header_footer.rb +5 -4
  121. data/lib/axlsx/workbook/worksheet/icon_set.rb +40 -12
  122. data/lib/axlsx/workbook/worksheet/merged_cells.rb +11 -11
  123. data/lib/axlsx/workbook/worksheet/outline_pr.rb +7 -4
  124. data/lib/axlsx/workbook/worksheet/page_margins.rb +41 -13
  125. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +7 -6
  126. data/lib/axlsx/workbook/worksheet/page_setup.rb +153 -131
  127. data/lib/axlsx/workbook/worksheet/pane.rb +34 -26
  128. data/lib/axlsx/workbook/worksheet/pivot_table.rb +78 -29
  129. data/lib/axlsx/workbook/worksheet/pivot_table_cache_definition.rb +12 -13
  130. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +6 -5
  131. data/lib/axlsx/workbook/worksheet/print_options.rb +4 -2
  132. data/lib/axlsx/workbook/worksheet/protected_range.rb +6 -5
  133. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +13 -11
  134. data/lib/axlsx/workbook/worksheet/rich_text.rb +6 -6
  135. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +66 -28
  136. data/lib/axlsx/workbook/worksheet/row.rb +34 -23
  137. data/lib/axlsx/workbook/worksheet/row_breaks.rb +9 -8
  138. data/lib/axlsx/workbook/worksheet/selection.rb +22 -16
  139. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +11 -7
  140. data/lib/axlsx/workbook/worksheet/sheet_data.rb +7 -7
  141. data/lib/axlsx/workbook/worksheet/sheet_format_pr.rb +23 -19
  142. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +12 -8
  143. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +22 -21
  144. data/lib/axlsx/workbook/worksheet/sheet_view.rb +71 -55
  145. data/lib/axlsx/workbook/worksheet/table.rb +13 -13
  146. data/lib/axlsx/workbook/worksheet/table_style_info.rb +8 -6
  147. data/lib/axlsx/workbook/worksheet/tables.rb +8 -6
  148. data/lib/axlsx/workbook/worksheet/worksheet.rb +120 -79
  149. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +13 -11
  150. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +11 -4
  151. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +12 -10
  152. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +9 -7
  153. data/lib/axlsx.rb +120 -60
  154. data/lib/caxlsx.rb +3 -2
  155. metadata +42 -75
@@ -1,67 +1,72 @@
1
- # -*- coding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  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'
4
+ autoload :SheetCalcPr, 'axlsx/workbook/worksheet/sheet_calc_pr'
5
+ autoload :AutoFilter, 'axlsx/workbook/worksheet/auto_filter/auto_filter'
6
+ autoload :FilterColumn, 'axlsx/workbook/worksheet/auto_filter/filter_column'
7
+ autoload :Filters, 'axlsx/workbook/worksheet/auto_filter/filters'
8
+ autoload :SortState, 'axlsx/workbook/worksheet/auto_filter/sort_state'
9
+ autoload :SortCondition, 'axlsx/workbook/worksheet/auto_filter/sort_condition'
10
+ autoload :DateTimeConverter, 'axlsx/workbook/worksheet/date_time_converter'
11
+ autoload :ProtectedRange, 'axlsx/workbook/worksheet/protected_range'
12
+ autoload :ProtectedRanges, 'axlsx/workbook/worksheet/protected_ranges'
13
+ autoload :RichTextRun, 'axlsx/workbook/worksheet/rich_text_run'
14
+ autoload :RichText, 'axlsx/workbook/worksheet/rich_text'
15
+ autoload :CellSerializer, 'axlsx/workbook/worksheet/cell_serializer'
16
+ autoload :Cell, 'axlsx/workbook/worksheet/cell'
17
+ autoload :PageMargins, 'axlsx/workbook/worksheet/page_margins'
18
+ autoload :PageSetUpPr, 'axlsx/workbook/worksheet/page_set_up_pr'
19
+ autoload :OutlinePr, 'axlsx/workbook/worksheet/outline_pr'
20
+ autoload :PageSetup, 'axlsx/workbook/worksheet/page_setup'
21
+ autoload :HeaderFooter, 'axlsx/workbook/worksheet/header_footer'
22
+ autoload :PrintOptions, 'axlsx/workbook/worksheet/print_options'
23
+ autoload :Cfvo, 'axlsx/workbook/worksheet/cfvo'
24
+ autoload :Cfvos, 'axlsx/workbook/worksheet/cfvos'
25
+ autoload :ColorScale, 'axlsx/workbook/worksheet/color_scale'
26
+ autoload :DataBar, 'axlsx/workbook/worksheet/data_bar'
27
+ autoload :IconSet, 'axlsx/workbook/worksheet/icon_set'
28
+ autoload :ConditionalFormatting, 'axlsx/workbook/worksheet/conditional_formatting'
29
+ autoload :ConditionalFormattingRule, 'axlsx/workbook/worksheet/conditional_formatting_rule'
30
+ autoload :ConditionalFormattings, 'axlsx/workbook/worksheet/conditional_formattings'
31
+ autoload :Row, 'axlsx/workbook/worksheet/row'
32
+ autoload :Col, 'axlsx/workbook/worksheet/col'
33
+ autoload :Cols, 'axlsx/workbook/worksheet/cols'
34
+ autoload :Comments, 'axlsx/workbook/worksheet/comments'
35
+ autoload :Comment, 'axlsx/workbook/worksheet/comment'
36
+ autoload :MergedCells, 'axlsx/workbook/worksheet/merged_cells'
37
+ autoload :SheetProtection, 'axlsx/workbook/worksheet/sheet_protection'
38
+ autoload :SheetPr, 'axlsx/workbook/worksheet/sheet_pr'
39
+ autoload :Dimension, 'axlsx/workbook/worksheet/dimension'
40
+ autoload :SheetData, 'axlsx/workbook/worksheet/sheet_data'
41
+ autoload :WorksheetDrawing, 'axlsx/workbook/worksheet/worksheet_drawing'
42
+ autoload :WorksheetComments, 'axlsx/workbook/worksheet/worksheet_comments'
43
+ autoload :WorksheetHyperlink, 'axlsx/workbook/worksheet/worksheet_hyperlink'
44
+ autoload :WorksheetHyperlinks, 'axlsx/workbook/worksheet/worksheet_hyperlinks'
45
+ autoload :Break, 'axlsx/workbook/worksheet/break'
46
+ autoload :RowBreaks, 'axlsx/workbook/worksheet/row_breaks'
47
+ autoload :ColBreaks, 'axlsx/workbook/worksheet/col_breaks'
48
+ autoload :WorkbookView, 'axlsx/workbook/workbook_view'
49
+ autoload :WorkbookViews, 'axlsx/workbook/workbook_views'
50
+ autoload :Worksheet, 'axlsx/workbook/worksheet/worksheet'
51
+ autoload :BorderCreator, 'axlsx/workbook/worksheet/border_creator'
52
+ autoload :SharedStringsTable, 'axlsx/workbook/shared_strings_table'
53
+ autoload :DefinedName, 'axlsx/workbook/defined_name'
54
+ autoload :DefinedNames, 'axlsx/workbook/defined_names'
55
+ autoload :TableStyleInfo, 'axlsx/workbook/worksheet/table_style_info'
56
+ autoload :Table, 'axlsx/workbook/worksheet/table'
57
+ autoload :Tables, 'axlsx/workbook/worksheet/tables'
58
+ autoload :PivotTableCacheDefinition, 'axlsx/workbook/worksheet/pivot_table_cache_definition'
59
+ autoload :PivotTable, 'axlsx/workbook/worksheet/pivot_table'
60
+ autoload :PivotTables, 'axlsx/workbook/worksheet/pivot_tables'
61
+ autoload :DataValidation, 'axlsx/workbook/worksheet/data_validation'
62
+ autoload :DataValidations, 'axlsx/workbook/worksheet/data_validations'
63
+ autoload :SheetView, 'axlsx/workbook/worksheet/sheet_view'
64
+ autoload :SheetFormatPr, 'axlsx/workbook/worksheet/sheet_format_pr'
65
+ autoload :Pane, 'axlsx/workbook/worksheet/pane'
66
+ autoload :Selection, 'axlsx/workbook/worksheet/selection'
67
+
63
68
  # The Workbook class is an xlsx workbook that manages worksheets, charts, drawings and styles.
64
- # The following parts of the Office Open XML spreadsheet specification are not implimented in this version.
69
+ # The following parts of the Office Open XML spreadsheet specification are not implemented in this version.
65
70
  #
66
71
  # bookViews
67
72
  # calcPr
@@ -84,7 +89,6 @@ require 'axlsx/workbook/worksheet/selection.rb'
84
89
  #
85
90
  # *workbookPr is only supported to the extend of date1904
86
91
  class Workbook
87
-
88
92
  BOLD_FONT_MULTIPLIER = 1.5
89
93
  FONT_SCALE_DIVISOR = 10.0
90
94
 
@@ -96,7 +100,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
96
100
 
97
101
  # @see use_shared_strings
98
102
  def use_shared_strings=(v)
99
- Axlsx::validate_boolean(v)
103
+ Axlsx.validate_boolean(v)
100
104
  @use_shared_strings = v
101
105
  end
102
106
 
@@ -105,33 +109,32 @@ require 'axlsx/workbook/worksheet/selection.rb'
105
109
  attr_reader :is_reversed
106
110
 
107
111
  def is_reversed=(v)
108
- Axlsx::validate_boolean(v)
112
+ Axlsx.validate_boolean(v)
109
113
  @is_reversed = v
110
114
  end
111
115
 
112
-
113
- # A collection of worksheets associated with this workbook.
116
+ # A collection of worksheets associated with this workbook.
114
117
  # @note The recommended way to manage worksheets is add_worksheet
115
118
  # @see Workbook#add_worksheet
116
119
  # @see Worksheet
117
120
  # @return [SimpleTypedList]
118
121
  attr_reader :worksheets
119
122
 
120
- # A colllection of charts associated with this workbook
123
+ # A collection of charts associated with this workbook
121
124
  # @note The recommended way to manage charts is Worksheet#add_chart
122
125
  # @see Worksheet#add_chart
123
126
  # @see Chart
124
127
  # @return [SimpleTypedList]
125
128
  attr_reader :charts
126
129
 
127
- # A colllection of images associated with this workbook
130
+ # A collection of images associated with this workbook
128
131
  # @note The recommended way to manage images is Worksheet#add_image
129
132
  # @see Worksheet#add_image
130
133
  # @see Pic
131
134
  # @return [SimpleTypedList]
132
135
  attr_reader :images
133
136
 
134
- # A colllection of drawings associated with this workbook
137
+ # A collection of drawings associated with this workbook
135
138
  # @note The recommended way to manage drawings is Worksheet#add_chart
136
139
  # @see Worksheet#add_chart
137
140
  # @see Drawing
@@ -140,15 +143,14 @@ require 'axlsx/workbook/worksheet/selection.rb'
140
143
 
141
144
  # pretty sure this two are always empty and can be removed.
142
145
 
143
-
144
- # A colllection of tables associated with this workbook
146
+ # A collection of tables associated with this workbook
145
147
  # @note The recommended way to manage drawings is Worksheet#add_table
146
148
  # @see Worksheet#add_table
147
149
  # @see Table
148
150
  # @return [SimpleTypedList]
149
151
  attr_reader :tables
150
152
 
151
- # A colllection of pivot tables associated with this workbook
153
+ # A collection of pivot tables associated with this workbook
152
154
  # @note The recommended way to manage drawings is Worksheet#add_table
153
155
  # @see Worksheet#add_table
154
156
  # @see Table
@@ -174,7 +176,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
174
176
  # @see Comment
175
177
  # @return [Comments]
176
178
  def comments
177
- worksheets.map { |sheet| sheet.comments }.compact
179
+ worksheets.map(&:comments).compact
178
180
  end
179
181
 
180
182
  # The styles associated with this workbook
@@ -187,6 +189,12 @@ require 'axlsx/workbook/worksheet/selection.rb'
187
189
  @styles
188
190
  end
189
191
 
192
+ # The theme associated with this workbook
193
+ # @return [Theme]
194
+ def theme
195
+ @theme ||= Theme.new
196
+ end
197
+
190
198
  # An array that holds all cells with styles
191
199
  # @return Set
192
200
  def styled_cells
@@ -200,16 +208,16 @@ require 'axlsx/workbook/worksheet/selection.rb'
200
208
  # A helper to apply styles that were added using `worksheet.add_style`
201
209
  # @return [Boolean]
202
210
  def apply_styles
203
- return false if !styled_cells
211
+ return false unless styled_cells
204
212
 
205
213
  styled_cells.each do |cell|
206
214
  current_style = styles.style_index[cell.style]
207
215
 
208
- if current_style
209
- new_style = Axlsx.hash_deep_merge(current_style, cell.raw_style)
210
- else
211
- new_style = cell.raw_style
212
- end
216
+ new_style = if current_style
217
+ Axlsx.hash_deep_merge(current_style, cell.raw_style)
218
+ else
219
+ cell.raw_style
220
+ end
213
221
 
214
222
  cell.style = styles.add_style(new_style)
215
223
  end
@@ -217,23 +225,21 @@ require 'axlsx/workbook/worksheet/selection.rb'
217
225
  self.styles_applied = true
218
226
  end
219
227
 
220
-
221
228
  # Indicates if the epoc date for serialization should be 1904. If false, 1900 is used.
222
229
  @@date1904 = false
223
230
 
224
-
225
- # A quick helper to retrive a worksheet by name
231
+ # A quick helper to retrieve a worksheet by name
226
232
  # @param [String] name The name of the sheet you are looking for
227
233
  # @return [Worksheet] The sheet found, or nil
228
234
  def sheet_by_name(name)
229
- index = @worksheets.index { |sheet| sheet.name == name }
230
- @worksheets[index] if index
235
+ encoded_name = Axlsx.coder.encode(name)
236
+ @worksheets.find { |sheet| sheet.name == encoded_name }
231
237
  end
232
238
 
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={})
239
+ # Creates a new Workbook.
240
+ # The recommended way to work with workbooks is via Package#workbook.
241
+ # @option options [Boolean] date1904 If this is not specified, date1904 is set to false. Office 2011 for Mac defaults to false.
242
+ def initialize(options = {})
237
243
  @styles = Styles.new
238
244
  @worksheets = SimpleTypedList.new Worksheet
239
245
  @drawings = SimpleTypedList.new Drawing
@@ -243,40 +249,65 @@ require 'axlsx/workbook/worksheet/selection.rb'
243
249
  @tables = SimpleTypedList.new Table
244
250
  @pivot_tables = SimpleTypedList.new PivotTable
245
251
  @comments = SimpleTypedList.new Comments
246
-
247
-
248
252
  @use_autowidth = true
249
253
  @bold_font_multiplier = BOLD_FONT_MULTIPLIER
250
254
  @font_scale_divisor = FONT_SCALE_DIVISOR
251
255
 
252
- self.date1904= !options[:date1904].nil? && options[:date1904]
256
+ self.escape_formulas = options[:escape_formulas].nil? ? Axlsx.escape_formulas : options[:escape_formulas]
257
+ self.date1904 = !options[:date1904].nil? && options[:date1904]
253
258
  yield self if block_given?
254
259
  end
255
260
 
256
261
  # Instance level access to the class variable 1904
257
262
  # @return [Boolean]
258
- def date1904() @@date1904; end
263
+ def date1904
264
+ @@date1904
265
+ end
259
266
 
260
267
  # see @date1904
261
- def date1904=(v) Axlsx::validate_boolean v; @@date1904 = v; end
268
+ def date1904=(v)
269
+ Axlsx.validate_boolean v
270
+ @@date1904 = v
271
+ end
262
272
 
263
273
  # Sets the date1904 attribute to the provided boolean
264
274
  # @return [Boolean]
265
- def self.date1904=(v) Axlsx::validate_boolean v; @@date1904 = v; end
275
+ def self.date1904=(v)
276
+ Axlsx.validate_boolean v
277
+ @@date1904 = v
278
+ end
266
279
 
267
280
  # retrieves the date1904 attribute
268
281
  # @return [Boolean]
269
- def self.date1904() @@date1904; end
282
+ def self.date1904
283
+ @@date1904
284
+ end
285
+
286
+ # Whether to treat values starting with an equals sign as formulas or as literal strings.
287
+ # Allowing user-generated data to be interpreted as formulas is a security risk.
288
+ # See https://www.owasp.org/index.php/CSV_Injection for details.
289
+ # @return [Boolean]
290
+ attr_reader :escape_formulas
291
+
292
+ # Sets whether to treat values starting with an equals sign as formulas or as literal strings.
293
+ # @param [Boolean] value The value to set.
294
+ def escape_formulas=(value)
295
+ Axlsx.validate_boolean(value)
296
+ @escape_formulas = value
297
+ end
270
298
 
271
299
  # Indicates if the workbook should use autowidths or not.
272
300
  # @note This gem no longer depends on RMagick for autowidth
273
301
  # calculation. Thus the performance benefits of turning this off are
274
302
  # marginal unless you are creating a very large sheet.
275
303
  # @return [Boolean]
276
- def use_autowidth() @use_autowidth; end
304
+ attr_reader :use_autowidth
277
305
 
278
306
  # see @use_autowidth
279
- def use_autowidth=(v=true) Axlsx::validate_boolean v; @use_autowidth = v; end
307
+ def use_autowidth=(v = true)
308
+ Axlsx.validate_boolean v
309
+ @use_autowidth = v
310
+ end
280
311
 
281
312
  # Font size of bold fonts is multiplied with this
282
313
  # Used for automatic calculation of cell widths with bold text
@@ -284,7 +315,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
284
315
  attr_reader :bold_font_multiplier
285
316
 
286
317
  def bold_font_multiplier=(v)
287
- Axlsx::validate_float v
318
+ Axlsx.validate_float v
288
319
  @bold_font_multiplier = v
289
320
  end
290
321
 
@@ -294,7 +325,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
294
325
  attr_reader :font_scale_divisor
295
326
 
296
327
  def font_scale_divisor=(v)
297
- Axlsx::validate_float v
328
+ Axlsx.validate_float v
298
329
  @font_scale_divisor = v
299
330
  end
300
331
 
@@ -306,7 +337,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
306
337
  # @param [Hash] options Options to pass into the worksheed during initialization.
307
338
  # @option options [String] name The name of the worksheet
308
339
  # @option options [Hash] page_margins The page margins for the worksheet
309
- def insert_worksheet(index=0, options={})
340
+ def insert_worksheet(index = 0, options = {})
310
341
  worksheet = Worksheet.new(self, options)
311
342
  @worksheets.delete_at(@worksheets.size - 1)
312
343
  @worksheets.insert(index, worksheet)
@@ -320,7 +351,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
320
351
  # @option options [String] name The name of the worksheet.
321
352
  # @option options [Hash] page_margins The page margins for the worksheet.
322
353
  # @see Worksheet#initialize
323
- def add_worksheet(options={})
354
+ def add_worksheet(options = {})
324
355
  worksheet = Worksheet.new(self, options)
325
356
  yield worksheet if block_given?
326
357
  worksheet
@@ -330,7 +361,7 @@ require 'axlsx/workbook/worksheet/selection.rb'
330
361
  # @return WorkbookViews
331
362
  # @option options [Hash] options passed into the added WorkbookView
332
363
  # @see WorkbookView#initialize
333
- def add_view(options={})
364
+ def add_view(options = {})
334
365
  views << WorkbookView.new(options)
335
366
  end
336
367
 
@@ -347,14 +378,15 @@ require 'axlsx/workbook/worksheet/selection.rb'
347
378
  def relationships
348
379
  r = Relationships.new
349
380
  @worksheets.each do |sheet|
350
- r << Relationship.new(sheet, WORKSHEET_R, WORKSHEET_PN % (r.size+1))
381
+ r << Relationship.new(sheet, WORKSHEET_R, format(WORKSHEET_PN, r.size + 1))
351
382
  end
352
383
  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))
384
+ r << Relationship.new(pivot_table.cache_definition, PIVOT_TABLE_CACHE_DEFINITION_R, format(PIVOT_TABLE_CACHE_DEFINITION_PN, index + 1))
354
385
  end
355
- r << Relationship.new(self, STYLES_R, STYLES_PN)
386
+ r << Relationship.new(self, STYLES_R, STYLES_PN)
387
+ r << Relationship.new(self, THEME_R, THEME_PN)
356
388
  if use_shared_strings
357
- r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN)
389
+ r << Relationship.new(self, SHARED_STRINGS_R, SHARED_STRINGS_PN)
358
390
  end
359
391
  r
360
392
  end
@@ -362,11 +394,11 @@ require 'axlsx/workbook/worksheet/selection.rb'
362
394
  # generates a shared string object against all cells in all worksheets.
363
395
  # @return [SharedStringTable]
364
396
  def shared_strings
365
- SharedStringsTable.new(worksheets.collect { |ws| ws.cells }, xml_space)
397
+ SharedStringsTable.new(worksheets.collect(&:cells), xml_space)
366
398
  end
367
399
 
368
400
  # The xml:space attribute for the worksheet.
369
- # This determines how whitespace is handled withing the document.
401
+ # This determines how whitespace is handled within the document.
370
402
  # The most relevant part being whitespace in the cell text.
371
403
  # allowed values are :preserve and :default. Axlsx uses :preserve unless
372
404
  # you explicily set this to :default.
@@ -380,28 +412,29 @@ require 'axlsx/workbook/worksheet/selection.rb'
380
412
  # @param [Symbol] space must be one of :preserve or :default
381
413
  def xml_space=(space)
382
414
  Axlsx::RestrictionValidator.validate(:xml_space, [:preserve, :default], space)
383
- @xml_space = space;
415
+ @xml_space = space
384
416
  end
385
417
 
386
418
  # returns a range of cells in a worksheet
387
- # @param [String] cell_def The excel style reference defining the worksheet and cells. The range must specify the sheet to
419
+ # @param [String] cell_def The Excel style reference defining the worksheet and cells. The range must specify the sheet to
388
420
  # retrieve the cells from. e.g. range('Sheet1!A1:B2') will return an array of four cells [A1, A2, B1, B2] while range('Sheet1!A1') will return a single Cell.
389
421
  # @return [Cell, Array]
390
422
  def [](cell_def)
391
- sheet_name = cell_def.split('!')[0] if cell_def.match('!')
392
- worksheet = self.worksheets.select { |s| s.name == sheet_name }.first
423
+ sheet_name = cell_def.split('!')[0] if cell_def.include?('!')
424
+ worksheet = worksheets.find { |s| s.name == sheet_name }
393
425
  raise ArgumentError, 'Unknown Sheet' unless sheet_name && worksheet.is_a?(Worksheet)
394
- worksheet[cell_def.gsub(/.+!/,"")]
426
+
427
+ worksheet[cell_def.gsub(/.+!/, "")]
395
428
  end
396
429
 
397
430
  # Serialize the workbook
398
431
  # @param [String] str
399
432
  # @return [String]
400
- def to_xml_string(str='')
401
- add_worksheet(name: 'Sheet1') unless worksheets.size > 0
433
+ def to_xml_string(str = +'')
434
+ add_worksheet(name: 'Sheet1') if worksheets.empty?
402
435
  str << '<?xml version="1.0" encoding="UTF-8"?>'
403
- str << ('<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">')
404
- str << ('<workbookPr date1904="' << @@date1904.to_s << '"/>')
436
+ str << '<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">'
437
+ str << '<workbookPr date1904="' << @@date1904.to_s << '"/>'
405
438
  views.to_xml_string(str)
406
439
  str << '<sheets>'
407
440
  if is_reversed
@@ -414,12 +447,11 @@ require 'axlsx/workbook/worksheet/selection.rb'
414
447
  unless pivot_tables.empty?
415
448
  str << '<pivotCaches>'
416
449
  pivot_tables.each do |pivot_table|
417
- str << ('<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << pivot_table.cache_definition.rId << '"/>')
450
+ str << '<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << pivot_table.cache_definition.rId << '"/>'
418
451
  end
419
452
  str << '</pivotCaches>'
420
453
  end
421
454
  str << '</workbook>'
422
455
  end
423
-
424
456
  end
425
457
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # <xsd:complexType name="CT_BookView">
2
4
  # <xsd:sequence>
3
5
  # <xsd:element name="extLst" type="CT_ExtensionList" minOccurs="0" maxOccurs="1"/>
@@ -19,19 +21,16 @@
19
21
  # </xsd:complexType>
20
22
 
21
23
  module Axlsx
22
-
23
24
  # A BookView defines the display properties for a workbook.
24
25
  # Units for window widths and other dimensions are expressed in twips.
25
26
  # Twip measurements are portable between different display resolutions.
26
27
  # The formula is (screen pixels) * (20 * 72) / (logical device dpi),
27
28
  # where the logical device dpi can be different for x and y coordinates.
28
29
  class WorkbookView
29
-
30
30
  include Axlsx::SerializedAttributes
31
31
  include Axlsx::OptionsParser
32
32
  include Axlsx::Accessors
33
33
 
34
-
35
34
  # Creates a new BookView object
36
35
  # @param [Hash] options A hash of key/value pairs that will be mapped to this instances attributes.
37
36
  # @option [Symbol] visibility Specifies visible state of the workbook window. The default value for this attribute is :visible.
@@ -39,7 +38,7 @@ module Axlsx
39
38
  # @option [Boolean] show_horizontal_scroll Specifies a boolean value that indicates whether to display the horizontal scroll bar in the user interface.
40
39
  # @option [Boolean] show_vertical_scroll Specifies a boolean value that indicates whether to display the vertical scroll bar.
41
40
  # @option [Boolean] show_sheet_tabs Specifies a boolean value that indicates whether to display the sheet tabs in the user interface.
42
- # @option [Integer] tab_ratio Specifies ratio between the workbook tabs bar and the horizontal scroll bar.
41
+ # @option [Integer] tab_ratio Specifies the ratio between the workbook tabs bar and the horizontal scroll bar (from 0 to 1000, higher values mean more space for tabs). May only be supported on some clients.
43
42
  # @option [Integer] first_sheet Specifies the index to the first sheet in this book view.
44
43
  # @option [Integer] active_tab Specifies an unsignedInt that contains the index to the active sheet in this book view.
45
44
  # @option [Integer] x_window Specifies the X coordinate for the upper left corner of the workbook window. The unit of measurement for this value is twips.
@@ -47,16 +46,15 @@ module Axlsx
47
46
  # @option [Integer] window_width Specifies the width of the workbook window. The unit of measurement for this value is twips.
48
47
  # @option [Integer] window_height Specifies the height of the workbook window. The unit of measurement for this value is twips.
49
48
  # @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={})
49
+ def initialize(options = {})
51
50
  parse_options options
52
51
  yield self if block_given?
53
52
  end
54
53
 
55
-
56
54
  unsigned_int_attr_accessor :x_window, :y_window, :window_width, :window_height,
57
55
  :tab_ratio, :first_sheet, :active_tab
58
56
 
59
- validated_attr_accessor [:visibility], :validate_view_visibility
57
+ validated_attr_accessor [:visibility], :validate_view_visibility
60
58
 
61
59
  serializable_attributes :visibility, :minimized,
62
60
  :show_horizontal_scroll, :show_vertical_scroll,
@@ -67,14 +65,13 @@ module Axlsx
67
65
  boolean_attr_accessor :minimized, :show_horizontal_scroll, :show_vertical_scroll,
68
66
  :show_sheet_tabs, :auto_filter_date_grouping
69
67
 
70
-
71
68
  # Serialize the WorkbookView
72
69
  # @param [String] str
73
70
  # @return [String]
74
- def to_xml_string(str = '')
75
- str << '<workbookView '
76
- serialized_attributes str
77
- str << '></workbookView>'
71
+ def to_xml_string(str = +'')
72
+ str << '<workbookView '
73
+ serialized_attributes str
74
+ str << '></workbookView>'
78
75
  end
79
76
  end
80
77
  end
@@ -1,22 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Axlsx
2
4
  # a simple types list of BookView objects
3
5
  class WorkbookViews < SimpleTypedList
4
-
5
6
  # creates the book views object
6
7
  def initialize
7
- super WorkbookView
8
+ super(WorkbookView)
8
9
  end
9
10
 
10
11
  # Serialize to xml
11
12
  # @param [String] str
12
13
  # @return [String]
13
- def to_xml_string(str = '')
14
+ def to_xml_string(str = +'')
14
15
  return if empty?
16
+
15
17
  str << "<bookViews>"
16
18
  each { |view| view.to_xml_string(str) }
17
19
  str << '</bookViews>'
18
20
  end
19
21
  end
20
22
  end
21
-
22
-