caxlsx 4.0.0 → 4.4.1

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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +48 -12
  3. data/README.md +18 -9
  4. data/Rakefile +2 -9
  5. data/examples/generate.rb +3 -1
  6. data/lib/axlsx/content_type/abstract_content_type.rb +6 -3
  7. data/lib/axlsx/content_type/content_type.rb +4 -4
  8. data/lib/axlsx/content_type/default.rb +4 -1
  9. data/lib/axlsx/content_type/override.rb +4 -1
  10. data/lib/axlsx/doc_props/app.rb +91 -24
  11. data/lib/axlsx/drawing/area_chart.rb +3 -3
  12. data/lib/axlsx/drawing/area_series.rb +10 -4
  13. data/lib/axlsx/drawing/ax_data_source.rb +1 -1
  14. data/lib/axlsx/drawing/axes.rb +1 -1
  15. data/lib/axlsx/drawing/axis.rb +25 -7
  16. data/lib/axlsx/drawing/bar_3D_chart.rb +14 -4
  17. data/lib/axlsx/drawing/bar_chart.rb +14 -4
  18. data/lib/axlsx/drawing/bar_series.rb +14 -5
  19. data/lib/axlsx/drawing/bubble_chart.rb +2 -2
  20. data/lib/axlsx/drawing/bubble_series.rb +2 -2
  21. data/lib/axlsx/drawing/cat_axis.rb +23 -8
  22. data/lib/axlsx/drawing/chart.rb +33 -8
  23. data/lib/axlsx/drawing/d_lbls.rb +9 -8
  24. data/lib/axlsx/drawing/drawing.rb +50 -49
  25. data/lib/axlsx/drawing/hyperlink.rb +13 -4
  26. data/lib/axlsx/drawing/line_3D_chart.rb +3 -3
  27. data/lib/axlsx/drawing/line_chart.rb +3 -3
  28. data/lib/axlsx/drawing/line_series.rb +10 -4
  29. data/lib/axlsx/drawing/marker.rb +19 -4
  30. data/lib/axlsx/drawing/num_val.rb +1 -1
  31. data/lib/axlsx/drawing/one_cell_anchor.rb +8 -2
  32. data/lib/axlsx/drawing/pic.rb +17 -8
  33. data/lib/axlsx/drawing/pie_3D_chart.rb +3 -3
  34. data/lib/axlsx/drawing/pie_chart.rb +36 -0
  35. data/lib/axlsx/drawing/pie_series.rb +18 -6
  36. data/lib/axlsx/drawing/scaling.rb +18 -4
  37. data/lib/axlsx/drawing/scatter_chart.rb +2 -2
  38. data/lib/axlsx/drawing/scatter_series.rb +2 -2
  39. data/lib/axlsx/drawing/ser_axis.rb +11 -5
  40. data/lib/axlsx/drawing/series.rb +8 -2
  41. data/lib/axlsx/drawing/two_cell_anchor.rb +1 -1
  42. data/lib/axlsx/drawing/val_axis.rb +2 -2
  43. data/lib/axlsx/drawing/view_3D.rb +8 -2
  44. data/lib/axlsx/drawing/vml_shape.rb +1 -1
  45. data/lib/axlsx/package.rb +54 -21
  46. data/lib/axlsx/rels/relationship.rb +15 -5
  47. data/lib/axlsx/rels/relationships.rb +3 -3
  48. data/lib/axlsx/stylesheet/border.rb +12 -3
  49. data/lib/axlsx/stylesheet/border_pr.rb +16 -4
  50. data/lib/axlsx/stylesheet/cell_alignment.rb +39 -10
  51. data/lib/axlsx/stylesheet/cell_protection.rb +9 -2
  52. data/lib/axlsx/stylesheet/cell_style.rb +30 -7
  53. data/lib/axlsx/stylesheet/color.rb +10 -4
  54. data/lib/axlsx/stylesheet/dxf.rb +29 -6
  55. data/lib/axlsx/stylesheet/fill.rb +4 -1
  56. data/lib/axlsx/stylesheet/font.rb +59 -13
  57. data/lib/axlsx/stylesheet/gradient_fill.rb +9 -3
  58. data/lib/axlsx/stylesheet/gradient_stop.rb +9 -2
  59. data/lib/axlsx/stylesheet/num_fmt.rb +8 -2
  60. data/lib/axlsx/stylesheet/pattern_fill.rb +15 -3
  61. data/lib/axlsx/stylesheet/styles.rb +84 -43
  62. data/lib/axlsx/stylesheet/table_style.rb +15 -4
  63. data/lib/axlsx/stylesheet/table_style_element.rb +12 -3
  64. data/lib/axlsx/stylesheet/table_styles.rb +10 -3
  65. data/lib/axlsx/stylesheet/theme.rb +163 -0
  66. data/lib/axlsx/stylesheet/xf.rb +70 -16
  67. data/lib/axlsx/util/accessors.rb +9 -7
  68. data/lib/axlsx/util/buffered_zip_output_stream.rb +6 -2
  69. data/lib/axlsx/util/constants.rb +14 -2
  70. data/lib/axlsx/util/mime_type_utils.rb +72 -13
  71. data/lib/axlsx/util/serialized_attributes.rb +2 -2
  72. data/lib/axlsx/util/simple_typed_list.rb +26 -14
  73. data/lib/axlsx/util/storage.rb +4 -4
  74. data/lib/axlsx/util/uri_utils.rb +70 -0
  75. data/lib/axlsx/util/validators.rb +6 -6
  76. data/lib/axlsx/version.rb +1 -1
  77. data/lib/axlsx/workbook/defined_name.rb +2 -1
  78. data/lib/axlsx/workbook/defined_names.rb +1 -1
  79. data/lib/axlsx/workbook/shared_strings_table.rb +3 -3
  80. data/lib/axlsx/workbook/workbook.rb +87 -67
  81. data/lib/axlsx/workbook/workbook_view.rb +1 -1
  82. data/lib/axlsx/workbook/workbook_views.rb +1 -1
  83. data/lib/axlsx/workbook/worksheet/auto_filter/auto_filter.rb +4 -4
  84. data/lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb +5 -3
  85. data/lib/axlsx/workbook/worksheet/auto_filter/filters.rb +4 -4
  86. data/lib/axlsx/workbook/worksheet/auto_filter/sort_condition.rb +1 -1
  87. data/lib/axlsx/workbook/worksheet/auto_filter/sort_state.rb +2 -2
  88. data/lib/axlsx/workbook/worksheet/border_creator.rb +4 -4
  89. data/lib/axlsx/workbook/worksheet/cell.rb +40 -20
  90. data/lib/axlsx/workbook/worksheet/cell_serializer.rb +1 -1
  91. data/lib/axlsx/workbook/worksheet/cfvo.rb +8 -2
  92. data/lib/axlsx/workbook/worksheet/col.rb +23 -9
  93. data/lib/axlsx/workbook/worksheet/col_breaks.rb +1 -1
  94. data/lib/axlsx/workbook/worksheet/cols.rb +1 -1
  95. data/lib/axlsx/workbook/worksheet/comment.rb +2 -2
  96. data/lib/axlsx/workbook/worksheet/comments.rb +1 -1
  97. data/lib/axlsx/workbook/worksheet/conditional_formatting.rb +9 -3
  98. data/lib/axlsx/workbook/worksheet/conditional_formatting_rule.rb +70 -15
  99. data/lib/axlsx/workbook/worksheet/conditional_formattings.rb +3 -3
  100. data/lib/axlsx/workbook/worksheet/data_validation.rb +53 -14
  101. data/lib/axlsx/workbook/worksheet/data_validations.rb +3 -3
  102. data/lib/axlsx/workbook/worksheet/date_time_converter.rb +2 -2
  103. data/lib/axlsx/workbook/worksheet/dimension.rb +1 -1
  104. data/lib/axlsx/workbook/worksheet/header_footer.rb +1 -1
  105. data/lib/axlsx/workbook/worksheet/icon_set.rb +17 -5
  106. data/lib/axlsx/workbook/worksheet/merged_cells.rb +1 -1
  107. data/lib/axlsx/workbook/worksheet/outline_pr.rb +1 -1
  108. data/lib/axlsx/workbook/worksheet/page_margins.rb +30 -7
  109. data/lib/axlsx/workbook/worksheet/page_set_up_pr.rb +1 -2
  110. data/lib/axlsx/workbook/worksheet/page_setup.rb +32 -9
  111. data/lib/axlsx/workbook/worksheet/pane.rb +9 -2
  112. data/lib/axlsx/workbook/worksheet/pivot_table.rb +30 -6
  113. data/lib/axlsx/workbook/worksheet/pivot_tables.rb +1 -1
  114. data/lib/axlsx/workbook/worksheet/print_options.rb +1 -0
  115. data/lib/axlsx/workbook/worksheet/protected_ranges.rb +1 -1
  116. data/lib/axlsx/workbook/worksheet/rich_text_run.rb +31 -11
  117. data/lib/axlsx/workbook/worksheet/row.rb +5 -2
  118. data/lib/axlsx/workbook/worksheet/row_breaks.rb +1 -1
  119. data/lib/axlsx/workbook/worksheet/selection.rb +8 -2
  120. data/lib/axlsx/workbook/worksheet/sheet_calc_pr.rb +1 -0
  121. data/lib/axlsx/workbook/worksheet/sheet_pr.rb +1 -1
  122. data/lib/axlsx/workbook/worksheet/sheet_protection.rb +1 -1
  123. data/lib/axlsx/workbook/worksheet/sheet_view.rb +30 -9
  124. data/lib/axlsx/workbook/worksheet/table_style_info.rb +3 -2
  125. data/lib/axlsx/workbook/worksheet/tables.rb +1 -1
  126. data/lib/axlsx/workbook/worksheet/worksheet.rb +28 -14
  127. data/lib/axlsx/workbook/worksheet/worksheet_comments.rb +4 -4
  128. data/lib/axlsx/workbook/worksheet/worksheet_drawing.rb +1 -1
  129. data/lib/axlsx/workbook/worksheet/worksheet_hyperlink.rb +3 -2
  130. data/lib/axlsx/workbook/worksheet/worksheet_hyperlinks.rb +2 -2
  131. data/lib/axlsx.rb +46 -30
  132. data/lib/caxlsx.rb +1 -1
  133. metadata +13 -52
@@ -7,7 +7,7 @@ module Axlsx
7
7
  def initialize(worksheet)
8
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
9
 
10
- super PivotTable
10
+ super(PivotTable)
11
11
  @worksheet = worksheet
12
12
  end
13
13
 
@@ -10,6 +10,7 @@ module Axlsx
10
10
  include Axlsx::OptionsParser
11
11
  include Axlsx::SerializedAttributes
12
12
  include Axlsx::Accessors
13
+
13
14
  # Creates a new PrintOptions object
14
15
  # @option options [Boolean] grid_lines Whether grid lines should be printed
15
16
  # @option options [Boolean] headings Whether row and column headings should be printed
@@ -9,7 +9,7 @@ module Axlsx
9
9
  def initialize(worksheet)
10
10
  raise ArgumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
11
11
 
12
- super ProtectedRange
12
+ super(ProtectedRange)
13
13
  @worksheet = worksheet
14
14
  end
15
15
 
@@ -29,7 +29,9 @@ module Axlsx
29
29
  attr_reader :font_name
30
30
 
31
31
  # @see font_name
32
- def font_name=(v) set_run_style :validate_string, :font_name, v; end
32
+ def font_name=(v)
33
+ set_run_style :validate_string, :font_name, v
34
+ end
33
35
 
34
36
  # The inline charset property for the cell
35
37
  # As far as I can tell, this is pretty much ignored. However, based on the spec it should be one of the following:
@@ -56,7 +58,9 @@ module Axlsx
56
58
  attr_reader :charset
57
59
 
58
60
  # @see charset
59
- def charset=(v) set_run_style :validate_unsigned_int, :charset, v; end
61
+ def charset=(v)
62
+ set_run_style :validate_unsigned_int, :charset, v
63
+ end
60
64
 
61
65
  # The inline family property for the cell
62
66
  # @return [Integer]
@@ -77,55 +81,69 @@ module Axlsx
77
81
  attr_reader :b
78
82
 
79
83
  # @see b
80
- def b=(v) set_run_style :validate_boolean, :b, v; end
84
+ def b=(v)
85
+ set_run_style :validate_boolean, :b, v
86
+ end
81
87
 
82
88
  # The inline italic property for the cell
83
89
  # @return [Boolean]
84
90
  attr_reader :i
85
91
 
86
92
  # @see i
87
- def i=(v) set_run_style :validate_boolean, :i, v; end
93
+ def i=(v)
94
+ set_run_style :validate_boolean, :i, v
95
+ end
88
96
 
89
97
  # The inline strike property for the cell
90
98
  # @return [Boolean]
91
99
  attr_reader :strike
92
100
 
93
101
  # @see strike
94
- def strike=(v) set_run_style :validate_boolean, :strike, v; end
102
+ def strike=(v)
103
+ set_run_style :validate_boolean, :strike, v
104
+ end
95
105
 
96
106
  # The inline outline property for the cell
97
107
  # @return [Boolean]
98
108
  attr_reader :outline
99
109
 
100
110
  # @see outline
101
- def outline=(v) set_run_style :validate_boolean, :outline, v; end
111
+ def outline=(v)
112
+ set_run_style :validate_boolean, :outline, v
113
+ end
102
114
 
103
115
  # The inline shadow property for the cell
104
116
  # @return [Boolean]
105
117
  attr_reader :shadow
106
118
 
107
119
  # @see shadow
108
- def shadow=(v) set_run_style :validate_boolean, :shadow, v; end
120
+ def shadow=(v)
121
+ set_run_style :validate_boolean, :shadow, v
122
+ end
109
123
 
110
124
  # The inline condense property for the cell
111
125
  # @return [Boolean]
112
126
  attr_reader :condense
113
127
 
114
128
  # @see condense
115
- def condense=(v) set_run_style :validate_boolean, :condense, v; end
129
+ def condense=(v)
130
+ set_run_style :validate_boolean, :condense, v
131
+ end
116
132
 
117
133
  # The inline extend property for the cell
118
134
  # @return [Boolean]
119
135
  attr_reader :extend
120
136
 
121
137
  # @see extend
122
- def extend=(v) set_run_style :validate_boolean, :extend, v; end
138
+ def extend=(v)
139
+ set_run_style :validate_boolean, :extend, v
140
+ end
123
141
 
124
142
  # The inline underline property for the cell.
125
143
  # It must be one of :none, :single, :double, :singleAccounting, :doubleAccounting, true
126
144
  # @return [Boolean]
127
145
  # @return [String]
128
- # @note true is for backwards compatability and is reassigned to :single
146
+ # @note true is for backwards compatibility and is reassigned to :single
129
147
  attr_reader :u
130
148
 
131
149
  # @see u
@@ -148,7 +166,9 @@ module Axlsx
148
166
  attr_reader :sz
149
167
 
150
168
  # @see sz
151
- def sz=(v) set_run_style :validate_unsigned_int, :sz, v; end
169
+ def sz=(v)
170
+ set_run_style :validate_unsigned_int, :sz, v
171
+ end
152
172
 
153
173
  # The inline vertical alignment property for the cell
154
174
  # this must be one of [:baseline, :subscript, :superscript]
@@ -143,7 +143,10 @@ module Axlsx
143
143
  private
144
144
 
145
145
  # assigns the owning worksheet for this row
146
- def worksheet=(v) DataTypeValidator.validate :row_worksheet, Worksheet, v; @worksheet = v; end
146
+ def worksheet=(v)
147
+ DataTypeValidator.validate :row_worksheet, Worksheet, v
148
+ @worksheet = v
149
+ end
147
150
 
148
151
  # Converts values, types, and style options into cells and associates them with this row.
149
152
  # A new cell is created for each item in the values array.
@@ -160,7 +163,7 @@ module Axlsx
160
163
  types, style, formula_values, escape_formulas, offset = options.delete(:types), options.delete(:style), options.delete(:formula_values), options.delete(:escape_formulas), options.delete(:offset)
161
164
  offset.to_i.times { |index| self[index] = Cell.new(self) } if offset
162
165
  values.each_with_index do |value, index|
163
- options[:style] = style.is_a?(Array) ? style[index] : style if style
166
+ options[:style] = (style.is_a?(Array) ? style[index] : style) || worksheet.column_info[index]&.style
164
167
  options[:type] = types.is_a?(Array) ? types[index] : types if types
165
168
  options[:escape_formulas] = escape_formulas.is_a?(Array) ? escape_formulas[index] : escape_formulas unless escape_formulas.nil?
166
169
  options[:formula_value] = formula_values[index] if formula_values.is_a?(Array)
@@ -5,7 +5,7 @@ module Axlsx
5
5
 
6
6
  class RowBreaks < SimpleTypedList
7
7
  def initialize
8
- super Break
8
+ super(Break)
9
9
  end
10
10
 
11
11
  # Adds a row break
@@ -80,7 +80,10 @@ module Axlsx
80
80
  end
81
81
 
82
82
  # @see active_cell_id
83
- def active_cell_id=(v); Axlsx.validate_unsigned_int(v); @active_cell_id = v end
83
+ def active_cell_id=(v)
84
+ Axlsx.validate_unsigned_int(v)
85
+ @active_cell_id = v
86
+ end
84
87
 
85
88
  # @see pane
86
89
  def pane=(v)
@@ -89,7 +92,10 @@ module Axlsx
89
92
  end
90
93
 
91
94
  # @see sqref
92
- def sqref=(v); Axlsx.validate_string(v); @sqref = v end
95
+ def sqref=(v)
96
+ Axlsx.validate_string(v)
97
+ @sqref = v
98
+ end
93
99
 
94
100
  # Serializes the data validation
95
101
  # @param [String] str
@@ -7,6 +7,7 @@ module Axlsx
7
7
  include Axlsx::OptionsParser
8
8
  include Axlsx::SerializedAttributes
9
9
  include Axlsx::Accessors
10
+
10
11
  # creates a new SheetCalcPr
11
12
  # @param [Hash] options Options for this object
12
13
  # @option [Boolean] full_calc_on_load @see full_calc_on_load
@@ -18,7 +18,7 @@ module Axlsx
18
18
  :sync_ref
19
19
 
20
20
  # These attributes are all boolean so I'm doing a bit of a hand
21
- # waving magic show to set up the attriubte accessors
21
+ # waving magic show to set up the attribute accessors
22
22
  boolean_attr_accessor :sync_horizontal,
23
23
  :sync_vertical,
24
24
  :transition_evaluation,
@@ -106,7 +106,7 @@ module Axlsx
106
106
  char = char.unpack1('c') << i # ord << i
107
107
  low_15 = char & 0x7fff
108
108
  high_15 = char & (0x7fff << 15)
109
- high_15 = high_15 >> 15
109
+ high_15 >>= 15
110
110
  low_15 | high_15
111
111
  end
112
112
 
@@ -33,8 +33,8 @@ module Axlsx
33
33
  def initialize(options = {})
34
34
  # defaults
35
35
  @color_id = @top_left_cell = @pane = nil
36
- @right_to_left = @show_formulas = @show_outline_symbols = @show_white_space = @tab_selected = @window_protection = false
37
- @default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = true
36
+ @right_to_left = @show_formulas = @show_white_space = @tab_selected = @window_protection = false
37
+ @default_grid_color = @show_grid_lines = @show_row_col_headers = @show_ruler = @show_zeros = @show_outline_symbols = true
38
38
  @zoom_scale = 100
39
39
  @zoom_scale_normal = @zoom_scale_page_layout_view = @zoom_scale_sheet_layout_view = @workbook_view_id = 0
40
40
  @selections = {}
@@ -162,7 +162,10 @@ module Axlsx
162
162
  end
163
163
 
164
164
  # @see color_id
165
- def color_id=(v); Axlsx.validate_unsigned_int(v); @color_id = v end
165
+ def color_id=(v)
166
+ Axlsx.validate_unsigned_int(v)
167
+ @color_id = v
168
+ end
166
169
 
167
170
  # @see top_left_cell
168
171
  def top_left_cell=(v)
@@ -172,22 +175,40 @@ module Axlsx
172
175
  end
173
176
 
174
177
  # @see view
175
- def view=(v); Axlsx.validate_sheet_view_type(v); @view = v end
178
+ def view=(v)
179
+ Axlsx.validate_sheet_view_type(v)
180
+ @view = v
181
+ end
176
182
 
177
183
  # @see workbook_view_id
178
- def workbook_view_id=(v); Axlsx.validate_unsigned_int(v); @workbook_view_id = v end
184
+ def workbook_view_id=(v)
185
+ Axlsx.validate_unsigned_int(v)
186
+ @workbook_view_id = v
187
+ end
179
188
 
180
189
  # @see zoom_scale
181
- def zoom_scale=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale = v end
190
+ def zoom_scale=(v)
191
+ Axlsx.validate_scale_0_10_400(v)
192
+ @zoom_scale = v
193
+ end
182
194
 
183
195
  # @see zoom_scale_normal
184
- def zoom_scale_normal=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_normal = v end
196
+ def zoom_scale_normal=(v)
197
+ Axlsx.validate_scale_0_10_400(v)
198
+ @zoom_scale_normal = v
199
+ end
185
200
 
186
201
  # @see zoom_scale_page_layout_view
187
- def zoom_scale_page_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_page_layout_view = v end
202
+ def zoom_scale_page_layout_view=(v)
203
+ Axlsx.validate_scale_0_10_400(v)
204
+ @zoom_scale_page_layout_view = v
205
+ end
188
206
 
189
207
  # @see zoom_scale_sheet_layout_view
190
- def zoom_scale_sheet_layout_view=(v); Axlsx.validate_scale_0_10_400(v); @zoom_scale_sheet_layout_view = v end
208
+ def zoom_scale_sheet_layout_view=(v)
209
+ Axlsx.validate_scale_0_10_400(v)
210
+ @zoom_scale_sheet_layout_view = v
211
+ end
191
212
 
192
213
  # Serializes the data validation
193
214
  # @param [String] str
@@ -7,6 +7,7 @@ module Axlsx
7
7
  include Axlsx::OptionsParser
8
8
  include Axlsx::SerializedAttributes
9
9
  include Axlsx::Accessors
10
+
10
11
  # creates a new TableStyleInfo instance
11
12
  # @param [Hash] options
12
13
  # @option [Boolean] show_first_column indicates if the first column should
@@ -34,14 +35,14 @@ module Axlsx
34
35
  # explicitly be disabled or all will show.
35
36
  def initialize_defaults
36
37
  %w(show_first_column show_last_column show_row_stripes show_column_stripes).each do |attr|
37
- send("#{attr}=", 0)
38
+ send(:"#{attr}=", 0)
38
39
  end
39
40
  end
40
41
 
41
42
  # The name of the table style.
42
43
  attr_accessor :name
43
44
 
44
- # seralizes this object to an xml string
45
+ # serializes this object to an xml string
45
46
  # @param [String] str the string to contact this objects serialization to.
46
47
  def to_xml_string(str = +'')
47
48
  serialized_tag('tableStyleInfo', str)
@@ -7,7 +7,7 @@ module Axlsx
7
7
  def initialize(worksheet)
8
8
  raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)
9
9
 
10
- super Table
10
+ super(Table)
11
11
  @worksheet = worksheet
12
12
  end
13
13
 
@@ -31,11 +31,11 @@ module Axlsx
31
31
 
32
32
  serializable_attributes :sheet_id, :state
33
33
 
34
- # Initalizes page margin, setup and print options
34
+ # Initializes page margin, setup and print options
35
35
  # @param [Hash] options Options passed in from the initializer
36
36
  def initialize_page_options(options)
37
37
  @page_margins = PageMargins.new options[:page_margins] if options[:page_margins]
38
- @page_setup = PageSetup.new options[:page_setup] if options[:page_setup]
38
+ @page_setup = PageSetup.new options[:page_setup] if options[:page_setup]
39
39
  @print_options = PrintOptions.new options[:print_options] if options[:print_options]
40
40
  @header_footer = HeaderFooter.new options[:header_footer] if options[:header_footer]
41
41
  @row_breaks = RowBreaks.new
@@ -181,7 +181,7 @@ module Axlsx
181
181
  @auto_filter ||= AutoFilter.new self
182
182
  end
183
183
 
184
- # Indicates if the worksheet will be fit by witdh or height to a specific number of pages.
184
+ # Indicates if the worksheet will be fit by width or height to a specific number of pages.
185
185
  # To alter the width or height for page fitting, please use page_setup.fit_to_widht or page_setup.fit_to_height.
186
186
  # If you want the worksheet to fit on more pages (e.g. 2x2), set {PageSetup#fit_to_width} and {PageSetup#fit_to_height} accordingly.
187
187
  # @return Boolean
@@ -421,7 +421,7 @@ module Axlsx
421
421
  # @option options [Array] values
422
422
  # @option options [Array, Symbol] types
423
423
  # @option options [Array, Integer] style
424
- # @option options [Array] widths each member of the widths array will affect how auto_fit behavies.
424
+ # @option options [Array] widths each member of the widths array will affect how auto_fit behaves.
425
425
  # @option options [Float] height the row's height (in points)
426
426
  # @option options [Integer] offset - add empty columns before values
427
427
  # @option options [Array, Boolean] escape_formulas - Whether to treat a value starting with an equal
@@ -552,6 +552,19 @@ module Axlsx
552
552
  end
553
553
  end
554
554
 
555
+ # This is a helper method that lets you specify a default style for multiple columns in a worksheet in one go.
556
+ # This style will be applied for all not-yet-defined cells in a column.
557
+ # Note that you must call column_styles BEFORE adding data, otherwise the styles will not be set successfully for new cells.
558
+ # @param [Integer] styles the cellXfs indexes
559
+ def column_styles(*styles)
560
+ styles.each_with_index do |style, index|
561
+ next if style.nil?
562
+
563
+ Axlsx.validate_unsigned_int(style)
564
+ find_or_create_column_info(index).style = style
565
+ end
566
+ end
567
+
555
568
  # Set the style for cells in a specific column
556
569
  # @param [Integer] index the index of the column
557
570
  # @param [Integer] style the cellXfs index
@@ -653,12 +666,11 @@ module Axlsx
653
666
  # @return [Relationships]
654
667
  def relationships
655
668
  r = Relationships.new
656
- r + [tables.relationships,
657
- worksheet_comments.relationships,
658
- hyperlinks.relationships,
659
- worksheet_drawing.relationship,
660
- pivot_tables.relationships].flatten.compact || []
661
- r
669
+ r.concat [tables.relationships,
670
+ worksheet_comments.relationships,
671
+ hyperlinks.relationships,
672
+ worksheet_drawing.relationship,
673
+ pivot_tables.relationships].flatten.compact
662
674
  end
663
675
 
664
676
  # Returns the cell or cells defined using Excel style A1:B3 references.
@@ -715,7 +727,7 @@ module Axlsx
715
727
  end
716
728
 
717
729
  # shortcut level to specify the outline level for a series of rows
718
- # Oulining is what lets you add collapse and expand to a data set.
730
+ # Outlining is what lets you add collapse and expand to a data set.
719
731
  # @param [Integer] start_index The zero based index of the first row of outlining.
720
732
  # @param [Integer] end_index The zero based index of the last row to be outlined
721
733
  # @param [integer] level The level of outline to apply
@@ -725,7 +737,7 @@ module Axlsx
725
737
  end
726
738
 
727
739
  # shortcut level to specify the outline level for a series of columns
728
- # Oulining is what lets you add collapse and expand to a data set.
740
+ # Outlining is what lets you add collapse and expand to a data set.
729
741
  # @param [Integer] start_index The zero based index of the first column of outlining.
730
742
  # @param [Integer] end_index The zero based index of the last column to be outlined
731
743
  # @param [integer] level The level of outline to apply
@@ -833,13 +845,15 @@ module Axlsx
833
845
  @worksheet_comments ||= WorksheetComments.new self
834
846
  end
835
847
 
836
- def workbook=(v) DataTypeValidator.validate "Worksheet.workbook", Workbook, v; @workbook = v; end
848
+ def workbook=(v)
849
+ DataTypeValidator.validate "Worksheet.workbook", Workbook, v
850
+ @workbook = v
851
+ end
837
852
 
838
853
  def update_column_info(cells, widths = nil)
839
854
  cells.each_with_index do |cell, index|
840
855
  width = widths ? widths[index] : nil
841
856
  col = find_or_create_column_info(index)
842
- next if width == :ignore
843
857
 
844
858
  col.update_width(cell, width, workbook.use_autowidth)
845
859
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Axlsx
4
- # A wraper class for comments that defines its on worksheet
5
- # serailization
4
+ # A wrapper class for comments that defines its on worksheet
5
+ # serialization
6
6
  class WorksheetComments
7
7
  # Creates a new WorksheetComments object
8
- # param [Worksheet] worksheet The worksheet comments in thes object belong to
8
+ # param [Worksheet] worksheet The worksheet to which the comments belong
9
9
  def initialize(worksheet)
10
10
  raise ArugumentError, 'You must provide a worksheet' unless worksheet.is_a?(Worksheet)
11
11
 
@@ -37,7 +37,7 @@ module Axlsx
37
37
 
38
38
  # Helper method to tell us if there are comments in the comments collection
39
39
  # @return [Boolean]
40
- def has_comments? # rubocop:disable Naming/PredicateName
40
+ def has_comments? # rubocop:disable Naming/PredicatePrefix
41
41
  !comments.empty?
42
42
  end
43
43
 
@@ -42,7 +42,7 @@ module Axlsx
42
42
 
43
43
  # helper method to tell us if the drawing has something in it or not
44
44
  # @return [Boolean]
45
- def has_drawing? # rubocop:disable Naming/PredicateName
45
+ def has_drawing? # rubocop:disable Naming/PredicatePrefix
46
46
  @drawing.is_a? Drawing
47
47
  end
48
48
 
@@ -6,6 +6,7 @@ module Axlsx
6
6
  include Axlsx::OptionsParser
7
7
  include Axlsx::Accessors
8
8
  include Axlsx::SerializedAttributes
9
+
9
10
  # Creates a new hyperlink object.
10
11
  # @note the preferred way to add hyperlinks to your worksheet is the Worksheet#add_hyperlink method
11
12
  # @param [Worksheet] worksheet the Worksheet that owns this hyperlink
@@ -55,12 +56,12 @@ module Axlsx
55
56
  Relationship.new(self, HYPERLINK_R, location, target_mode: :External)
56
57
  end
57
58
 
58
- # Seralize the object
59
+ # Serialize the object
59
60
  # @param [String] str
60
61
  # @return [String]
61
62
  def to_xml_string(str = +'')
62
63
  str << '<hyperlink '
63
- serialized_attributes str, location_or_id
64
+ serialized_attributes str, location_or_id, false
64
65
  str << '/>'
65
66
  end
66
67
 
@@ -8,7 +8,7 @@ module Axlsx
8
8
  def initialize(worksheet)
9
9
  DataTypeValidator.validate "Hyperlinks.worksheet", [Worksheet], worksheet
10
10
  @worksheet = worksheet
11
- super WorksheetHyperlink
11
+ super(WorksheetHyperlink)
12
12
  end
13
13
 
14
14
  # Creates and adds a new hyperlink based on the options provided
@@ -27,7 +27,7 @@ module Axlsx
27
27
  map(&:relationship)
28
28
  end
29
29
 
30
- # seralize the collection of hyperlinks
30
+ # serialize the collection of hyperlinks
31
31
  # @return [String]
32
32
  def to_xml_string(str = +'')
33
33
  return if empty?
data/lib/axlsx.rb CHANGED
@@ -1,38 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'axlsx/version'
4
+
5
+ # gemspec dependencies
3
6
  require 'htmlentities'
4
- require 'axlsx/version'
5
7
  require 'marcel'
6
-
7
- require 'axlsx/util/simple_typed_list'
8
- require 'axlsx/util/constants'
9
- require 'axlsx/util/validators'
10
- require 'axlsx/util/accessors'
11
- require 'axlsx/util/serialized_attributes'
12
- require 'axlsx/util/options_parser'
13
- require 'axlsx/util/mime_type_utils'
14
- require 'axlsx/util/buffered_zip_output_stream'
15
- require 'axlsx/util/zip_command'
16
-
17
- require 'axlsx/stylesheet/styles'
18
-
19
- require 'axlsx/doc_props/app'
20
- require 'axlsx/doc_props/core'
21
- require 'axlsx/content_type/content_type'
22
- require 'axlsx/rels/relationships'
23
-
24
- require 'axlsx/drawing/drawing'
25
- require 'axlsx/workbook/workbook'
26
- require 'axlsx/package'
27
- # required gems
28
8
  require 'nokogiri'
29
9
  require 'zip'
30
10
 
31
- # core dependencies
32
- require 'bigdecimal'
11
+ # Ruby core dependencies
33
12
  require 'cgi'
34
13
  require 'set'
35
14
  require 'time'
15
+ require 'uri'
16
+ require 'net/http'
17
+
18
+ require_relative 'axlsx/util/simple_typed_list'
19
+ require_relative 'axlsx/util/constants'
20
+ require_relative 'axlsx/util/validators'
21
+ require_relative 'axlsx/util/accessors'
22
+ require_relative 'axlsx/util/serialized_attributes'
23
+ require_relative 'axlsx/util/options_parser'
24
+ require_relative 'axlsx/util/uri_utils'
25
+ require_relative 'axlsx/util/mime_type_utils'
26
+ require_relative 'axlsx/util/buffered_zip_output_stream'
27
+ require_relative 'axlsx/util/zip_command'
28
+
29
+ require_relative 'axlsx/stylesheet/styles'
30
+
31
+ require_relative 'axlsx/doc_props/app'
32
+ require_relative 'axlsx/doc_props/core'
33
+ require_relative 'axlsx/content_type/content_type'
34
+ require_relative 'axlsx/rels/relationships'
35
+
36
+ require_relative 'axlsx/drawing/drawing'
37
+ require_relative 'axlsx/workbook/workbook'
38
+ require_relative 'axlsx/package'
36
39
 
37
40
  if Gem.loaded_specs.key?("axlsx_styler")
38
41
  raise StandardError, "Please remove `axlsx_styler` from your Gemfile, the associated functionality is now built-in to `caxlsx` directly."
@@ -88,12 +91,10 @@ module Axlsx
88
91
  letters_str = name[/[A-Z]+/]
89
92
 
90
93
  # capitalization?!?
91
- v = letters_str.reverse.chars.reduce({ base: 1, i: 0 }) do |val, c|
94
+ v = letters_str.reverse.chars.each_with_object({ base: 1, i: 0 }) do |c, val|
92
95
  val[:i] += ((c.bytes.first - 64) * val[:base])
93
96
 
94
97
  val[:base] *= 26
95
-
96
- next val
97
98
  end
98
99
 
99
100
  col_index = (v[:i] - 1)
@@ -154,7 +155,7 @@ module Axlsx
154
155
  end
155
156
  end
156
157
 
157
- # performs the increadible feat of changing snake_case to CamelCase
158
+ # performs the incredible feat of changing snake_case to CamelCase
158
159
  # @param [String] s The snake case string to camelize
159
160
  # @return [String]
160
161
  def self.camel(s = "", all_caps = true)
@@ -163,7 +164,7 @@ module Axlsx
163
164
  s.gsub(/_(.)/) { ::Regexp.last_match(1).upcase }
164
165
  end
165
166
 
166
- # returns the provided string with all invalid control charaters
167
+ # returns the provided string with all invalid control characters
167
168
  # removed.
168
169
  # @param [String] str The string to process
169
170
  # @return [String]
@@ -229,4 +230,19 @@ module Axlsx
229
230
  Axlsx.validate_boolean(value)
230
231
  @escape_formulas = value
231
232
  end
233
+
234
+ # Returns a URI parser instance, preferring RFC2396_PARSER if available,
235
+ # otherwise falling back to DEFAULT_PARSER. This method ensures consistent
236
+ # URI parsing across different Ruby versions.
237
+ # This method can be removed when dropping compatibility for Ruby < 3.4
238
+ # See https://github.com/ruby/uri/pull/114 for details.
239
+ # @return [Object]
240
+ def self.uri_parser
241
+ @uri_parser ||=
242
+ if defined?(URI::RFC2396_PARSER)
243
+ URI::RFC2396_PARSER
244
+ else
245
+ URI::DEFAULT_PARSER
246
+ end
247
+ end
232
248
  end
data/lib/caxlsx.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'axlsx'
3
+ require_relative 'axlsx'