xlsxrb 0.1.16 → 0.1.18

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/README.md +81 -21
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +619 -98
  6. data/lib/xlsxrb/dsl_helpers.rb +583 -15
  7. data/lib/xlsxrb/elements/cell.rb +265 -53
  8. data/lib/xlsxrb/elements/column.rb +95 -6
  9. data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
  10. data/lib/xlsxrb/elements/image.rb +81 -15
  11. data/lib/xlsxrb/elements/metadata.rb +2733 -0
  12. data/lib/xlsxrb/elements/row.rb +130 -46
  13. data/lib/xlsxrb/elements/styles.rb +184 -76
  14. data/lib/xlsxrb/elements/types.rb +243 -7
  15. data/lib/xlsxrb/elements/workbook.rb +202 -65
  16. data/lib/xlsxrb/elements/worksheet.rb +728 -85
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
  22. data/lib/xlsxrb/ooxml/reader.rb +92 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
  24. data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
  25. data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
  26. data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
  27. data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
  28. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
  29. data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
  30. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
  31. data/lib/xlsxrb/ooxml/writer.rb +288 -35
  32. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  33. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  34. data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
  35. data/lib/xlsxrb/stream_row.rb +97 -18
  36. data/lib/xlsxrb/stream_sheet.rb +827 -157
  37. data/lib/xlsxrb/stream_writer.rb +2766 -375
  38. data/lib/xlsxrb/style_builder.rb +821 -105
  39. data/lib/xlsxrb/utils.rb +82 -57
  40. data/lib/xlsxrb/version.rb +1 -1
  41. data/lib/xlsxrb/workbook_builder.rb +542 -62
  42. data/lib/xlsxrb/worksheet_builder.rb +2279 -209
  43. data/lib/xlsxrb.rb +1539 -344
  44. data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
  45. data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
  46. data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
  47. data/sig/generated/xlsxrb/elements/column.rbs +62 -3
  48. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  49. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  50. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  51. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  52. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  53. data/sig/generated/xlsxrb/elements/types.rbs +29 -0
  54. data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
  55. data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
  56. data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
  57. data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
  58. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
  59. data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
  60. data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
  61. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
  62. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
  63. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
  64. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
  65. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
  66. data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
  67. data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
  68. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  69. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  70. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
  71. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  72. data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
  73. data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
  74. data/sig/generated/xlsxrb/style_builder.rbs +403 -75
  75. data/sig/generated/xlsxrb/utils.rbs +49 -13
  76. data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
  77. data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
  78. data/sig/generated/xlsxrb.rbs +321 -52
  79. metadata +3 -1
@@ -9,14 +9,19 @@ module Xlsxrb
9
9
  #
10
10
  # @api public
11
11
  class WorksheetBuilder
12
+ OMITTED = Object.new.freeze
13
+ private_constant :OMITTED
12
14
  # @param name [String] The worksheet name.
13
15
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel limits.
14
16
  # @param state [Symbol] Sheet visibility state (:visible, :hidden, or :very_hidden).
15
- #: (String name, ?strict_excel_mode: bool, ?state: Symbol) -> void
16
- def initialize(name, strict_excel_mode: true, state: :visible)
17
+ # @param escape_formulas [Boolean] Whether to treat strings starting with formula prefixes as plain text.
18
+ #: (String name, ?strict_excel_mode: bool, ?state: Symbol, ?escape_formulas: bool) -> void
19
+ def initialize(name, strict_excel_mode: true, state: :visible, escape_formulas: false)
17
20
  @name = name
18
21
  @strict_excel_mode = strict_excel_mode
19
22
  @state = state ? state.to_sym : :visible
23
+ @escape_formulas = escape_formulas ? true : false
24
+ @next_row_index = 0
20
25
  @rows = []
21
26
  @columns = []
22
27
  @charts = []
@@ -30,6 +35,7 @@ module Xlsxrb
30
35
  @conditional_formats = []
31
36
  @tables = []
32
37
  @comments = []
38
+ @threaded_comments = []
33
39
  @sparkline_groups = []
34
40
  @merge_cells_ranges = []
35
41
  @freeze_pane = nil
@@ -49,12 +55,38 @@ module Xlsxrb
49
55
  @col_breaks = []
50
56
  @protected_ranges = []
51
57
  @cell_watches = []
58
+ @ignored_errors = []
59
+ @phonetic_properties = nil
60
+ @sheet_calc_pr = nil
61
+ @background_image = nil
52
62
  @print_area = nil
53
63
  @print_titles = nil
64
+ @defined_names = []
65
+ @current_row_outline_level = nil
66
+ @current_row_collapsed = false
67
+ @current_row_hidden = false
68
+ @pending_row_attributes = {}
54
69
  end
55
70
 
71
+ #: String
56
72
  attr_reader :name
57
73
 
74
+ #: Array[Hash[Symbol, untyped]]
75
+ attr_reader :defined_names
76
+
77
+ # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
78
+ #: bool
79
+ attr_accessor :escape_formulas
80
+
81
+ # Returns whether formula escaping is enabled.
82
+ #
83
+ # @return [Boolean]
84
+ # @api public
85
+ #: () -> bool
86
+ def escape_formulas?
87
+ @escape_formulas ? true : false
88
+ end
89
+
58
90
  # Defines or configures a named cell style.
59
91
  #
60
92
  # @example Define a bold header style
@@ -76,57 +108,110 @@ module Xlsxrb
76
108
  style_builder
77
109
  end
78
110
 
111
+ # Creates an {Elements::Formula} object.
112
+ # @api public
113
+ #: (String expression, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), ?type: (Symbol | String)?, ?ref: String?, ?shared_index: Integer?) -> Elements::Formula
114
+ def formula(...)
115
+ Xlsxrb.formula(...)
116
+ end
117
+
118
+ # Creates an array or dynamic array {Elements::Formula} object.
119
+ # @api public
120
+ #: (String expression, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), **untyped attrs) -> Elements::Formula
121
+ def array_formula(...)
122
+ Xlsxrb.array_formula(...)
123
+ end
124
+
125
+ # Creates a shared formula {Elements::Formula} object.
126
+ # @api public
127
+ #: (?String? expression, ?shared_index: Integer?, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil)) -> Elements::Formula
128
+ def shared_formula(...)
129
+ Xlsxrb.shared_formula(...)
130
+ end
131
+
132
+ # Creates an {Elements::RichText} object.
133
+ # @api public
134
+ #: (*(Hash[Symbol, untyped] | Elements::RichTextRun | String | Array[untyped] | untyped) runs, ?text: String?, ?base_font: untyped, **untyped font_props) -> Elements::RichText
135
+ def rich_text(...)
136
+ Xlsxrb.rich_text(...)
137
+ end
138
+
139
+ # Creates or returns an {Elements::CellError} object.
140
+ # @api public
141
+ #: (String | Symbol | Elements::CellError code) -> Elements::CellError
142
+ def cell_error(...)
143
+ Xlsxrb.cell_error(...)
144
+ end
145
+
79
146
  # Appends a row of cells to the worksheet.
80
147
  #
81
148
  # @example Add a row with values and array styles
82
- # sheet.row(["ID", "Name", "Total"], styles: [:header, :header, :header])
149
+ # sheet.row(["ID", "Name", "Total"], cell_styles: [:header, :header, :header])
83
150
  #
84
151
  # @example Add a row with a hash of column keys
85
152
  # sheet.row({ "A" => "Invoice", "C" => 12345 })
86
153
  #
87
154
  # @param values [Array<Object>, Hash{String, Integer => Object}] The cell values.
88
- # @param styles [String, Symbol, Array<String | Symbol>, Hash, nil] Style names or inline styles to apply.
155
+ # @param cell_styles [String, Symbol, Array<String | Symbol>, Hash, nil] Style names or inline styles to apply to each cell.
156
+ # @param row_style [Integer, Symbol, String, Hash, nil] Row style format or index.
89
157
  # @param height [Float, Integer, nil] The row height in points (0 to 409).
90
158
  # @param hidden [Boolean] Whether the row is hidden.
91
159
  # @param custom_height [Boolean] Whether custom row height is enforced.
92
160
  # @param outline_level [Integer, nil] Grouping/outline hierarchy level.
93
161
  # @param collapsed [Boolean] Whether the row is collapsed.
94
- # @param style [Integer, Symbol, String, Hash, nil] Row style format or index.
162
+ # @param styles [String, Symbol, Array<String | Symbol>, Hash, nil] Deprecated. Use cell_styles: instead.
163
+ # @param style [Integer, Symbol, String, Hash, nil] Deprecated. Use row_style: instead.
95
164
  # @return [void]
96
165
  # @raise [ArgumentError] If limits are exceeded when strict_excel_mode is enabled.
97
166
  # @api public
98
- #: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
99
- def row(values, styles: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil, style: nil)
100
- row_index = @rows.size
167
+ #: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: (Integer | Symbol | String | Hash[Symbol, untyped])?, ?styles: untyped, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
168
+ def row(values, cell_styles: nil, row_style: nil, styles: nil, style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
169
+ if styles
170
+ warn "[DEPRECATION] WorksheetBuilder#row keyword :styles is deprecated; use :cell_styles instead.", uplevel: 1
171
+ cell_styles ||= styles
172
+ end
173
+ if style
174
+ warn "[DEPRECATION] WorksheetBuilder#row keyword :style is deprecated; use :row_style instead.", uplevel: 1
175
+ row_style ||= style
176
+ end
177
+
178
+ row_index = @next_row_index
101
179
  DslHelpers.validate_row_bounds!(row_index, height, strict_excel_mode: @strict_excel_mode)
180
+ @next_row_index += 1
181
+
182
+ pending = @pending_row_attributes.delete(row_index) || {}
183
+ outline_level ||= @current_row_outline_level || pending[:outline_level]
184
+ collapsed = @current_row_collapsed || pending[:collapsed] if !collapsed && (@current_row_collapsed || pending[:collapsed])
185
+ hidden = @current_row_hidden || pending[:hidden] if !hidden && (@current_row_hidden || pending[:hidden])
186
+ height ||= pending[:height]
102
187
 
103
188
  values = DslHelpers.normalize_row_values(values)
104
- styles = DslHelpers.normalize_row_styles(styles)
189
+ cell_styles = DslHelpers.normalize_row_styles(cell_styles)
105
190
 
106
191
  # Auto-detect Date / Time for built-in styles
107
192
  values.each_with_index do |val, idx|
108
- cell_style = styles.is_a?(Array) ? styles[idx] : styles
193
+ cell_style = cell_styles.is_a?(Array) ? cell_styles[idx] : cell_styles
109
194
 
110
195
  if val.is_a?(Date) && cell_style.nil?
111
- style("__xlsxrb_date", number_format: "yyyy-mm-dd") unless @styles.key?("__xlsxrb_date")
112
- styles = [] if styles.nil?
113
- styles = Array.new(values.size, styles) unless styles.is_a?(Array)
114
- styles[idx] = "__xlsxrb_date"
196
+ self.style("__xlsxrb_date", number_format: "yyyy-mm-dd") unless @styles.key?("__xlsxrb_date")
197
+ cell_styles = [] if cell_styles.nil?
198
+ cell_styles = Array.new(values.size, cell_styles) unless cell_styles.is_a?(Array)
199
+ cell_styles[idx] = "__xlsxrb_date"
115
200
  elsif val.is_a?(Time) && cell_style.nil?
116
- style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss") unless @styles.key?("__xlsxrb_time")
117
- styles = [] if styles.nil?
118
- styles = Array.new(values.size, styles) unless styles.is_a?(Array)
119
- styles[idx] = "__xlsxrb_time"
201
+ self.style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss") unless @styles.key?("__xlsxrb_time")
202
+ cell_styles = [] if cell_styles.nil?
203
+ cell_styles = Array.new(values.size, cell_styles) unless cell_styles.is_a?(Array)
204
+ cell_styles[idx] = "__xlsxrb_time"
120
205
  end
121
206
  end
122
207
 
123
208
  max_len = values.size
124
- max_len = [max_len, styles.size].max if styles.is_a?(Array)
209
+ max_len = [max_len, cell_styles.size].max if cell_styles.is_a?(Array)
125
210
  # See: https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
126
211
  raise ArgumentError, "Row contains #{max_len} columns, exceeding Excel limit of 16_384 columns" if @strict_excel_mode && max_len > 16_384
127
212
 
128
213
  cells = Array.new(max_len)
129
- style_lookup = styles.is_a?(Array)
214
+ style_lookup = cell_styles.is_a?(Array)
130
215
 
131
216
  col_index = 0
132
217
  while col_index < max_len
@@ -146,14 +231,14 @@ module Xlsxrb
146
231
  end
147
232
 
148
233
  style_name = if style_lookup
149
- col_index < styles.size ? styles[col_index] : nil
234
+ col_index < cell_styles.size ? cell_styles[col_index] : nil
150
235
  else
151
- styles
236
+ cell_styles
152
237
  end
153
238
 
154
239
  if style_name.is_a?(Hash)
155
240
  inline_name = "__inline_#{style_name.hash}"
156
- style(inline_name, **style_name) unless @styles.key?(inline_name)
241
+ self.style(inline_name, **style_name) unless @styles.key?(inline_name)
157
242
  style_name = inline_name
158
243
  end
159
244
  if val.nil? && style_name.nil?
@@ -161,8 +246,8 @@ module Xlsxrb
161
246
  next
162
247
  end
163
248
  sb = @styles[style_name]
164
- fmt_code = if sb&.num_fmt_id
165
- sb.num_fmt_id.is_a?(String) ? sb.num_fmt_id : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.num_fmt_id]
249
+ fmt_code = if sb&.number_format
250
+ sb.number_format.is_a?(String) ? sb.number_format : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.number_format]
166
251
  end
167
252
  # If value is a Formula object or Hash with :formula, store it as the cell's formula
168
253
  cells[col_index] = if val.is_a?(Elements::Formula)
@@ -171,16 +256,18 @@ module Xlsxrb
171
256
  column_index: col_index,
172
257
  value: val.cached_value,
173
258
  formula: val,
174
- style_index: style_name,
259
+ style: style_name,
175
260
  raw_value: val.cached_value&.to_s,
176
261
  format_code: fmt_code
177
262
  )
178
- elsif val.is_a?(Hash) && val.key?(:formula)
263
+ elsif val.is_a?(Hash) && (val.key?(:formula) || val.key?(:expression) || (val[:type]&.to_sym == :shared && (val.key?(:shared_index) || val.key?(:si))))
179
264
  cached_val = val.key?(:value) ? val[:value] : val[:cached_value]
265
+ f_expr = val[:formula] || val[:expression] || ""
266
+ f_type = val[:type] || (:shared if val.key?(:shared_index) || val.key?(:si))
180
267
  f_obj = Elements::Formula.new(
181
- expression: val[:formula],
268
+ expression: f_expr,
182
269
  cached_value: cached_val,
183
- type: val[:type],
270
+ type: f_type,
184
271
  ref: val[:ref],
185
272
  shared_index: val[:shared_index] || val[:si],
186
273
  calculate_always: val[:calculate_always]
@@ -190,7 +277,7 @@ module Xlsxrb
190
277
  column_index: col_index,
191
278
  value: cached_val,
192
279
  formula: f_obj,
193
- style_index: style_name,
280
+ style: style_name,
194
281
  raw_value: cached_val&.to_s,
195
282
  format_code: fmt_code
196
283
  )
@@ -199,7 +286,7 @@ module Xlsxrb
199
286
  row_index: row_index,
200
287
  column_index: col_index,
201
288
  value: val,
202
- style_index: style_name,
289
+ style: style_name,
203
290
  raw_value: val&.to_s,
204
291
  format_code: fmt_code
205
292
  )
@@ -208,7 +295,7 @@ module Xlsxrb
208
295
  end
209
296
 
210
297
  cells.compact!
211
- unmapped = style ? { style_index: style } : {}
298
+ unmapped = row_style ? { style_index: row_style } : {}
212
299
  @rows << Elements::Row.new(
213
300
  index: row_index,
214
301
  cells: cells,
@@ -217,9 +304,11 @@ module Xlsxrb
217
304
  custom_height: custom_height || !height.nil?,
218
305
  collapsed: collapsed,
219
306
  outline_level: outline_level,
307
+ style_index: row_style,
220
308
  unmapped_data: unmapped
221
309
  )
222
310
  end
311
+ # @deprecated Use {#row} instead. Will be removed in 0.2.0 (available via xlsxrb-adapters).
223
312
  alias add_row row
224
313
 
225
314
  # Appends a row to the worksheet and returns self for chaining.
@@ -236,6 +325,26 @@ module Xlsxrb
236
325
  self
237
326
  end
238
327
 
328
+ # Advances the row cursor by count without writing empty row elements.
329
+ #
330
+ # @example Skip one row
331
+ # sheet.skip_row
332
+ #
333
+ # @example Skip multiple rows
334
+ # sheet.skip_rows(3)
335
+ #
336
+ # @param count [Integer] Number of rows to skip (must be >= 1).
337
+ # @return [void]
338
+ # @api public
339
+ #: (?Integer count) -> void
340
+ def skip_rows(count = 1)
341
+ raise ArgumentError, "count must be positive: #{count.inspect}" if !count.is_a?(Integer) || count < 1
342
+
343
+ @next_row_index += count
344
+ end
345
+ # @deprecated Use {#skip_rows} instead. Will be removed in 0.2.0.
346
+ alias skip_row skip_rows
347
+
239
348
  # Sets column formatting and properties for one or multiple columns.
240
349
  #
241
350
  # @example Set width for column A
@@ -246,43 +355,221 @@ module Xlsxrb
246
355
  #
247
356
  # @param index [Integer, String, Range, Array] Column index (0-based), letter ("A"), or range ("A".."D").
248
357
  # @param width [Float, Integer, nil] Column width in character units (0 to 255).
358
+ # @param collapsed [Boolean] Whether the column is collapsed.
249
359
  # @param style [Integer, Symbol, String, nil] Column style format or index.
250
360
  # @return [void]
251
361
  # @raise [ArgumentError] If width exceeds 255 in strict mode.
252
362
  # @api public
253
- #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String)?) -> void
254
- def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, style: nil)
363
+ #: (Integer | String | Symbol | Range[Integer | String | Symbol] | Array[Integer | String | Symbol] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?, ?best_fit: bool) -> void
364
+ def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, collapsed: false, style: nil, best_fit: false)
255
365
  raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
256
366
 
257
367
  DslHelpers.normalize_column_indices(index).each do |idx|
258
- unmapped = style ? { style_index: style } : {}
259
- @columns << Elements::Column.new(
260
- index: idx,
261
- width: width,
262
- hidden: hidden,
263
- custom_width: custom_width || !width.nil?,
264
- outline_level: outline_level,
265
- style_index: style,
266
- unmapped_data: unmapped
267
- )
368
+ existing_idx = @columns.find_index { |c| c.index == idx }
369
+ if existing_idx
370
+ prev = @columns[existing_idx]
371
+ new_width = width.nil? ? prev.width : width
372
+ new_custom_width = (custom_width || !width.nil?) || prev.custom_width
373
+ new_hidden = hidden || prev.hidden
374
+ new_outline = outline_level.nil? ? prev.outline_level : outline_level
375
+ new_style = style.nil? ? prev.style_index : style
376
+ unmapped = prev.unmapped_data ? prev.unmapped_data.dup : {}
377
+ unmapped[:style_index] = new_style if new_style
378
+ unmapped[:collapsed] = true if collapsed || prev.unmapped_data&.[](:collapsed)
379
+ unmapped[:best_fit] = true if best_fit || prev.unmapped_data&.[](:best_fit)
380
+ @columns[existing_idx] = Elements::Column.new(
381
+ index: idx,
382
+ width: new_width,
383
+ hidden: new_hidden,
384
+ custom_width: new_custom_width,
385
+ outline_level: new_outline,
386
+ style_index: new_style,
387
+ unmapped_data: unmapped
388
+ )
389
+ else
390
+ unmapped = style ? { style_index: style } : {}
391
+ unmapped[:collapsed] = true if collapsed
392
+ unmapped[:best_fit] = true if best_fit
393
+ @columns << Elements::Column.new(
394
+ index: idx,
395
+ width: width,
396
+ hidden: hidden,
397
+ custom_width: custom_width || !width.nil?,
398
+ outline_level: outline_level,
399
+ style_index: style,
400
+ unmapped_data: unmapped
401
+ )
402
+ end
403
+ end
404
+ @columns.sort_by!(&:index)
405
+ nil
406
+ end
407
+
408
+ # Returns column configurations defined for this worksheet.
409
+ #
410
+ # @return [Array<Elements::Column>]
411
+ # @api public
412
+ #: () -> Array[Elements::Column]
413
+ def columns
414
+ @columns.map { |c| c.is_a?(Elements::Column) ? c : Elements::Column.new(**c) }
415
+ end
416
+
417
+ # Groups multiple columns together with outline hierarchy.
418
+ #
419
+ # @example Group columns B through D
420
+ # sheet.group_columns("B".."D", level: 1)
421
+ #
422
+ # @example Group columns 1 through 3 and collapse
423
+ # sheet.group_columns(1..3, level: 1, collapsed: true)
424
+ #
425
+ # @param index [Integer, String, Range, Array] Column index (0-based), letter, range, or array.
426
+ # @param level [Integer] Grouping outline level (1 to 7).
427
+ # @param collapsed [Boolean] Whether the group is collapsed.
428
+ # @param hidden [Boolean] Whether the columns are hidden.
429
+ # @param width [Float, Integer, nil] Optional column width.
430
+ # @param style [Integer, Symbol, String, nil] Optional column style.
431
+ # @return [void]
432
+ # @api public
433
+ #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?level: Integer, ?collapsed: bool, ?hidden: bool, ?width: Float | Integer | nil, ?style: untyped) -> void
434
+ def group_columns(index, level: 1, collapsed: false, hidden: false, width: nil, style: nil)
435
+ column(index, outline_level: level, collapsed: collapsed, hidden: hidden, width: width, style: style)
436
+ end
437
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
438
+ alias group_column group_columns
439
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
440
+ alias group_cols group_columns
441
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
442
+ alias group_col group_columns
443
+
444
+ # Groups multiple rows with outline hierarchy, either by range or with a block.
445
+ #
446
+ # @example Group rows with a block
447
+ # sheet.group_rows(level: 1, collapsed: true) do
448
+ # sheet.row(["Subtotal Item 1"])
449
+ # sheet.row(["Subtotal Item 2"])
450
+ # end
451
+ #
452
+ # @example Group rows by 0-based range
453
+ # sheet.group_rows(1..3, level: 1, collapsed: true)
454
+ #
455
+ # @param rows [Range, Array, Integer, nil] 0-based row index or range.
456
+ # @param level [Integer] Grouping outline level (1 to 7).
457
+ # @param collapsed [Boolean] Whether the group is collapsed.
458
+ # @param hidden [Boolean] Whether the rows are hidden.
459
+ # @yield Optional block executed with active group outline settings.
460
+ # @return [void]
461
+ # @api public
462
+ #: (?untyped rows, ?level: Integer, ?collapsed: bool, ?hidden: bool) ?{ (self) -> void } -> void
463
+ def group_rows(rows = nil, level: 1, collapsed: false, hidden: false)
464
+ if block_given?
465
+ prev_level = @current_row_outline_level
466
+ prev_collapsed = @current_row_collapsed
467
+ prev_hidden = @current_row_hidden
468
+ @current_row_outline_level = level
469
+ @current_row_collapsed = collapsed
470
+ @current_row_hidden = hidden
471
+ begin
472
+ yield(self)
473
+ ensure
474
+ @current_row_outline_level = prev_level
475
+ @current_row_collapsed = prev_collapsed
476
+ @current_row_hidden = prev_hidden
477
+ end
478
+ elsif rows
479
+ row_indices = case rows
480
+ when Range then rows.to_a
481
+ when Array then rows
482
+ else [rows.to_i]
483
+ end
484
+ row_indices.each do |idx|
485
+ existing_row = @rows.find { |r| r.index == idx }
486
+ if existing_row
487
+ existing_idx = @rows.index(existing_row)
488
+ @rows[existing_idx] = Elements::Row.new(
489
+ index: existing_row.index,
490
+ cells: existing_row.cells,
491
+ height: existing_row.height,
492
+ hidden: hidden || existing_row.hidden,
493
+ custom_height: existing_row.custom_height,
494
+ collapsed: collapsed || existing_row.collapsed,
495
+ outline_level: level,
496
+ style_index: existing_row.style_index,
497
+ unmapped_data: existing_row.unmapped_data
498
+ )
499
+ else
500
+ @pending_row_attributes[idx] = { outline_level: level, collapsed: collapsed, hidden: hidden }
501
+ end
502
+ end
268
503
  end
269
504
  end
505
+ # @deprecated Use {#group_rows} instead. Will be removed in 0.2.0.
506
+ alias group_row group_rows
507
+
508
+ # Configures worksheet-level outline and grouping view properties.
509
+ #
510
+ # @example Show summary row below detail rows
511
+ # sheet.outline_properties(summary_below: true, summary_right: true)
512
+ #
513
+ # @param summary_below [Boolean, nil] Flag indicating if summary rows appear below detail rows.
514
+ # @param summary_right [Boolean, nil] Flag indicating if summary columns appear to the right of detail columns.
515
+ # @param show_outline_symbols [Boolean, nil] Flag indicating whether outline symbols are visible.
516
+ # @param show_symbols [Boolean, nil] Deprecated alias for show_outline_symbols.
517
+ # @param apply_styles [Boolean, nil] Flag indicating whether automatic styles apply to outlines.
518
+ # @param opts [Hash] Additional options.
519
+ # @return [Hash<Symbol, untyped>, void]
520
+ # @api public
521
+ #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> (Hash[Symbol, untyped] | void)
522
+ def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, show_symbols: nil, apply_styles: nil, **opts)
523
+ return @sheet_properties.slice(:summary_below, :summary_right, :show_outline_symbols, :apply_styles) if summary_below.nil? && summary_right.nil? && show_outline_symbols.nil? && show_symbols.nil? && apply_styles.nil? && opts.empty?
524
+
525
+ warn "[Xlsxrb DEPRECATION] outline_properties keyword show_symbols: is deprecated; use show_outline_symbols: instead.", uplevel: 1 unless show_symbols.nil?
526
+ props = (@sheet_properties[:outline_properties] || {}).dup
527
+ props[:summary_below] = summary_below unless summary_below.nil?
528
+ props[:summary_right] = summary_right unless summary_right.nil?
529
+ symbols = show_outline_symbols.nil? ? show_symbols : show_outline_symbols
530
+ props[:show_outline_symbols] = symbols unless symbols.nil?
531
+ props[:apply_styles] = apply_styles unless apply_styles.nil?
532
+ props.merge!(opts)
533
+ @sheet_properties[:outline_properties] = props
534
+ @sheet_properties[:summary_below] = props[:summary_below] unless props[:summary_below].nil?
535
+ @sheet_properties[:summary_right] = props[:summary_right] unless props[:summary_right].nil?
536
+ nil
537
+ end
538
+ # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
539
+ alias outline_pr outline_properties
540
+
541
+ # Sets worksheet outline and grouping view properties.
542
+ #
543
+ # @param opts [Hash] Outline properties.
544
+ # @return [void]
545
+ # @api public
546
+ #: (Hash[Symbol, untyped] opts) -> void
547
+ def outline_properties=(opts)
548
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
549
+ outline_properties(**h)
550
+ nil
551
+ end
552
+ alias outline_pr= outline_properties=
270
553
 
271
554
  # Adds a chart to the worksheet.
272
555
  #
556
+ # @param type [Symbol, String, nil] Optional chart type (e.g. :bar, :line).
273
557
  # @param options [Hash] Chart configuration options.
274
558
  # @yield [builder]
275
559
  # @yieldparam builder [Xlsxrb::ChartBuilder]
276
560
  # @return [void]
277
561
  # @api public
278
- #: (**untyped options) ?{ (ChartBuilder) -> void } -> void
279
- def chart(**options)
562
+ #: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
563
+ def chart(type = nil, **options)
564
+ options = options.merge(type: type) if type
280
565
  if block_given?
281
566
  builder = ChartBuilder.new
567
+ builder.type(type) if type
282
568
  yield builder
283
569
  options = builder.options.merge(options)
284
570
  end
285
571
  @charts << options
572
+ nil
286
573
  end
287
574
 
288
575
  # Adds a hyperlink to a cell.
@@ -315,23 +602,37 @@ module Xlsxrb
315
602
 
316
603
  # Sets an auto-filter range on the sheet.
317
604
  #
318
- # @param range [String] The cell range (e.g. "A1:E100").
319
- # @return [String]
605
+ # @param range [String, nil] The cell range (e.g. "A1:E100").
606
+ # @return [void]
320
607
  # @api public
321
- #: (String range) -> String
608
+ #: (String? range) -> void
322
609
  def auto_filter(range)
323
610
  @auto_filter = range
611
+ nil
612
+ end
613
+
614
+ # Sets the auto-filter range for the worksheet.
615
+ #
616
+ # @param range [String, nil] Cell range (e.g. "A1:E100").
617
+ # @return [String, nil]
618
+ # @api public
619
+ #: (String? range) -> String?
620
+ def auto_filter=(range)
621
+ auto_filter(range)
622
+ range
324
623
  end
325
624
 
326
625
  # Configures filtering rules on a specific column of an auto-filter.
327
626
  #
328
- # @param col_id [Integer] 0-based column index relative to filter range.
627
+ # @param col_id [Integer, String, Symbol] 0-based column index relative to filter range or column letter ("A", :B).
329
628
  # @param filter [Hash] Filter criteria (e.g. values, custom filters).
330
- # @return [Hash]
629
+ # @return [void]
331
630
  # @api public
332
- #: (Integer col_id, Hash[untyped, untyped] filter) -> Hash[untyped, untyped]
631
+ #: (Integer | String | Symbol col_id, untyped filter) -> void
333
632
  def filter_column(col_id, filter)
633
+ col_id = Elements::Cell._column_index(col_id) if col_id.is_a?(String) || col_id.is_a?(Symbol)
334
634
  @filter_columns[col_id] = filter
635
+ nil
335
636
  end
336
637
 
337
638
  # Configures column sort state for the sheet.
@@ -339,42 +640,66 @@ module Xlsxrb
339
640
  # @param ref [String] The sorted range.
340
641
  # @param sort_conditions [Array<Hash>] List of sort condition definitions.
341
642
  # @param opts [Hash] Additional sort state options.
342
- # @return [Hash]
643
+ # @return [Elements::SortState, Hash<Symbol, untyped>, nil, void]
343
644
  # @api public
344
- #: (String ref, Array[Hash[untyped, untyped]] sort_conditions, **untyped opts) -> Hash[untyped, untyped]
345
- def sort_state(ref, sort_conditions, **opts)
645
+ #: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, **untyped opts) -> (untyped | void)
646
+ def sort_state(ref = nil, sort_conditions = nil, **opts)
647
+ if ref.nil? && sort_conditions.nil? && opts.empty?
648
+ return nil unless @sort_state
649
+ return Elements::SortState.new(**@sort_state) if defined?(Elements::SortState)
650
+
651
+ return @sort_state
652
+ end
653
+
346
654
  @sort_state = { ref: ref, sort_conditions: sort_conditions }.merge(opts)
655
+ nil
656
+ end
657
+
658
+ # Sets column sort state for the sheet.
659
+ #
660
+ # @param opts [Elements::SortState, Hash, nil] Sort state options.
661
+ # @return [void]
662
+ # @api public
663
+ #: (untyped opts) -> void
664
+ def sort_state=(opts)
665
+ @sort_state = opts&.respond_to?(:to_h) ? opts.to_h : opts
666
+ nil
347
667
  end
348
668
 
349
- # Adds a data validation rule to a cell or range.
669
+ # Adds a data validation rule to a cell, range, or coordinates.
350
670
  #
351
671
  # @param sqref [String, nil] Target cell or range reference (e.g. "B2:B100").
352
- # @param opts [Hash] Validation configuration (e.g. type: :list, formula1: '"Option1,Option2"').
672
+ # @param opts [Hash] Validation configuration (e.g. type: :list, formula1: '"Option1,Option2"', or coordinate options `columns:`, `rows:`, `except_rows:`, `list:`, `in:`).
353
673
  # @yield [data_validation_builder] Optional configuration block.
354
674
  # @return [void]
355
675
  # @api public
356
676
  #: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
357
- def validate_data(sqref = nil, **opts)
358
- if block_given?
359
- builder = DataValidationBuilder.new(sqref, **opts)
360
- yield builder
361
- opts = builder.to_h
362
- sqref = opts.delete(:sqref) || sqref
363
- end
364
- raise ArgumentError, "data validation sqref must be provided" unless sqref
677
+ def data_validation(sqref = nil, **opts, &)
678
+ normalized_list = DslHelpers.normalize_data_validation(sqref, **opts, &)
679
+ @data_validations.concat(normalized_list)
680
+ end
365
681
 
366
- @data_validations << opts.merge(sqref: sqref)
682
+ # @deprecated Use {#data_validation} instead.
683
+ #: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
684
+ def validate_data(...)
685
+ warn "[DEPRECATION] `validate_data` is deprecated; use `data_validation` instead.", uplevel: 1
686
+ data_validation(...)
367
687
  end
368
688
 
369
689
  # Adds a conditional formatting rule to a cell range.
690
+ # Supports block configuration via {ConditionalFormatBuilder} and coordinate targeting (:columns, :rows).
370
691
  #
371
- # @param sqref [String] Target cell range reference (e.g. "C2:C50").
692
+ # @param sqref [String, nil] Target cell range reference (e.g. "C2:C50").
372
693
  # @param opts [Hash] Rule options (e.g. type: :cellIs, operator: :greaterThan, formula: "100").
694
+ # @option opts [Hash] :dxf Hierarchical differential format specification (e.g. `dxf: { font: { bold: false }, fill: { pattern: "none" } }`).
695
+ # @option opts [Integer] :format_id Pre-registered differential format index (dxfId).
696
+ # @yield [conditional_format_builder] Optional block for configuration.
373
697
  # @return [void]
374
698
  # @api public
375
- #: (String sqref, **untyped opts) -> void
376
- def conditional_format(sqref, **opts)
377
- @conditional_formats << opts.merge(sqref: sqref)
699
+ #: (?String? sqref, **untyped opts) ?{ (ConditionalFormatBuilder) -> void } -> void
700
+ def conditional_format(sqref = nil, **opts, &)
701
+ normalized_list = DslHelpers.normalize_conditional_format(sqref, **opts, &)
702
+ @conditional_formats.concat(normalized_list)
378
703
  end
379
704
 
380
705
  # Adds an Excel Table (ListObject) to the sheet.
@@ -417,17 +742,27 @@ module Xlsxrb
417
742
  # @param name [String, nil] Pivot table name.
418
743
  # @param field_names [Array<String>, nil] Custom field display names.
419
744
  # @param items [Array, nil] Item configuration.
745
+ # @param column_fields [Array<String, Integer>] Field names or indices for columns.
746
+ # @param col_fields [Array<String, Integer>] Deprecated alias for column_fields.
747
+ # @param ref [String] Target cell for pivot table top-left corner (e.g. "E1").
748
+ # @param dest_ref [String] Deprecated alias for ref.
420
749
  # @return [void]
421
750
  # @api public
422
- #: (String source_ref, row_fields: Array[String | Integer], data_fields: Array[String | Hash[Symbol, untyped]], ?col_fields: Array[String | Integer], ?dest_ref: String, ?name: String?, ?field_names: Array[String]?, ?items: Array[untyped]?, **untyped opts) -> void
423
- def pivot_table(source_ref, row_fields:, data_fields:, col_fields: [], dest_ref: "E1", name: nil, field_names: nil, items: nil)
751
+ #: (String source_ref, row_fields: Array[String | Integer], data_fields: Array[String | Hash[Symbol, untyped]], ?column_fields: Array[String | Integer]?, ?col_fields: Array[String | Integer]?, ?ref: String?, ?dest_ref: String?, ?name: String?, ?field_names: Array[String]?, ?items: Array[untyped]?, **untyped opts) -> void
752
+ def pivot_table(source_ref, row_fields:, data_fields:, column_fields: nil, col_fields: nil, ref: nil, dest_ref: nil, name: nil, field_names: nil, items: nil, **opts)
753
+ warn "[DEPRECATION] `col_fields:` is deprecated; use `column_fields:` instead.", uplevel: 1 if col_fields && column_fields.nil?
754
+ warn "[DEPRECATION] `dest_ref:` is deprecated; use `ref:` instead.", uplevel: 1 if dest_ref && ref.nil?
755
+ c_fields = column_fields || col_fields || []
756
+ target_ref = ref || dest_ref || "E1"
424
757
  @pivot_tables ||= []
425
- @pivot_tables << {
758
+ entry = {
426
759
  source_ref: source_ref, row_fields: row_fields,
427
- data_fields: data_fields, col_fields: col_fields,
428
- dest_ref: dest_ref, name: name,
760
+ data_fields: data_fields, column_fields: c_fields,
761
+ col_fields: c_fields, ref: target_ref,
762
+ dest_ref: target_ref, name: name,
429
763
  field_names: field_names, items: items
430
- }
764
+ }.merge(opts)
765
+ @pivot_tables << entry
431
766
  end
432
767
 
433
768
  # Adds a cell comment / note.
@@ -439,9 +774,44 @@ module Xlsxrb
439
774
  # @api public
440
775
  #: (String | Integer cell, String text, ?author: ::String) -> void
441
776
  def comment(cell, text, author: "Author")
442
- @comments << { cell: cell, text: text, author: author }
777
+ ref_str = cell.to_s
778
+ @comments << { ref: ref_str, text: text, author: author }
779
+ nil
443
780
  end
444
781
 
782
+ # Adds a threaded comment to a cell.
783
+ #
784
+ # @param cell [String, Integer] Cell reference (e.g. "B2").
785
+ # @param text [String] The comment text.
786
+ # @param author [String] Author display name.
787
+ # @param timestamp [String, Time, nil] Optional ISO 8601 timestamp.
788
+ # @param id [String, nil] Optional GUID for this comment.
789
+ # @param parent_id [String, nil] Optional parent comment GUID for replies.
790
+ # @param done [Boolean, nil] Optional resolved flag.
791
+ # @param user_id [String, nil] Optional user ID.
792
+ # @param provider_id [String, nil] Optional provider ID.
793
+ # @return [void]
794
+ # @api public
795
+ #: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
796
+ def threaded_comment(cell, text, author: "Author", timestamp: nil, id: nil, parent_id: nil, done: false, user_id: nil, provider_id: nil)
797
+ ref_str = cell.to_s
798
+ entry = {
799
+ ref: ref_str,
800
+ text: text,
801
+ author: author,
802
+ timestamp: timestamp,
803
+ id: id,
804
+ parent_id: parent_id,
805
+ done: done ? true : false,
806
+ user_id: user_id,
807
+ provider_id: provider_id
808
+ }.compact
809
+ @threaded_comments << entry
810
+ nil
811
+ end
812
+ # @deprecated Use {#threaded_comment} instead. Will be removed in 0.2.0.
813
+ alias add_threaded_comment threaded_comment
814
+
445
815
  # Adds a sparkline group to the sheet.
446
816
  #
447
817
  # @param sparklines [Array<Hash>] List of { data_ref:, location_ref: } items.
@@ -468,6 +838,7 @@ module Xlsxrb
468
838
  # @example Add a win/loss sparkline
469
839
  # sheet.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
470
840
  #
841
+ # @deprecated Use {#sparkline_group} instead. Will be removed in 0.2.0.
471
842
  # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
472
843
  # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
473
844
  # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
@@ -476,6 +847,7 @@ module Xlsxrb
476
847
  # @api public
477
848
  #: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
478
849
  def add_sparkline(location: nil, range: nil, type: nil, **opts)
850
+ warn "[DEPRECATION] #add_sparkline is deprecated; use #sparkline_group instead.", uplevel: 1
479
851
  loc = location || opts.delete(:location_ref)
480
852
  rng = range || opts.delete(:data_ref) || opts.delete(:data)
481
853
  raise ArgumentError, "Missing required location: parameter for sparkline" unless loc
@@ -494,9 +866,7 @@ module Xlsxrb
494
866
  # @example Merge with string range
495
867
  # sheet.merge("A1:C1")
496
868
  #
497
- # @example Merge with row and column bounds
498
- # sheet.merge(row_start: 0, row_end: 2, col_start: "A", col_end: "C")
499
- #
869
+ # @deprecated Passing coordinate keyword arguments (row:, col_start:, col_end:, row_start:, row_end:) is deprecated and will be removed in 0.2.0. Use a range string (e.g. merge("A1:C1")) instead.
500
870
  # @param range [String, Hash, nil] Cell range (e.g. "A1:B2") or hash of coordinates.
501
871
  # @param row [Integer, nil] Single row index.
502
872
  # @param col_start [Integer, String, nil] Starting column.
@@ -516,44 +886,150 @@ module Xlsxrb
516
886
  @merge_cells_ranges << canonical unless @merge_cells_ranges.include?(canonical)
517
887
  end
518
888
 
519
- # Freezes window panes at the specified row and column.
889
+ # Freezes window panes at the specified row and column, or queries freeze pane settings.
890
+ #
891
+ # @param row [Integer, nil] Number of rows to freeze from top (0-based split position).
892
+ # @param column [Integer, String, nil] Number of columns to freeze from left (0-based or letter).
893
+ # @param col [Integer, String, nil] Deprecated alias for column.
894
+ # @return [Elements::FreezePane, Hash<Symbol, untyped>, nil, void]
895
+ # @api public
896
+ #: (?row: Integer | nil, ?column: (Integer | String)?, ?col: (Integer | String)?) -> (untyped | void)
897
+ def freeze_pane(row: nil, column: nil, col: nil)
898
+ if row.nil? && column.nil? && col.nil?
899
+ return nil unless @freeze_pane
900
+ return Elements::FreezePane.new(**@freeze_pane) if defined?(Elements::FreezePane)
901
+
902
+ return @freeze_pane
903
+ end
904
+
905
+ warn "[DEPRECATION] `col:` is deprecated; use `column:` instead.", uplevel: 1 if col && column.nil?
906
+ c = Elements::Cell._column_index(column || col || 0)
907
+ @freeze_pane = { row: row || 0, col: c, column: c }
908
+ nil
909
+ end
910
+
911
+ # Sets or clears freeze pane configuration.
520
912
  #
521
- # @param row [Integer] Number of rows to freeze from top (0-based split position).
522
- # @param col [Integer, String] Number of columns to freeze from left (0-based or letter).
913
+ # @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
523
914
  # @return [void]
524
915
  # @api public
525
- #: (?row: Integer, ?col: (Integer | String)) -> void
526
- def freeze_pane(row: 0, col: 0)
527
- col = Elements::Cell.column_index(col)
528
- @freeze_pane = { row: row, col: col }
916
+ #: (untyped opts) -> void
917
+ def freeze_pane=(opts)
918
+ if opts.nil?
919
+ @freeze_pane = nil
920
+ else
921
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
922
+ c = h[:column] || h[:col]
923
+ c = Elements::Cell._column_index(c) if c
924
+ @freeze_pane = { row: h[:row] || 0, col: c || 0, column: c || 0 }
925
+ end
926
+ nil
529
927
  end
530
928
 
531
- # Splits window panes without freezing.
929
+ # Splits window panes without freezing or queries split pane settings.
532
930
  #
533
- # @param x_split [Integer] Horizontal split offset in points.
534
- # @param y_split [Integer] Vertical split offset in points.
931
+ # @param x_split [Integer, nil] Horizontal split offset in points.
932
+ # @param y_split [Integer, nil] Vertical split offset in points.
535
933
  # @param top_left_cell [String, nil] Top-left cell reference in bottom-right pane.
934
+ # @param active_pane [String, Symbol, nil] Active pane identifier.
935
+ # @param state [String, Symbol, nil] Split state.
936
+ # @return [Elements::SplitPane, Hash<Symbol, untyped>, nil, void]
937
+ # @api public
938
+ #: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?, ?state: (String | Symbol)?) -> (untyped | void)
939
+ def split_pane(x_split: nil, y_split: nil, top_left_cell: nil, active_pane: nil, state: nil)
940
+ if x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil? && state.nil?
941
+ return nil unless @split_pane
942
+ return Elements::SplitPane.new(**@split_pane) if defined?(Elements::SplitPane)
943
+
944
+ return @split_pane
945
+ end
946
+
947
+ entry = { x_split: x_split || 0, y_split: y_split || 0, top_left_cell: top_left_cell }
948
+ entry[:active_pane] = active_pane.to_s if active_pane
949
+ entry[:state] = state.to_s if state
950
+ @split_pane = entry
951
+ nil
952
+ end
953
+
954
+ # Sets or clears split pane configuration.
955
+ #
956
+ # @param opts [Elements::SplitPane, Hash, nil] Split pane options.
536
957
  # @return [void]
537
958
  # @api public
538
- #: (?x_split: ::Integer, ?y_split: ::Integer, ?top_left_cell: String?) -> void
539
- def split_pane(x_split: 0, y_split: 0, top_left_cell: nil)
540
- @split_pane = { x_split: x_split, y_split: y_split, top_left_cell: top_left_cell }
959
+ #: (untyped opts) -> void
960
+ def split_pane=(opts)
961
+ if opts.nil?
962
+ @split_pane = nil
963
+ else
964
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
965
+ entry = { x_split: h[:x_split] || 0, y_split: h[:y_split] || 0, top_left_cell: h[:top_left_cell] }
966
+ entry[:active_pane] = h[:active_pane].to_s if h[:active_pane]
967
+ entry[:state] = h[:state].to_s if h[:state]
968
+ @split_pane = entry
969
+ end
970
+ nil
541
971
  end
542
972
 
543
- # Sets the active cell and selection area for the worksheet.
973
+ # Sets or queries the active cell and selection area (<selection>).
544
974
  #
545
- # @param active_cell [String] Active cell reference (e.g. "A1").
975
+ # @param active_cell [String, nil] Active cell reference (e.g. "A1") or range (e.g. "A1:D10").
546
976
  # @param sqref [String, nil] Selected range reference (e.g. "A1:D10").
547
977
  # @param pane [String, Symbol, nil] Target pane (:topLeft, :topRight, :bottomLeft, :bottomRight).
978
+ # @return [Elements::Selection, Array<Elements::Selection>, Hash<Symbol, untyped>, nil, void]
979
+ # @api public
980
+ #: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> (untyped | void)
981
+ def selection(active_cell = nil, sqref: nil, pane: nil)
982
+ if active_cell.nil? && sqref.nil? && pane.nil?
983
+ return nil if @selection.nil?
984
+
985
+ if defined?(Elements::Selection)
986
+ return @selection.map { |s| Elements::Selection.new(**s) } if @selection.is_a?(Array)
987
+
988
+ return Elements::Selection.new(**@selection)
989
+ end
990
+
991
+ return @selection
992
+ end
993
+
994
+ if sqref.nil? && active_cell.is_a?(String) && active_cell.include?(":")
995
+ sqref = active_cell
996
+ active_cell = sqref.split(":").first
997
+ else
998
+ sqref ||= active_cell
999
+ end
1000
+ @selection = { active_cell: active_cell, sqref: sqref }
1001
+ @selection[:pane] = pane if pane
1002
+ nil
1003
+ end
1004
+
1005
+ # Sets or clears the selection configuration.
1006
+ #
1007
+ # @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
548
1008
  # @return [void]
549
1009
  # @api public
1010
+ #: (untyped opts) -> void
1011
+ def selection=(opts)
1012
+ @selection = if opts.nil?
1013
+ nil
1014
+ elsif opts.is_a?(Array)
1015
+ opts.map { |o| o.respond_to?(:to_h) ? o.to_h : o }
1016
+ else
1017
+ opts.respond_to?(:to_h) ? opts.to_h : opts
1018
+ end
1019
+ nil
1020
+ end
1021
+
1022
+ # @deprecated Use {#selection} instead.
550
1023
  #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
551
- def select_cell(active_cell, sqref: nil, pane: nil)
552
- @selection = { active_cell: active_cell, sqref: sqref || active_cell }
553
- @selection[:pane] = pane if pane
1024
+ def select_cell(...)
1025
+ warn "[DEPRECATION] `select_cell` is deprecated; use `selection` instead.", uplevel: 1
1026
+ selection(...)
554
1027
  end
555
1028
 
556
- # Sets page margins in inches for printing.
1029
+ # Configures or queries page margins in inches for printing (<pageMargins>).
1030
+ #
1031
+ # When called with no arguments, returns the page margins value object or hash.
1032
+ # When called with arguments, configures page margins and returns nil.
557
1033
  #
558
1034
  # @param left [Float, nil] Left margin.
559
1035
  # @param right [Float, nil] Right margin.
@@ -561,44 +1037,215 @@ module Xlsxrb
561
1037
  # @param bottom [Float, nil] Bottom margin.
562
1038
  # @param header [Float, nil] Header margin.
563
1039
  # @param footer [Float, nil] Footer margin.
564
- # @return [void]
1040
+ # @return [Elements::PageMargins, Hash<Symbol, untyped>, nil, void]
565
1041
  # @api public
566
- #: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> void
1042
+ #: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> (untyped | void)
567
1043
  def page_margins(left: nil, right: nil, top: nil, bottom: nil, header: nil, footer: nil)
1044
+ if left.nil? && right.nil? && top.nil? && bottom.nil? && header.nil? && footer.nil?
1045
+ return nil unless @page_margins
1046
+ return Elements::PageMargins.new(**@page_margins) if defined?(Elements::PageMargins)
1047
+
1048
+ return @page_margins
1049
+ end
1050
+
568
1051
  @page_margins = DslHelpers.normalize_page_margins(
569
1052
  left: left, right: right, top: top, bottom: bottom, header: header, footer: footer
570
1053
  )
1054
+ nil
571
1055
  end
572
1056
 
573
- # Sets page setup configuration (orientation, paper size, fit to page, scaling).
1057
+ # Sets or clears page margins configuration.
574
1058
  #
575
- # @param opts [Hash] Page setup options (e.g. orientation: :landscape, paper_size: 9).
1059
+ # @param opts [Hash, Elements::PageMargins, nil]
576
1060
  # @return [void]
577
1061
  # @api public
578
- #: (**untyped opts) -> void
1062
+ #: (untyped opts) -> void
1063
+ def page_margins=(opts)
1064
+ if opts.nil?
1065
+ @page_margins = nil
1066
+ else
1067
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
1068
+ @page_margins = DslHelpers.normalize_page_margins(**h)
1069
+ end
1070
+ nil
1071
+ end
1072
+
1073
+ # Configures or queries page setup configuration (<pageSetup>).
1074
+ #
1075
+ # When called with no arguments, returns the page setup value object or hash.
1076
+ # When called with keyword arguments, updates page setup and returns nil.
1077
+ #
1078
+ # @param opts [Hash] Page setup options (e.g. orientation: :landscape, paper_size: 9).
1079
+ # @return [Elements::PageSetup, Hash<Symbol, untyped>, void]
1080
+ # @api public
1081
+ #: (**untyped opts) -> (untyped | void)
579
1082
  def page_setup(**opts)
1083
+ if opts.empty?
1084
+ return defined?(Elements::PageSetup) ? Elements::PageSetup.new(**@page_setup) : @page_setup
1085
+ end
1086
+
580
1087
  @page_setup.merge!(opts)
1088
+ @sheet_properties[:fit_to_page] = true if (opts.key?(:fit_to_width) || opts.key?(:fit_to_height)) && !@sheet_properties.key?(:fit_to_page)
1089
+ nil
581
1090
  end
582
1091
 
583
- # Configures headers and footers for printing.
1092
+ # Sets page setup configuration.
584
1093
  #
585
- # @param opts [Hash] Header and footer options (e.g. odd_header: "&CHeader Text").
1094
+ # @param opts [Hash, Elements::PageSetup]
586
1095
  # @return [void]
587
1096
  # @api public
588
- #: (**untyped opts) -> void
1097
+ #: (untyped opts) -> void
1098
+ def page_setup=(opts)
1099
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
1100
+ @page_setup = h.transform_keys(&:to_sym)
1101
+ nil
1102
+ end
1103
+
1104
+ # Configures whether page setup fits content to page width/height.
1105
+ # When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
1106
+ #
1107
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fit_to_page=} or {#page_setup} with :fit_to_width/:fit_to_height instead.
1108
+ # @param enabled [Boolean, nil] Whether to fit to page.
1109
+ # @param width [Integer, nil] Pages wide to fit to.
1110
+ # @param height [Integer, nil] Pages tall to fit to.
1111
+ # @return [Boolean, void]
1112
+ # @api public
1113
+ #: (?bool? enabled, ?width: Integer?, ?height: Integer?) -> (bool | void)
1114
+ def fit_to_page(enabled = OMITTED, width: nil, height: nil)
1115
+ if enabled.equal?(OMITTED) && width.nil? && height.nil?
1116
+ return @sheet_properties[:fit_to_page] ? true : false
1117
+ end
1118
+
1119
+ @sheet_properties[:fit_to_page] = if enabled.equal?(OMITTED)
1120
+ true
1121
+ else
1122
+ enabled ? true : false
1123
+ end
1124
+ page_setup(fit_to_width: width) if width
1125
+ page_setup(fit_to_height: height) if height
1126
+ end
1127
+
1128
+ # @deprecated Use {#fit_to_page} instead. Will be removed in 0.2.0.
1129
+ # @return [Boolean]
1130
+ # @api public
1131
+ #: () -> bool
1132
+ def fit_to_page?
1133
+ warn "[Xlsxrb DEPRECATION] fit_to_page? is deprecated; use fit_to_page instead.", uplevel: 1
1134
+ fit_to_page
1135
+ end
1136
+
1137
+ # Sets whether page setup fits content to page width/height.
1138
+ #
1139
+ # @param enabled [Boolean, nil] Whether to fit to page.
1140
+ # @return [Boolean]
1141
+ # @api public
1142
+ #: (bool? enabled) -> bool?
1143
+ def fit_to_page=(enabled)
1144
+ @sheet_properties[:fit_to_page] = enabled ? true : false
1145
+ end
1146
+
1147
+ # Configures or queries headers and footers for printing (<headerFooter>).
1148
+ #
1149
+ # When called with no arguments, returns the header/footer value object or hash.
1150
+ # When called with keyword arguments, updates headers and footers and returns nil.
1151
+ #
1152
+ # @param opts [Hash] Header and footer options (e.g. odd_header: "&CHeader Text").
1153
+ # @return [Elements::HeaderFooter, Hash<Symbol, untyped>, void]
1154
+ # @api public
1155
+ #: (**untyped opts) -> (untyped | void)
589
1156
  def header_footer(**opts)
1157
+ if opts.empty?
1158
+ return defined?(Elements::HeaderFooter) ? Elements::HeaderFooter.new(**@header_footer) : @header_footer
1159
+ end
1160
+
590
1161
  @header_footer.merge!(opts)
1162
+ nil
1163
+ end
1164
+
1165
+ # Sets header and footer configuration.
1166
+ #
1167
+ # @param opts [Hash, Elements::HeaderFooter]
1168
+ # @return [void]
1169
+ # @api public
1170
+ #: (untyped opts) -> void
1171
+ def header_footer=(opts)
1172
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
1173
+ @header_footer = h.transform_keys(&:to_sym)
1174
+ nil
1175
+ end
1176
+
1177
+ # Configures or queries print options (<printOptions>).
1178
+ #
1179
+ # When called with no arguments, returns the {Elements::PrintOptions} value object.
1180
+ # When called with arguments or keyword options, configures print options and returns nil.
1181
+ #
1182
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Option name or hash/record of options.
1183
+ # @param value [Object, nil] Option value.
1184
+ # @param opts [Hash] Additional print options.
1185
+ # @return [Elements::PrintOptions, void]
1186
+ # @api public
1187
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::PrintOptions | void)
1188
+ def print_options(name = nil, value = nil, **opts)
1189
+ return Elements::PrintOptions.new(**@print_options) if name.nil? && value.nil? && opts.empty?
1190
+
1191
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
1192
+ opts = name.to_h.merge(opts)
1193
+ name = nil
1194
+ end
1195
+ @print_options[name.to_sym] = value if name && !value.nil?
1196
+ opts.each { |k, v| @print_options[k.to_sym] = v }
1197
+ nil
1198
+ end
1199
+
1200
+ # Replaces print options with the given hash or {Elements::PrintOptions} object.
1201
+ #
1202
+ # @param opts [Hash, Elements::PrintOptions]
1203
+ # @return [void]
1204
+ # @api public
1205
+ #: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
1206
+ def print_options=(opts)
1207
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
1208
+ @print_options = h.transform_keys(&:to_sym)
1209
+ nil
591
1210
  end
592
1211
 
593
- # Sets a print option (e.g. grid_lines: true, headings: true).
1212
+ # Adds a defined name (named range or formula) scoped to this sheet or workbook.
1213
+ # Bare cell references and coordinate keywords are automatically formatted with sheet quotes and absolute $ references.
594
1214
  #
595
- # @param name [Symbol] Option name.
596
- # @param value [Object] Option value.
1215
+ # @param name [String] Defined name identifier.
1216
+ # @param value [Object, nil] Cell reference, formula, or constant.
1217
+ # @param hidden [Boolean] Whether the defined name is hidden from Excel's UI.
1218
+ # @param column [Integer, String, nil] Deprecated alias for columns.
1219
+ # @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
1220
+ # @param col [Integer, String, nil] Deprecated alias for column.
1221
+ # @param row [Integer, Range, nil] Deprecated alias for rows.
1222
+ # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
1223
+ # @param range [String, nil] Cell range reference (e.g. "A1:A10").
1224
+ # @param sheet [String, nil] Reference sheet name (defaults to current sheet).
1225
+ # @param scope [String, Symbol, nil] Scope identifier (:workbook or sheet name).
1226
+ # @param local [Boolean] Deprecated alias for scope: :current.
597
1227
  # @return [void]
598
1228
  # @api public
599
- #: (Symbol name, untyped value) -> void
600
- def print_options(name, value)
601
- @print_options[name] = value
1229
+ #: (String name, ?untyped value, ?hidden: bool, ?column: untyped, ?columns: untyped, ?col: untyped, ?row: untyped, ?rows: untyped, ?range: untyped, ?sheet: String?, ?scope: (String | Symbol)?, ?local: bool) -> void
1230
+ def defined_name(name, value = nil, hidden: false, column: nil, columns: nil, col: nil, row: nil, rows: nil, range: nil, sheet: nil, scope: nil, local: false)
1231
+ warn "[DEPRECATION] `col:` is deprecated; use `column:` (or `columns:`) instead.", uplevel: 1 if col
1232
+ warn "[DEPRECATION] `local:` is deprecated; use `scope:` instead.", uplevel: 1 if local
1233
+ warn "[Xlsxrb DEPRECATION] defined_name keyword column: is deprecated; use columns: instead.", uplevel: 1 unless column.nil?
1234
+ warn "[Xlsxrb DEPRECATION] defined_name keyword row: is deprecated; use rows: instead.", uplevel: 1 unless row.nil?
1235
+ c_arg = column || columns || col
1236
+ r_arg = row || rows
1237
+ ref_sheet = sheet || @name
1238
+ normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: ref_sheet, col: c_arg, rows: r_arg, range: range)
1239
+ entry = { name: name, value: normalized_val, hidden: hidden }
1240
+ local_sheet = if scope
1241
+ scope == :workbook ? nil : scope.to_s
1242
+ elsif local
1243
+ @name || sheet
1244
+ else
1245
+ sheet
1246
+ end
1247
+ entry[:local_sheet_name] = local_sheet if local_sheet
1248
+ @defined_names << entry
602
1249
  end
603
1250
 
604
1251
  # Sets or gets the print area for the worksheet.
@@ -610,13 +1257,24 @@ module Xlsxrb
610
1257
  # sheet.print_area #=> "A1:H50"
611
1258
  #
612
1259
  # @param range [String, nil] Cell range (e.g. "A1:H50").
613
- # @return [String, nil]
1260
+ # @return [String, nil, void]
614
1261
  # @api public
615
- #: (?String? range) -> String?
1262
+ #: (?String? range) -> (String | nil | void)
616
1263
  def print_area(range = nil)
617
1264
  return @print_area if range.nil?
618
1265
 
619
- @print_area = range
1266
+ @print_area = range&.to_s
1267
+ nil
1268
+ end
1269
+
1270
+ # Sets the print area for the worksheet.
1271
+ #
1272
+ # @param range [String, nil] Cell range (e.g. "A1:H50").
1273
+ # @return [String, nil]
1274
+ # @api public
1275
+ #: (String? range) -> String?
1276
+ def print_area=(range)
1277
+ @print_area = range&.to_s
620
1278
  end
621
1279
 
622
1280
  # Sets or gets repeating print titles (rows and/or columns) for pagination.
@@ -625,17 +1283,44 @@ module Xlsxrb
625
1283
  # sheet.print_titles(rows: "1:2")
626
1284
  #
627
1285
  # @example Get repeating print titles
628
- # sheet.print_titles #=> { rows: "1:2", cols: nil }
1286
+ # sheet.print_titles #=> { rows: "1:2", columns: nil, cols: nil }
629
1287
  #
630
1288
  # @param rows [String, nil] Repeating row range (e.g. "1:2").
631
- # @param cols [String, nil] Repeating column range (e.g. "A:B").
632
- # @return [Hash, nil]
1289
+ # @param rows [String, Integer, Range, nil] Repeating row range (e.g. "1:2" or 0-based 0..1).
1290
+ # @param columns [String, Integer, Symbol, Range, nil] Repeating column range (e.g. "A:B" or 0..1).
1291
+ # @param cols [String, Integer, Symbol, Range, nil] Deprecated alias for columns.
1292
+ # @return [Elements::PrintTitles, nil, void]
633
1293
  # @api public
634
- #: (?rows: String?, ?cols: String?) -> Hash[Symbol, untyped]?
635
- def print_titles(rows: nil, cols: nil)
636
- return @print_titles if rows.nil? && cols.nil?
1294
+ #: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?, ?cols: (String | Integer | Symbol | Range[untyped])?) -> (Elements::PrintTitles | nil | void)
1295
+ def print_titles(rows: nil, columns: nil, cols: nil)
1296
+ if rows.nil? && columns.nil? && cols.nil?
1297
+ return nil unless @print_titles
1298
+
1299
+ return Elements::PrintTitles.new(**@print_titles)
1300
+ end
637
1301
 
638
- @print_titles = { rows: rows, cols: cols }
1302
+ warn "[DEPRECATION] `cols:` is deprecated; use `columns:` instead.", uplevel: 1 if cols && columns.nil?
1303
+ c = columns || cols
1304
+ norm_rows = DslHelpers.normalize_print_titles_rows(rows)
1305
+ norm_cols = DslHelpers.normalize_print_titles_columns(c)
1306
+ @print_titles = Elements::PrintTitles.new(rows: norm_rows, columns: norm_cols, cols: norm_cols)
1307
+ nil
1308
+ end
1309
+
1310
+ # Sets repeating print titles for the worksheet.
1311
+ #
1312
+ # @param opts [Elements::PrintTitles, Hash, nil] Options with :rows and/or :columns.
1313
+ # @return [Elements::PrintTitles, Hash, nil]
1314
+ # @api public
1315
+ #: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
1316
+ def print_titles=(opts)
1317
+ if opts.nil?
1318
+ @print_titles = nil
1319
+ else
1320
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
1321
+ print_titles(**h)
1322
+ end
1323
+ opts
639
1324
  end
640
1325
 
641
1326
  # Sets repeating title rows to appear at the top of each printed page.
@@ -659,7 +1344,8 @@ module Xlsxrb
659
1344
  last ||= first
660
1345
  "#{first + 1}:#{last + 1}"
661
1346
  end
662
- @print_titles = (@print_titles || {}).merge(rows: rows_str)
1347
+ existing_cols = @print_titles&.columns
1348
+ print_titles(rows: rows_str, columns: existing_cols)
663
1349
  end
664
1350
 
665
1351
  # Sets repeating title columns to appear at the left of each printed page.
@@ -680,9 +1366,9 @@ module Xlsxrb
680
1366
  cols_str = if first.is_a?(String)
681
1367
  first.include?(":") ? first : "#{first}:#{last || first}"
682
1368
  else
683
- first_name = Utils.col_index_to_name(first)
1369
+ first_name = Elements::Cell._column_letter(first)
684
1370
  last_name = if last.is_a?(Integer)
685
- Utils.col_index_to_name(last)
1371
+ Elements::Cell._column_letter(last)
686
1372
  elsif last
687
1373
  last.to_s
688
1374
  else
@@ -690,121 +1376,427 @@ module Xlsxrb
690
1376
  end
691
1377
  "#{first_name}:#{last_name}"
692
1378
  end
693
- @print_titles = (@print_titles || {}).merge(cols: cols_str)
1379
+ existing_rows = @print_titles&.rows
1380
+ print_titles(rows: existing_rows, columns: cols_str)
694
1381
  end
695
1382
 
696
- # Sets sheet-level protection with optional password hashing.
1383
+ # Configures or queries sheet-level protection with optional password hashing (<sheetProtection>).
1384
+ #
1385
+ # When called with no arguments, returns the sheet protection value object or hash.
1386
+ # When called with keyword arguments, sets sheet protection and returns nil.
697
1387
  #
698
1388
  # @param opts [Hash] Protection options (e.g. password: "secret", select_locked_cells: true).
1389
+ # @return [Elements::SheetProtection, Hash<Symbol, untyped>, nil, void]
1390
+ # @api public
1391
+ #: (**untyped opts) -> (untyped | void)
1392
+ def sheet_protection(**opts)
1393
+ if opts.empty?
1394
+ return nil unless @sheet_protection
1395
+ return Elements::SheetProtection.new(**@sheet_protection) if defined?(Elements::SheetProtection)
1396
+
1397
+ @sheet_protection
1398
+ else
1399
+ @sheet_protection = DslHelpers.normalize_protection_options(opts)
1400
+ nil
1401
+ end
1402
+ end
1403
+
1404
+ # Sets or clears sheet protection configuration.
1405
+ #
1406
+ # @param opts [Elements::SheetProtection, Hash, Boolean, nil]
699
1407
  # @return [void]
700
1408
  # @api public
1409
+ #: (untyped opts) -> void
1410
+ def sheet_protection=(opts)
1411
+ if opts.nil? || opts == false
1412
+ @sheet_protection = nil
1413
+ elsif opts == true
1414
+ @sheet_protection = DslHelpers.normalize_protection_options(sheet: true)
1415
+ else
1416
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
1417
+ @sheet_protection = DslHelpers.normalize_protection_options(h)
1418
+ end
1419
+ nil
1420
+ end
1421
+
1422
+ # @deprecated Use {#sheet_protection} instead.
701
1423
  #: (**untyped opts) -> void
702
- def protect_sheet(**opts)
703
- @sheet_protection = DslHelpers.normalize_protection_options(opts)
1424
+ def protect_sheet(...)
1425
+ warn "[DEPRECATION] `protect_sheet` is deprecated; use `sheet_protection` instead.", uplevel: 1
1426
+ sheet_protection(...)
704
1427
  end
705
1428
 
706
1429
  # Inserts an embedded image from raw binary data.
707
1430
  #
708
1431
  # @param file_data [String] Binary image data.
709
1432
  # @param ext [String] File extension ("png", "jpeg", etc.).
710
- # @param from_col [Integer] Top-left starting column (0-based).
1433
+ # @param from_column [Integer, nil] Top-left starting column (0-based).
1434
+ # @param from_col [Integer, nil] Deprecated alias for from_column.
711
1435
  # @param from_row [Integer] Top-left starting row (0-based).
712
- # @param to_col [Integer] Bottom-right ending column (0-based).
1436
+ # @param to_column [Integer, nil] Bottom-right ending column (0-based).
1437
+ # @param to_col [Integer, nil] Deprecated alias for to_column.
713
1438
  # @param to_row [Integer] Bottom-right ending row (0-based).
714
1439
  # @param opts [Hash] Additional image anchoring options.
715
1440
  # @return [void]
716
1441
  # @api public
717
- #: (String file_data, ?ext: ::String, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, **untyped opts) -> void
718
- def image(file_data, ext: "png", from_col: 0, from_row: 0, to_col: 5, to_row: 10, **opts)
719
- img = { file_data: file_data, ext: ext, from_col: from_col, from_row: from_row, to_col: to_col, to_row: to_row }
1442
+ #: (String file_data, ?ext: ::String, ?from_column: ::Integer?, ?from_col: ::Integer?, ?from_row: ::Integer, ?to_column: ::Integer?, ?to_col: ::Integer?, ?to_row: ::Integer, **untyped opts) -> void
1443
+ def image(file_data, ext: "png", from_column: nil, from_col: nil, from_row: 0, to_column: nil, to_col: nil, to_row: 10, **opts)
1444
+ warn "[DEPRECATION] `from_col:` is deprecated; use `from_column:` instead.", uplevel: 1 if from_col && from_column.nil?
1445
+ warn "[DEPRECATION] `to_col:` is deprecated; use `to_column:` instead.", uplevel: 1 if to_col && to_column.nil?
1446
+ fc = from_column || from_col || 0
1447
+ tc = to_column || to_col || 5
1448
+ img = { file_data: file_data, ext: ext, from_column: fc, from_col: fc, from_row: from_row, to_column: tc, to_col: tc, to_row: to_row }
720
1449
  img.merge!(opts)
721
1450
  @images << img
722
1451
  end
723
1452
 
1453
+ # Configures the worksheet background image (<picture>).
1454
+ #
1455
+ # @example Set background image from binary data
1456
+ # sheet.background_image(png_bytes, ext: "png")
1457
+ #
1458
+ # @example Set background image from file path
1459
+ # sheet.background_image("path/to/background.png")
1460
+ #
1461
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#background_image=} instead.
1462
+ # @param file_data [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
1463
+ # @param ext [String, nil] Image extension ("png", "jpeg", "jpg", "gif", etc.).
1464
+ # @param opts [Hash] Additional image options.
1465
+ # @return [Hash, nil]
1466
+ # @api public
1467
+ #: (?untyped file_data, ?ext: ::String?, **untyped opts) -> (Elements::BackgroundImage | Hash[Symbol, untyped] | nil)
1468
+ def background_image(file_data = nil, ext: nil, **opts)
1469
+ if file_data.nil? && ext.nil? && opts.empty?
1470
+ return nil unless @background_image
1471
+
1472
+ return @background_image.is_a?(Elements::BackgroundImage) ? @background_image : Elements::BackgroundImage.new(**@background_image)
1473
+ end
1474
+
1475
+ data = file_data
1476
+ inferred_ext = nil
1477
+ if data.is_a?(String) && !data.include?("\x00") && File.file?(data)
1478
+ inferred_ext = File.extname(data).delete_prefix(".").downcase
1479
+ data = File.binread(data)
1480
+ elsif data.is_a?(Hash)
1481
+ inferred_ext = data[:ext] || (data[:filename] && File.extname(data[:filename]).delete_prefix("."))
1482
+ data = data[:file_data] || data[:data]
1483
+ elsif data.is_a?(Elements::Image)
1484
+ inferred_ext = File.extname(data.filename).delete_prefix(".").downcase
1485
+ data = data.data
1486
+ end
1487
+
1488
+ final_ext = (ext || inferred_ext || opts[:ext] || "png").to_s.delete_prefix(".").downcase
1489
+ mime = case final_ext
1490
+ when "png" then "image/png"
1491
+ when "jpg", "jpeg" then "image/jpeg"
1492
+ when "gif" then "image/gif"
1493
+ when "bmp" then "image/bmp"
1494
+ when "emf" then "image/x-emf"
1495
+ when "wmf" then "image/x-wmf"
1496
+ else "application/octet-stream"
1497
+ end
1498
+
1499
+ @background_image = {
1500
+ data: data&.b,
1501
+ file_data: data&.b,
1502
+ ext: final_ext,
1503
+ filename: "background.#{final_ext}",
1504
+ content_type: mime
1505
+ }.merge(opts).freeze
1506
+ end
1507
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1508
+ alias background_picture background_image
1509
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1510
+ alias picture background_image
1511
+
1512
+ #: (untyped val) -> untyped
1513
+ def background_image=(val)
1514
+ if val.nil?
1515
+ @background_image = nil
1516
+ else
1517
+ background_image(val)
1518
+ end
1519
+ val
1520
+ end
1521
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1522
+ alias background_picture= background_image=
1523
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1524
+ alias picture= background_image=
1525
+
724
1526
  # Inserts a drawing shape (e.g. rectangle, callout, arrow).
725
1527
  #
726
1528
  # @param preset [String] Shape preset name (e.g. "rect", "roundRect").
727
1529
  # @param text [String, nil] Shape label text.
728
- # @param from_col [Integer] Top-left column.
1530
+ # @param from_column [Integer, nil] Top-left column.
1531
+ # @param from_col [Integer, nil] Deprecated alias for from_column.
729
1532
  # @param from_row [Integer] Top-left row.
730
- # @param to_col [Integer] Bottom-right column.
1533
+ # @param to_column [Integer, nil] Bottom-right column.
1534
+ # @param to_col [Integer, nil] Deprecated alias for to_column.
731
1535
  # @param to_row [Integer] Bottom-right row.
732
1536
  # @param opts [Hash] Additional shape formatting options.
733
1537
  # @return [void]
734
1538
  # @api public
735
1539
  #: (**untyped opts) -> void
736
- def shape(preset: "rect", text: nil, from_col: 0, from_row: 0, to_col: 5, to_row: 5, **opts)
737
- shape = { preset: preset, text: text, from_col: from_col, from_row: from_row, to_col: to_col, to_row: to_row }
738
- shape[:name] = opts.delete(:name) || "Shape #{@shapes.size + 1}"
739
- shape.merge!(opts)
740
- @shapes << shape
741
- end
742
-
743
- # Sets a sheet-level property (e.g. tab_color: "FF0000").
1540
+ def shape(preset: "rect", text: nil, from_column: nil, from_col: nil, from_row: 0, to_column: nil, to_col: nil, to_row: 5, **opts)
1541
+ warn "[DEPRECATION] `from_col:` is deprecated; use `from_column:` instead.", uplevel: 1 if from_col && from_column.nil?
1542
+ warn "[DEPRECATION] `to_col:` is deprecated; use `to_column:` instead.", uplevel: 1 if to_col && to_column.nil?
1543
+ fc = from_column || from_col || 0
1544
+ tc = to_column || to_col || 5
1545
+ shape_data = { preset: preset, text: text, from_column: fc, from_col: fc, from_row: from_row, to_column: tc, to_col: tc, to_row: to_row }
1546
+ shape_data[:name] = opts.delete(:name) || "Shape #{@shapes.size + 1}"
1547
+ shape_data.merge!(opts)
1548
+ @shapes << shape_data
1549
+ end
1550
+
1551
+ # Gets or sets the sheet visibility state (:visible, :hidden, or :very_hidden).
744
1552
  #
745
- # @param name [Symbol] Property name.
746
- # @param value [Object] Property value.
747
- # @return [void]
1553
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#state=} instead.
1554
+ # @param new_state [Symbol, nil] The new state.
1555
+ # @return [Symbol]
748
1556
  # @api public
749
- #: (Symbol name, untyped value) -> void
750
- def sheet_properties(name, value)
751
- @sheet_properties[name] = value
1557
+ #: (?Symbol? new_state) -> Symbol
1558
+ def state(new_state = nil)
1559
+ if new_state
1560
+ val = new_state.to_sym
1561
+ raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
1562
+
1563
+ @state = val
1564
+ else
1565
+ @state
1566
+ end
752
1567
  end
753
1568
 
754
- # Sets a sheet view display property (e.g. show_grid_lines: true, zoom_scale: 120).
1569
+ # Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
755
1570
  #
756
- # @param name [Symbol] View property name.
757
- # @param value [Object] View property value.
758
- # @return [void]
1571
+ # @param new_state [Symbol, String] The new state.
1572
+ # @return [Symbol]
759
1573
  # @api public
760
- #: (Symbol name, untyped value) -> void
761
- def sheet_view(name, value)
762
- @sheet_view[name] = value
1574
+ #: (Symbol | String new_state) -> Symbol
1575
+ def state=(new_state)
1576
+ val = new_state.to_sym
1577
+ raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
1578
+
1579
+ @state = val
763
1580
  end
764
1581
 
765
- # Configures sheet format properties (e.g. default_row_height, default_col_width).
766
- #
767
- # @example Using keyword arguments
768
- # sheet.sheet_format(default_row_height: 24, default_col_width: 15)
769
- #
770
- # @example Using property name and value
771
- # sheet.sheet_format(:default_row_height, 24)
1582
+ # Gets or sets the worksheet tab color.
772
1583
  #
773
- # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
774
- # @param value [Object, nil] Property value when name is provided.
775
- # @param opts [Hash] Keyword arguments for sheet format properties.
776
- # @return [Hash]
1584
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_color=} instead.
1585
+ # @overload tab_color()
1586
+ # Returns the current tab color specification.
1587
+ # @return [String, Hash, nil]
1588
+ # @overload tab_color(spec, **opts)
1589
+ # Sets the tab color using an RGB hex string or color options.
1590
+ # @param spec [String, Hash, Symbol, nil] RGB hex string (e.g. "FF0000"), theme/indexed hash, or nil.
1591
+ # @param opts [Hash] Color keyword arguments (e.g. theme: 1, tint: 0.5, indexed: 9, auto: true).
1592
+ # @return [String, Hash, nil]
777
1593
  # @api public
778
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
779
- def sheet_format(name = nil, value = nil, **opts)
780
- if name.is_a?(Hash)
781
- @sheet_format.merge!(name)
782
- elsif name && value
783
- @sheet_format[name.to_sym] = value
1594
+ #: (?String | Symbol | Hash[Symbol, untyped] | nil spec, **untyped opts) -> (String | Hash[Symbol, untyped] | nil)
1595
+ def tab_color(spec = OMITTED, **opts)
1596
+ if spec.equal?(OMITTED) && opts.empty?
1597
+ @sheet_properties[:tab_color]
1598
+ else
1599
+ color = if opts.empty?
1600
+ spec
1601
+ else
1602
+ spec.is_a?(Hash) ? spec.merge(opts) : opts
1603
+ end
1604
+ @sheet_properties[:tab_color] = color
784
1605
  end
785
- @sheet_format.merge!(opts) unless opts.empty?
786
- @sheet_format
787
1606
  end
788
1607
 
789
- # Inserts a horizontal page break before the specified row.
1608
+ # Sets the tab color of this worksheet.
790
1609
  #
791
- # @param row_num [Integer] 1-based row number.
792
- # @return [void]
1610
+ # @param spec [String, Hash, Symbol, nil] Tab color hex string (e.g. "FF0000") or hash options.
1611
+ # @return [String, Hash, nil]
793
1612
  # @api public
1613
+ #: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
1614
+ def tab_color=(spec)
1615
+ @sheet_properties[:tab_color] = spec
1616
+ end
1617
+
1618
+ # Sets a single sheet property.
1619
+ #
1620
+ # @param name [Symbol, String] Property name.
1621
+ # @param value [Object] Property value.
1622
+ # @return [void]
1623
+ # @api public
1624
+ #: (Symbol | String name, untyped value) -> void
1625
+ def sheet_property(name, value)
1626
+ sheet_properties(name, value)
1627
+ end
1628
+
1629
+ # Configures or queries sheet properties (<sheetPr>).
1630
+ #
1631
+ # When called with no arguments, returns the {Elements::SheetProperties} value object.
1632
+ # When called with arguments or keyword options, configures properties and returns nil.
1633
+ #
1634
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
1635
+ # @param value [Object, nil] Property value when name is provided.
1636
+ # @param opts [Hash] Additional sheet properties.
1637
+ # @return [Elements::SheetProperties, void]
1638
+ # @api public
1639
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetProperties | void)
1640
+ def sheet_properties(name = nil, value = nil, **opts)
1641
+ return Elements::SheetProperties.new(**@sheet_properties) if name.nil? && value.nil? && opts.empty?
1642
+
1643
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
1644
+ opts = name.to_h.merge(opts)
1645
+ name = nil
1646
+ end
1647
+ if name && !value.nil?
1648
+ sym = name.to_sym
1649
+ if sym == :state
1650
+ val = value.to_sym
1651
+ raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
1652
+
1653
+ @state = val
1654
+ return nil
1655
+ elsif sym == :hidden
1656
+ @state = value ? :hidden : :visible
1657
+ return nil
1658
+ end
1659
+ @sheet_properties[name.to_sym] = value
1660
+ end
1661
+ opts.each { |k, v| sheet_properties(k, v) }
1662
+ nil
1663
+ end
1664
+
1665
+ # Replaces worksheet properties with the given hash or {Elements::SheetProperties} object.
1666
+ #
1667
+ # @param opts [Hash, Elements::SheetProperties]
1668
+ # @return [void]
1669
+ # @api public
1670
+ #: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
1671
+ def sheet_properties=(opts)
1672
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
1673
+ @sheet_properties = {}
1674
+ h.each { |k, v| sheet_properties(k, v) }
1675
+ nil
1676
+ end
1677
+
1678
+ # Configures or queries sheet view display properties (<sheetView>).
1679
+ #
1680
+ # When called with no arguments, returns the {Elements::SheetView} value object.
1681
+ # When called with arguments or keyword options, configures view properties and returns nil.
1682
+ #
1683
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] View property name or hash/record of properties.
1684
+ # @param value [Object, nil] View property value when name is provided.
1685
+ # @param opts [Hash] Additional view properties.
1686
+ # @return [Elements::SheetView, void]
1687
+ # @api public
1688
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetView | void)
1689
+ def sheet_view(name = nil, value = nil, **opts)
1690
+ return Elements::SheetView.new(**@sheet_view) if name.nil? && value.nil? && opts.empty?
1691
+
1692
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
1693
+ opts = name.to_h.merge(opts)
1694
+ name = nil
1695
+ end
1696
+ @sheet_view[name.to_sym] = value if name && !value.nil?
1697
+ opts.each { |k, v| @sheet_view[k.to_sym] = v }
1698
+ nil
1699
+ end
1700
+
1701
+ # Replaces sheet view properties with the given hash or {Elements::SheetView} object.
1702
+ #
1703
+ # @param opts [Hash, Elements::SheetView]
1704
+ # @return [void]
1705
+ # @api public
1706
+ #: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
1707
+ def sheet_view=(opts)
1708
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
1709
+ @sheet_view = h.transform_keys(&:to_sym)
1710
+ nil
1711
+ end
1712
+
1713
+ # Configures or queries sheet format properties (<sheetFormatPr>).
1714
+ #
1715
+ # When called with no arguments, returns the {Elements::SheetFormat} value object.
1716
+ # When called with arguments or keyword options, configures format properties and returns nil.
1717
+ #
1718
+ # @example Using keyword arguments
1719
+ # sheet.sheet_format(default_row_height: 24, default_column_width: 15)
1720
+ #
1721
+ # @example Using property name and value
1722
+ # sheet.sheet_format(:default_row_height, 24)
1723
+ #
1724
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
1725
+ # @param value [Object, nil] Property value when name is provided.
1726
+ # @param opts [Hash] Keyword arguments for sheet format properties.
1727
+ # @return [Elements::SheetFormat, void]
1728
+ # @api public
1729
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetFormat | void)
1730
+ def sheet_format(name = nil, value = nil, **opts)
1731
+ return Elements::SheetFormat.new(**@sheet_format) if name.nil? && value.nil? && opts.empty?
1732
+
1733
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
1734
+ @sheet_format.merge!(name.to_h)
1735
+ elsif name && value
1736
+ @sheet_format[name.to_sym] = value
1737
+ end
1738
+ if opts.key?(:default_col_width) && !opts.key?(:default_column_width)
1739
+ warn "[DEPRECATION] `default_col_width:` is deprecated; use `default_column_width:` instead.", uplevel: 1
1740
+ opts[:default_column_width] = opts[:default_col_width]
1741
+ end
1742
+ if opts.key?(:base_col_width) && !opts.key?(:base_column_width)
1743
+ warn "[DEPRECATION] `base_col_width:` is deprecated; use `base_column_width:` instead.", uplevel: 1
1744
+ opts[:base_column_width] = opts[:base_col_width]
1745
+ end
1746
+ if opts.key?(:outline_level_col) && !opts.key?(:outline_level_column)
1747
+ warn "[DEPRECATION] `outline_level_col:` is deprecated; use `outline_level_column:` instead.", uplevel: 1
1748
+ opts[:outline_level_column] = opts[:outline_level_col]
1749
+ end
1750
+ @sheet_format.merge!(opts) unless opts.empty?
1751
+ nil
1752
+ end
1753
+
1754
+ # Replaces sheet format properties with the given hash or {Elements::SheetFormat} object.
1755
+ #
1756
+ # @param opts [Hash, Elements::SheetFormat]
1757
+ # @return [void]
1758
+ # @api public
1759
+ #: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
1760
+ def sheet_format=(opts)
1761
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
1762
+ @sheet_format = {}
1763
+ sheet_format(h)
1764
+ nil
1765
+ end
1766
+
1767
+ # Inserts a horizontal page break after the specified 0-based row.
1768
+ #
1769
+ # @param row_index [Integer] 0-based row index.
1770
+ # @return [void]
1771
+ # @api public
1772
+ #: (Integer row_index) -> void
1773
+ def row_break(row_index)
1774
+ @row_breaks << { id: row_index, max: 16_383, man: 1 }
1775
+ end
1776
+
1777
+ # @deprecated Use {#row_break} instead.
794
1778
  #: (Integer row_num) -> void
795
1779
  def page_break_row(row_num)
796
- @row_breaks << row_num
1780
+ warn "[DEPRECATION] `page_break_row` is deprecated; use `row_break` instead.", uplevel: 1
1781
+ row_break(row_num)
797
1782
  end
798
1783
 
799
- # Inserts a vertical page break before the specified column.
1784
+ # Inserts a vertical page break after the specified column.
800
1785
  #
801
- # @param col_index [Integer, String] Column index (0-based) or letter ("B").
1786
+ # @param col [Integer, String, Symbol] Column index (0-based) or letter ("B", :B).
802
1787
  # @return [void]
803
1788
  # @api public
804
- #: (Integer | String col_index) -> void
1789
+ #: (Integer | String | Symbol col) -> void
1790
+ def column_break(col)
1791
+ col_index = Elements::Cell._column_index(col)
1792
+ @col_breaks << { id: col_index, max: 1_048_575, man: 1 }
1793
+ end
1794
+
1795
+ # @deprecated Use {#column_break} instead.
1796
+ #: (Integer | String | Symbol col_index) -> void
805
1797
  def page_break_col(col_index)
806
- col_index = Elements::Cell.column_index(col_index)
807
- @col_breaks << col_index
1798
+ warn "[DEPRECATION] `page_break_col` is deprecated; use `column_break` instead.", uplevel: 1
1799
+ column_break(col_index)
808
1800
  end
809
1801
 
810
1802
  # Adds a protected range to the worksheet.
@@ -822,6 +1814,7 @@ module Xlsxrb
822
1814
  entry.merge!(opts) unless opts.empty?
823
1815
  @protected_ranges << DslHelpers.normalize_protection_options(entry)
824
1816
  end
1817
+ # @deprecated Use {#protected_range} instead. Will be removed in 0.2.0.
825
1818
  alias add_protected_range protected_range
826
1819
 
827
1820
  # Adds a cell watch to the worksheet.
@@ -833,8 +1826,239 @@ module Xlsxrb
833
1826
  def cell_watch(ref)
834
1827
  @cell_watches << ref.to_s
835
1828
  end
1829
+ # @deprecated Use {#cell_watch} instead. Will be removed in 0.2.0.
836
1830
  alias add_cell_watch cell_watch
837
1831
 
1832
+ # Adds an ignored error entry for the worksheet.
1833
+ #
1834
+ # @param sqref [String] Cell range reference (e.g. "A1" or "A1:B10").
1835
+ # @param opts [Hash] Error check flags to ignore (e.g. number_stored_as_text: true, eval_error: true).
1836
+ # @return [void]
1837
+ # @api public
1838
+ #: (String sqref, ?eval_error: bool, ?two_digit_text_year: bool, ?number_stored_as_text: bool, ?formula: bool, ?formula_range: bool, ?unlocked_formula: bool, ?empty_cell_reference: bool, ?list_data_validation: bool, ?calculated_column: bool) -> void
1839
+ def ignored_error(sqref, **opts)
1840
+ @ignored_errors << { sqref: sqref.to_s }.merge(opts)
1841
+ end
1842
+
1843
+ # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
1844
+ #: (String sqref, ?eval_error: bool, ?two_digit_text_year: bool, ?number_stored_as_text: bool, ?formula: bool, ?formula_range: bool, ?unlocked_formula: bool, ?empty_cell_reference: bool, ?list_data_validation: bool, ?calculated_column: bool) -> void
1845
+ def ignore_error(sqref, **opts)
1846
+ warn "[DEPRECATION] #ignore_error is deprecated; use #ignored_error instead.", uplevel: 1
1847
+ ignored_error(sqref, **opts)
1848
+ end
1849
+
1850
+ # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
1851
+ #: (String sqref, ?eval_error: bool, ?two_digit_text_year: bool, ?number_stored_as_text: bool, ?formula: bool, ?formula_range: bool, ?unlocked_formula: bool, ?empty_cell_reference: bool, ?list_data_validation: bool, ?calculated_column: bool) -> void
1852
+ def add_ignored_error(sqref, **opts)
1853
+ warn "[DEPRECATION] #add_ignored_error is deprecated; use #ignored_error instead.", uplevel: 1
1854
+ ignored_error(sqref, **opts)
1855
+ end
1856
+
1857
+ # Returns ignored error rules configured for this worksheet.
1858
+ #
1859
+ # @return [Array<Hash[Symbol, untyped]>]
1860
+ # @api public
1861
+ #: () -> Array[Hash[Symbol, untyped]]
1862
+ def ignored_errors
1863
+ @ignored_errors.map { |ie| ie.is_a?(Elements::IgnoredError) ? ie : Elements::IgnoredError.new(**ie) }.freeze
1864
+ end
1865
+
1866
+ # Gets or sets phonetic (furigana) guide properties for the worksheet.
1867
+ #
1868
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#phonetic_properties=} instead.
1869
+ # @overload phonetic_properties()
1870
+ # Returns the current phonetic properties.
1871
+ # @return [Hash, nil]
1872
+ # @overload phonetic_properties(props = nil, font_id: nil, type: nil, alignment: nil)
1873
+ # Sets phonetic properties.
1874
+ # @param spec [Hash, Integer, nil]
1875
+ # @param font_id [Integer, nil]
1876
+ # @param type [Symbol, String, nil]
1877
+ # @param alignment [Symbol, String, nil]
1878
+ # @return [Hash, nil]
1879
+ # @api public
1880
+ #: (?untyped spec, ?font_id: Integer?, ?type: (Symbol | String)?, ?alignment: (Symbol | String)?, **untyped opts) -> (Elements::PhoneticProperties | Hash[Symbol, untyped] | nil)
1881
+ def phonetic_properties(spec = OMITTED, font_id: nil, type: nil, alignment: nil, **opts)
1882
+ if spec.equal?(OMITTED) && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
1883
+ return nil unless @phonetic_properties
1884
+
1885
+ @phonetic_properties.is_a?(Elements::PhoneticProperties) ? @phonetic_properties : Elements::PhoneticProperties.new(**@phonetic_properties)
1886
+ elsif !spec.equal?(OMITTED) && spec.nil? && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
1887
+ @phonetic_properties = nil
1888
+ else
1889
+ props = if spec.is_a?(Hash)
1890
+ spec.merge(opts)
1891
+ elsif spec.is_a?(Integer)
1892
+ { font_id: spec, type: type, alignment: alignment }.merge(opts)
1893
+ else
1894
+ { font_id: font_id, type: type, alignment: alignment }.merge(opts)
1895
+ end
1896
+ props.compact!
1897
+ @phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
1898
+ end
1899
+ end
1900
+ # @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
1901
+ alias phonetic_pr phonetic_properties
1902
+
1903
+ # Sets phonetic (furigana) guide properties for the sheet.
1904
+ #
1905
+ # @param spec [Hash, Integer, nil] Options hash or font ID integer.
1906
+ # @return [Hash[Symbol, untyped], Integer, nil]
1907
+ # @api public
1908
+ #: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
1909
+ def phonetic_properties=(spec)
1910
+ if spec.nil?
1911
+ @phonetic_properties = nil
1912
+ else
1913
+ props = if spec.is_a?(Hash)
1914
+ spec.dup
1915
+ elsif spec.is_a?(Integer)
1916
+ { font_id: spec }
1917
+ else
1918
+ {}
1919
+ end
1920
+ @phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
1921
+ end
1922
+ spec
1923
+ end
1924
+ # @deprecated Use {#phonetic_properties=} instead. Will be removed in 0.2.0.
1925
+ alias phonetic_pr= phonetic_properties=
1926
+
1927
+ # Normalizes phonetic properties to OOXML schema values.
1928
+ #
1929
+ # @param props [Hash, nil]
1930
+ # @return [Hash[Symbol, untyped], nil]
1931
+ # @api private
1932
+ #: (Hash[untyped, untyped]? props) -> Hash[Symbol, untyped]?
1933
+ def self.normalize_phonetic_properties(props)
1934
+ return nil if props.nil? || props.empty?
1935
+
1936
+ raw_font = props[:font_id] || props["font_id"] || props[:fontId] || props["fontId"] || 0
1937
+ type = props[:type] || props["type"]
1938
+ type_str = case type&.to_s
1939
+ when "hiragana", "Hiragana" then "Hiragana"
1940
+ when "halfwidth_katakana", "halfwidthKatakana" then "halfwidthKatakana"
1941
+ when "fullwidth_katakana", "fullwidthKatakana" then "fullwidthKatakana"
1942
+ when "no_conversion", "noConversion" then "noConversion"
1943
+ else type&.to_s
1944
+ end
1945
+
1946
+ align = props[:alignment] || props["alignment"]
1947
+ align_str = case align&.to_s
1948
+ when "no_control", "noControl" then "noControl"
1949
+ when "left" then "left"
1950
+ when "center" then "center"
1951
+ when "distributed" then "distributed"
1952
+ else align&.to_s
1953
+ end
1954
+
1955
+ res = { font_id: raw_font.to_i }
1956
+ res[:type] = type_str if type_str
1957
+ res[:alignment] = align_str if align_str
1958
+ res
1959
+ end
1960
+
1961
+ # Sets or gets the internal code name of the worksheet.
1962
+ #
1963
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
1964
+ # @param val [String, Symbol, nil] The code name.
1965
+ # @return [String, nil]
1966
+ # @api public
1967
+ #: (?String | Symbol | nil val) -> String?
1968
+ def code_name(val = OMITTED)
1969
+ return @sheet_properties[:code_name] if val.equal?(OMITTED)
1970
+
1971
+ @sheet_properties[:code_name] = val&.to_s
1972
+ end
1973
+
1974
+ # Sets the internal code name of the worksheet.
1975
+ #
1976
+ # @param val [String, Symbol, nil] The code name.
1977
+ # @return [String, nil]
1978
+ # @api public
1979
+ #: (String | Symbol | nil val) -> String?
1980
+ def code_name=(val)
1981
+ @sheet_properties[:code_name] = val&.to_s
1982
+ end
1983
+
1984
+ # Configures worksheet calculation properties (<sheetCalcPr>).
1985
+ #
1986
+ # @example Instruct Excel to recalculate formulas when loading sheet
1987
+ # sheet.sheet_calc_properties = { full_calc_on_load: true }
1988
+ #
1989
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sheet_calc_properties=} instead.
1990
+ # @param spec [Hash, nil] Calculation properties hash.
1991
+ # @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
1992
+ # @return [Hash, nil]
1993
+ # @api public
1994
+ #: (?untyped spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
1995
+ def sheet_calc_properties(spec = OMITTED, full_calc_on_load: nil, **opts)
1996
+ if spec.equal?(OMITTED) && full_calc_on_load.nil? && opts.empty?
1997
+ calc = @sheet_calc_pr || (@sheet_properties[:full_calc_on_load] ? { full_calc_on_load: true } : nil)
1998
+ return nil unless calc
1999
+
2000
+ return calc.is_a?(Elements::SheetCalcProperties) ? calc : Elements::SheetCalcProperties.new(**calc)
2001
+ end
2002
+
2003
+ warn "[DEPRECATION] Calling #sheet_calc_properties with arguments is deprecated and will be removed in 0.2.0. Use #sheet_calc_properties= instead.", uplevel: 1
2004
+ if !spec.equal?(OMITTED) && spec.nil? && full_calc_on_load.nil? && opts.empty?
2005
+ @sheet_properties.delete(:full_calc_on_load)
2006
+ return @sheet_calc_pr = nil
2007
+ end
2008
+
2009
+ pr = spec.is_a?(Hash) ? spec.dup : {}
2010
+ pr[:full_calc_on_load] = full_calc_on_load unless full_calc_on_load.nil?
2011
+ pr.merge!(opts) unless opts.empty?
2012
+ @sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
2013
+ @sheet_calc_pr = pr
2014
+ end
2015
+
2016
+ # Sets worksheet calculation properties (<sheetCalcPr>).
2017
+ #
2018
+ # @param spec [Hash, nil] Calculation properties hash.
2019
+ # @return [Hash, nil]
2020
+ # @api public
2021
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2022
+ def sheet_calc_properties=(spec)
2023
+ if spec.nil?
2024
+ @sheet_properties.delete(:full_calc_on_load)
2025
+ @sheet_calc_pr = nil
2026
+ else
2027
+ pr = spec.is_a?(Hash) ? spec.dup : {}
2028
+ @sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
2029
+ @sheet_calc_pr = pr
2030
+ end
2031
+ spec
2032
+ end
2033
+
2034
+ # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
2035
+ #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2036
+ def sheet_calc_pr(spec = OMITTED, full_calc_on_load: nil, **opts)
2037
+ warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
2038
+ sheet_calc_properties(spec, full_calc_on_load: full_calc_on_load, **opts)
2039
+ end
2040
+
2041
+ # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
2042
+ #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2043
+ def calc_pr(spec = OMITTED, full_calc_on_load: nil, **opts)
2044
+ warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
2045
+ sheet_calc_properties(spec, full_calc_on_load: full_calc_on_load, **opts)
2046
+ end
2047
+
2048
+ # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
2049
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2050
+ def sheet_calc_pr=(spec)
2051
+ warn "[DEPRECATION] #sheet_calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
2052
+ self.sheet_calc_properties = spec
2053
+ end
2054
+
2055
+ # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
2056
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2057
+ def calc_pr=(spec)
2058
+ warn "[DEPRECATION] #calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
2059
+ self.sheet_calc_properties = spec
2060
+ end
2061
+
838
2062
  # Builds and returns the in-memory {Elements::Worksheet}.
839
2063
  #
840
2064
  # @return [Elements::Worksheet]
@@ -851,6 +2075,7 @@ module Xlsxrb
851
2075
  facade_meta[:tables] = @tables unless @tables.empty?
852
2076
  facade_meta[:pivot_tables] = @pivot_tables unless (@pivot_tables || []).empty?
853
2077
  facade_meta[:comments] = @comments unless @comments.empty?
2078
+ facade_meta[:threaded_comments] = @threaded_comments unless @threaded_comments.empty?
854
2079
  facade_meta[:sparkline_groups] = @sparkline_groups unless @sparkline_groups.empty?
855
2080
  facade_meta[:merge_cells] = @merge_cells_ranges unless @merge_cells_ranges.empty?
856
2081
  facade_meta[:freeze_pane] = @freeze_pane if @freeze_pane
@@ -870,35 +2095,62 @@ module Xlsxrb
870
2095
  facade_meta[:col_breaks] = @col_breaks unless @col_breaks.empty?
871
2096
  facade_meta[:protected_ranges] = @protected_ranges unless @protected_ranges.empty?
872
2097
  facade_meta[:cell_watches] = @cell_watches unless @cell_watches.empty?
2098
+ facade_meta[:ignored_errors] = @ignored_errors unless @ignored_errors.empty?
2099
+ facade_meta[:phonetic_properties] = @phonetic_properties if @phonetic_properties
2100
+ facade_meta[:sheet_calc_pr] = @sheet_calc_pr if @sheet_calc_pr
2101
+ facade_meta[:background_image] = @background_image if @background_image
873
2102
  facade_meta[:print_area] = @print_area if @print_area
874
2103
  facade_meta[:print_titles] = @print_titles if @print_titles
875
2104
 
876
2105
  hl_hash = {}
877
2106
  @hyperlinks.each do |h|
878
- ref = h[:cell].to_s.upcase
879
- entry = {}
880
- entry[:url] = h[:url] if h[:url]
881
- entry[:display] = h[:display] if h[:display]
882
- entry[:tooltip] = h[:tooltip] if h[:tooltip]
883
- entry[:location] = h[:location] if h[:location]
884
- hl_hash[ref] = entry unless entry.empty?
2107
+ if h.is_a?(Elements::Hyperlink)
2108
+ ref_val = if h.respond_to?(:cell)
2109
+ h.cell
2110
+ elsif h.respond_to?(:ref)
2111
+ h.ref
2112
+ end
2113
+ ref = ref_val.to_s.upcase
2114
+ hl_hash[ref] = h unless ref.empty?
2115
+ else
2116
+ ref = (h[:cell] || h[:ref]).to_s.upcase
2117
+ entry = {}
2118
+ entry[:url] = h[:url] if h[:url]
2119
+ entry[:display] = h[:display] if h[:display]
2120
+ entry[:tooltip] = h[:tooltip] if h[:tooltip]
2121
+ entry[:location] = h[:location] if h[:location]
2122
+ hl_hash[ref] = Elements::Hyperlink.new(**entry) unless entry.empty?
2123
+ end
885
2124
  end
886
2125
 
887
2126
  cm_hash = {}
888
2127
  @comments.each do |c|
889
- ref = (c[:ref] || c[:cell]).to_s.upcase
890
- cm_hash[ref] = c
2128
+ obj = c.is_a?(Elements::Comment) ? c : Elements::Comment.new(**c)
2129
+ ref = obj.ref.to_s.upcase
2130
+ cm_hash[ref] = obj
891
2131
  end
892
2132
 
893
- rows = if hl_hash.empty? && cm_hash.empty?
2133
+ tc_hash = {}
2134
+ @threaded_comments.each do |c|
2135
+ obj = c.is_a?(Elements::ThreadedComment) ? c : Elements::ThreadedComment.new(**c)
2136
+ ref = obj.ref.to_s.upcase
2137
+ (tc_hash[ref] ||= []) << obj
2138
+ end
2139
+
2140
+ rows = if hl_hash.empty? && cm_hash.empty? && tc_hash.empty?
894
2141
  @rows
895
2142
  else
896
2143
  @rows.map do |row|
897
2144
  new_cells = row.cells.map do |cell|
898
2145
  hl = hl_hash[cell.ref]
899
2146
  cm = cm_hash[cell.ref]
900
- if hl || cm
901
- cell.with(hyperlink: hl || cell.hyperlink, comment: cm || cell.comment)
2147
+ tcs = tc_hash[cell.ref]
2148
+ if hl || cm || tcs
2149
+ cell.with(
2150
+ hyperlink: hl || cell.hyperlink,
2151
+ comment: cm || cell.comment,
2152
+ threaded_comments: (tcs ? (cell.threaded_comments + tcs) : cell.threaded_comments)
2153
+ )
902
2154
  else
903
2155
  cell
904
2156
  end
@@ -909,12 +2161,13 @@ module Xlsxrb
909
2161
 
910
2162
  Elements::Worksheet.new(
911
2163
  name: @name, rows: rows, columns: @columns, charts: @charts,
912
- conditional_formatting: @conditional_formats,
2164
+ conditional_formats: @conditional_formats,
913
2165
  data_validations: @data_validations,
914
2166
  unmapped_data: facade_meta.empty? ? {} : { facade: facade_meta },
915
2167
  state: @state,
916
2168
  hyperlinks: hl_hash,
917
2169
  comments: @comments,
2170
+ threaded_comments: @threaded_comments,
918
2171
  print_area: @print_area,
919
2172
  print_titles: @print_titles,
920
2173
  sparkline_groups: @sparkline_groups,
@@ -932,10 +2185,14 @@ module Xlsxrb
932
2185
  sheet_properties: @sheet_properties,
933
2186
  sheet_format: @sheet_format,
934
2187
  row_breaks: @row_breaks,
935
- col_breaks: @col_breaks,
2188
+ column_breaks: @col_breaks,
936
2189
  protected_ranges: @protected_ranges,
937
2190
  cell_watches: @cell_watches,
938
- selection: @selection
2191
+ ignored_errors: @ignored_errors,
2192
+ phonetic_properties: @phonetic_properties,
2193
+ selection: @selection,
2194
+ sheet_calc_properties: @sheet_calc_pr,
2195
+ background_image: @background_image
939
2196
  )
940
2197
  end
941
2198
 
@@ -949,6 +2206,8 @@ module Xlsxrb
949
2206
  #
950
2207
  # @api public
951
2208
  class TableBuilder
2209
+ OMITTED = Object.new.freeze
2210
+ private_constant :OMITTED
952
2211
  # @param ref [String, nil] Table range (e.g. "A1:D10").
953
2212
  # @param columns [Array, nil] Column header names or definition hashes.
954
2213
  # @param name [String, nil] Table name identifier.
@@ -965,16 +2224,21 @@ module Xlsxrb
965
2224
  @options[:style] = style if style
966
2225
  end
967
2226
 
2227
+ # @deprecated Use explicit getter methods instead.
968
2228
  #: (untyped key) -> untyped
969
2229
  def [](key)
2230
+ warn "[Xlsxrb DEPRECATION] TableBuilder#[] is deprecated and will be removed in v0.2.0. Use explicit getter methods instead.", uplevel: 1
970
2231
  @options[key.to_sym]
971
2232
  end
972
2233
 
2234
+ # @deprecated Use explicit setter methods instead.
973
2235
  #: (untyped key, untyped value) -> untyped
974
2236
  def []=(key, value)
2237
+ warn "[Xlsxrb DEPRECATION] TableBuilder#[]= is deprecated and will be removed in v0.2.0. Use explicit setter methods instead.", uplevel: 1
975
2238
  @options[key.to_sym] = value
976
2239
  end
977
2240
 
2241
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#ref=} instead.
978
2242
  #: (?String? val) -> String?
979
2243
  def ref(val = nil)
980
2244
  if val
@@ -989,6 +2253,7 @@ module Xlsxrb
989
2253
  @options[:ref] = val.to_s
990
2254
  end
991
2255
 
2256
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#columns=} instead.
992
2257
  #: (*untyped cols) -> untyped
993
2258
  def columns(*cols)
994
2259
  if cols.empty?
@@ -1007,14 +2272,36 @@ module Xlsxrb
1007
2272
 
1008
2273
  # Appends a single column name or column definition.
1009
2274
  #
1010
- # @param col [String, Hash] Column header name or definition.
2275
+ # @param col [String, Hash, Symbol] Column header name or definition.
2276
+ # @param opts [Hash] Column options (e.g. totals_row_function, totals_row_label, formula, totals_row_formula).
1011
2277
  # @return [void]
1012
- #: (String | Hash[Symbol, untyped] col) -> void
1013
- def column(col)
1014
- (@options[:columns] ||= []) << col
2278
+ #: (String | Symbol | Hash[Symbol, untyped] col, **untyped opts) -> void
2279
+ def column(col, **opts)
2280
+ col_spec = if opts.empty?
2281
+ col
2282
+ elsif col.is_a?(Hash)
2283
+ col.merge(opts)
2284
+ else
2285
+ opts.merge(name: col.to_s)
2286
+ end
2287
+ (@options[:columns] ||= []) << col_spec
2288
+ nil
1015
2289
  end
2290
+ # @deprecated Use {#column} instead. Will be removed in 0.2.0.
1016
2291
  alias add_column column
1017
2292
 
2293
+ # Appends a calculated column with formula and options.
2294
+ #
2295
+ # @param name [String, Symbol] The column name.
2296
+ # @param formula [String] The formula for the calculated column (e.g. "[@Qty]*[@Price]").
2297
+ # @param opts [Hash] Additional column options.
2298
+ # @return [void]
2299
+ #: (String | Symbol name, String formula, **untyped opts) -> void
2300
+ def calculated_column(name, formula, **opts)
2301
+ column(name, formula: formula, **opts)
2302
+ end
2303
+
2304
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#name=} instead.
1018
2305
  #: (?String? val) -> String?
1019
2306
  def name(val = nil)
1020
2307
  if val
@@ -1029,6 +2316,7 @@ module Xlsxrb
1029
2316
  @options[:name] = val.to_s
1030
2317
  end
1031
2318
 
2319
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#display_name=} instead.
1032
2320
  #: (?String? val) -> String?
1033
2321
  def display_name(val = nil)
1034
2322
  if val
@@ -1043,6 +2331,7 @@ module Xlsxrb
1043
2331
  @options[:display_name] = val.to_s
1044
2332
  end
1045
2333
 
2334
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#style=} instead.
1046
2335
  #: (?String? val) -> String?
1047
2336
  def style(val = nil)
1048
2337
  if val
@@ -1057,6 +2346,7 @@ module Xlsxrb
1057
2346
  @options[:style] = val.to_s
1058
2347
  end
1059
2348
 
2349
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_row_stripes=} instead.
1060
2350
  #: (?bool? val) -> bool?
1061
2351
  def show_row_stripes(val = nil)
1062
2352
  if val.nil?
@@ -1071,6 +2361,7 @@ module Xlsxrb
1071
2361
  @options[:show_row_stripes] = val ? true : false
1072
2362
  end
1073
2363
 
2364
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_column_stripes=} instead.
1074
2365
  #: (?bool? val) -> bool?
1075
2366
  def show_column_stripes(val = nil)
1076
2367
  if val.nil?
@@ -1085,6 +2376,7 @@ module Xlsxrb
1085
2376
  @options[:show_column_stripes] = val ? true : false
1086
2377
  end
1087
2378
 
2379
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_first_column=} instead.
1088
2380
  #: (?bool? val) -> bool?
1089
2381
  def show_first_column(val = nil)
1090
2382
  if val.nil?
@@ -1099,6 +2391,7 @@ module Xlsxrb
1099
2391
  @options[:show_first_column] = val ? true : false
1100
2392
  end
1101
2393
 
2394
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_last_column=} instead.
1102
2395
  #: (?bool? val) -> bool?
1103
2396
  def show_last_column(val = nil)
1104
2397
  if val.nil?
@@ -1113,18 +2406,82 @@ module Xlsxrb
1113
2406
  @options[:show_last_column] = val ? true : false
1114
2407
  end
1115
2408
 
2409
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#totals_row_count=} instead.
1116
2410
  #: (?Integer? val) -> Integer?
1117
- def total_row_count(val = nil)
2411
+ def totals_row_count(val = nil)
1118
2412
  if val.nil?
1119
- @options[:total_row_count]
2413
+ @options[:totals_row_count] || @options[:total_row_count]
1120
2414
  else
1121
- @options[:total_row_count] = val.to_i
2415
+ @options[:totals_row_count] = val.to_i
1122
2416
  end
1123
2417
  end
1124
2418
 
2419
+ #: (Integer val) -> Integer
2420
+ def totals_row_count=(val)
2421
+ @options[:totals_row_count] = val.to_i
2422
+ end
2423
+
2424
+ # @deprecated Use {#totals_row_count} instead. Will be removed in 0.2.0.
2425
+ #: (?Integer? val) -> Integer?
2426
+ def total_row_count(val = nil)
2427
+ warn "[DEPRECATION] #total_row_count is deprecated; use #totals_row_count instead.", uplevel: 1
2428
+ totals_row_count(val)
2429
+ end
2430
+
2431
+ # @deprecated Use {#totals_row_count=} instead. Will be removed in 0.2.0.
1125
2432
  #: (Integer val) -> Integer
1126
2433
  def total_row_count=(val)
1127
- @options[:total_row_count] = val.to_i
2434
+ warn "[DEPRECATION] #total_row_count= is deprecated; use #totals_row_count= instead.", uplevel: 1
2435
+ self.totals_row_count = val
2436
+ end
2437
+
2438
+ # Gets or sets whether the table has a totals row.
2439
+ #
2440
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#totals_row=} instead.
2441
+ #: (?untyped val) -> bool?
2442
+ def totals_row(val = OMITTED)
2443
+ if val.equal?(OMITTED)
2444
+ rc = @options[:totals_row_count] || @options[:total_row_count]
2445
+ rc ? rc.positive? : @options[:totals_row]
2446
+ else
2447
+ @options[:totals_row_count] = val ? 1 : 0
2448
+ val ? true : false
2449
+ end
2450
+ end
2451
+
2452
+ #: (bool val) -> bool
2453
+ def totals_row=(val)
2454
+ @options[:totals_row_count] = val ? 1 : 0
2455
+ val
2456
+ end
2457
+
2458
+ # @deprecated Use {#totals_row} instead. Will be removed in 0.2.0.
2459
+ #: (?bool? val) -> bool?
2460
+ def total_row(val = OMITTED)
2461
+ warn "[DEPRECATION] #total_row is deprecated; use #totals_row instead.", uplevel: 1
2462
+ totals_row(val)
2463
+ end
2464
+
2465
+ # @deprecated Use {#totals_row=} instead. Will be removed in 0.2.0.
2466
+ #: (bool val) -> bool
2467
+ def total_row=(val)
2468
+ warn "[DEPRECATION] #total_row= is deprecated; use #totals_row= instead.", uplevel: 1
2469
+ self.totals_row = val
2470
+ end
2471
+
2472
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#auto_filter=} instead.
2473
+ #: (?bool? val) -> bool?
2474
+ def auto_filter(val = nil)
2475
+ if val.nil?
2476
+ @options[:auto_filter]
2477
+ else
2478
+ @options[:auto_filter] = val ? true : false
2479
+ end
2480
+ end
2481
+
2482
+ #: (bool val) -> bool
2483
+ def auto_filter=(val)
2484
+ @options[:auto_filter] = val ? true : false
1128
2485
  end
1129
2486
 
1130
2487
  #: () -> Hash[Symbol, untyped]
@@ -1145,16 +2502,28 @@ module Xlsxrb
1145
2502
  @options[:sqref] = sqref if sqref
1146
2503
  end
1147
2504
 
2505
+ # @deprecated Use dedicated property accessors instead. Will be removed in 0.2.0.
2506
+ # @param key [Symbol, String]
2507
+ # @return [Object, nil]
2508
+ # @api public
1148
2509
  #: (untyped key) -> untyped
1149
2510
  def [](key)
2511
+ warn "[Xlsxrb DEPRECATION] DataValidationBuilder#[] is deprecated; use dedicated property accessors instead.", uplevel: 1
1150
2512
  @options[key.to_sym]
1151
2513
  end
1152
2514
 
2515
+ # @deprecated Use dedicated property accessors instead. Will be removed in 0.2.0.
2516
+ # @param key [Symbol, String]
2517
+ # @param value [Object]
2518
+ # @return [Object]
2519
+ # @api public
1153
2520
  #: (untyped key, untyped value) -> untyped
1154
2521
  def []=(key, value)
2522
+ warn "[Xlsxrb DEPRECATION] DataValidationBuilder#[]= is deprecated; use dedicated property accessors instead.", uplevel: 1
1155
2523
  @options[key.to_sym] = value
1156
2524
  end
1157
2525
 
2526
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sqref=} instead.
1158
2527
  #: (?String? val) -> String?
1159
2528
  def sqref(val = nil)
1160
2529
  if val
@@ -1168,9 +2537,103 @@ module Xlsxrb
1168
2537
  def sqref=(val)
1169
2538
  @options[:sqref] = val.to_s
1170
2539
  end
2540
+ # @deprecated Use {#sqref} instead. Will be removed in 0.2.0.
1171
2541
  alias range sqref
2542
+ # @deprecated Use {#sqref=} instead. Will be removed in 0.2.0.
1172
2543
  alias range= sqref=
1173
2544
 
2545
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#columns=} instead.
2546
+ #: (?untyped val) -> untyped
2547
+ def columns(val = nil)
2548
+ if val
2549
+ @options[:columns] = val
2550
+ else
2551
+ @options[:columns]
2552
+ end
2553
+ end
2554
+
2555
+ #: (untyped val) -> untyped
2556
+ def columns=(val)
2557
+ @options[:columns] = val
2558
+ end
2559
+ # @deprecated Use {#columns} instead. Will be removed in 0.2.0.
2560
+ alias col columns
2561
+ # @deprecated Use {#columns=} instead. Will be removed in 0.2.0.
2562
+ alias col= columns=
2563
+
2564
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#rows=} instead.
2565
+ #: (?untyped val) -> untyped
2566
+ def rows(val = nil)
2567
+ if val
2568
+ @options[:rows] = val
2569
+ else
2570
+ @options[:rows]
2571
+ end
2572
+ end
2573
+
2574
+ #: (untyped val) -> untyped
2575
+ def rows=(val)
2576
+ @options[:rows] = val
2577
+ end
2578
+ # @deprecated Use {#rows} instead. Will be removed in 0.2.0.
2579
+ alias row rows
2580
+ # @deprecated Use {#rows=} instead. Will be removed in 0.2.0.
2581
+ alias row= rows=
2582
+
2583
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#except_rows=} instead.
2584
+ #: (?untyped val) -> untyped
2585
+ def except_rows(val = nil)
2586
+ if val
2587
+ @options[:except_rows] = val
2588
+ else
2589
+ @options[:except_rows]
2590
+ end
2591
+ end
2592
+
2593
+ #: (untyped val) -> untyped
2594
+ def except_rows=(val)
2595
+ @options[:except_rows] = val
2596
+ end
2597
+
2598
+ # Sets or gets the list validation choices.
2599
+ #
2600
+ # @example
2601
+ # b.list = ["Option1", "Option2"]
2602
+ #
2603
+ # @param val [Array<Object>, nil]
2604
+ # @return [Array<Object>, nil]
2605
+ # @api public
2606
+ #: (?Array[untyped]? val) -> untyped
2607
+ def list(val = nil)
2608
+ if val
2609
+ @options[:list] = val
2610
+ @options[:in] = val
2611
+ else
2612
+ @options[:list] || @options[:in]
2613
+ end
2614
+ end
2615
+
2616
+ #: (Array[untyped] val) -> untyped
2617
+ def list=(val)
2618
+ @options[:list] = val
2619
+ @options[:in] = val
2620
+ end
2621
+
2622
+ # @deprecated Use {#list} instead.
2623
+ #: (?Array[untyped]? val) -> untyped
2624
+ def in(val = nil)
2625
+ warn "[DEPRECATION] `DataValidationBuilder#in` is deprecated; use `list` instead.", uplevel: 1
2626
+ list(val)
2627
+ end
2628
+
2629
+ # @deprecated Use {#list=} instead.
2630
+ #: (Array[untyped] val) -> untyped
2631
+ def in=(val)
2632
+ warn "[DEPRECATION] `DataValidationBuilder#in=` is deprecated; use `list=` instead.", uplevel: 1
2633
+ self.list = val
2634
+ end
2635
+
2636
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#type=} instead.
1174
2637
  #: (?untyped val) -> untyped
1175
2638
  def type(val = nil)
1176
2639
  if val
@@ -1185,6 +2648,7 @@ module Xlsxrb
1185
2648
  @options[:type] = val
1186
2649
  end
1187
2650
 
2651
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#operator=} instead.
1188
2652
  #: (?untyped val) -> untyped
1189
2653
  def operator(val = nil)
1190
2654
  if val
@@ -1199,6 +2663,7 @@ module Xlsxrb
1199
2663
  @options[:operator] = val
1200
2664
  end
1201
2665
 
2666
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#formula1=} instead.
1202
2667
  #: (?untyped val) -> untyped
1203
2668
  def formula1(val = nil)
1204
2669
  if val
@@ -1213,6 +2678,7 @@ module Xlsxrb
1213
2678
  @options[:formula1] = val
1214
2679
  end
1215
2680
 
2681
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#formula2=} instead.
1216
2682
  #: (?untyped val) -> untyped
1217
2683
  def formula2(val = nil)
1218
2684
  if val
@@ -1227,6 +2693,7 @@ module Xlsxrb
1227
2693
  @options[:formula2] = val
1228
2694
  end
1229
2695
 
2696
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#allow_blank=} instead.
1230
2697
  #: (?bool? val) -> bool?
1231
2698
  def allow_blank(val = nil)
1232
2699
  if val.nil?
@@ -1241,6 +2708,7 @@ module Xlsxrb
1241
2708
  @options[:allow_blank] = val ? true : false
1242
2709
  end
1243
2710
 
2711
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_input_message=} instead.
1244
2712
  #: (?bool? val) -> bool?
1245
2713
  def show_input_message(val = nil)
1246
2714
  if val.nil?
@@ -1255,6 +2723,7 @@ module Xlsxrb
1255
2723
  @options[:show_input_message] = val ? true : false
1256
2724
  end
1257
2725
 
2726
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_error_message=} instead.
1258
2727
  #: (?bool? val) -> bool?
1259
2728
  def show_error_message(val = nil)
1260
2729
  if val.nil?
@@ -1269,6 +2738,7 @@ module Xlsxrb
1269
2738
  @options[:show_error_message] = val ? true : false
1270
2739
  end
1271
2740
 
2741
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#error_title=} instead.
1272
2742
  #: (?String? val) -> String?
1273
2743
  def error_title(val = nil)
1274
2744
  if val
@@ -1283,6 +2753,7 @@ module Xlsxrb
1283
2753
  @options[:error_title] = val.to_s
1284
2754
  end
1285
2755
 
2756
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#error_message=} instead.
1286
2757
  #: (?String? val) -> String?
1287
2758
  def error_message(val = nil)
1288
2759
  if val
@@ -1296,9 +2767,12 @@ module Xlsxrb
1296
2767
  def error_message=(val)
1297
2768
  @options[:error] = val.to_s
1298
2769
  end
2770
+ # @deprecated Use {#error_message} instead. Will be removed in 0.2.0.
1299
2771
  alias error error_message
2772
+ # @deprecated Use {#error_message=} instead. Will be removed in 0.2.0.
1300
2773
  alias error= error_message=
1301
2774
 
2775
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#prompt_title=} instead.
1302
2776
  #: (?String? val) -> String?
1303
2777
  def prompt_title(val = nil)
1304
2778
  if val
@@ -1313,6 +2787,7 @@ module Xlsxrb
1313
2787
  @options[:prompt_title] = val.to_s
1314
2788
  end
1315
2789
 
2790
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#prompt_message=} instead.
1316
2791
  #: (?String? val) -> String?
1317
2792
  def prompt_message(val = nil)
1318
2793
  if val
@@ -1326,9 +2801,12 @@ module Xlsxrb
1326
2801
  def prompt_message=(val)
1327
2802
  @options[:prompt] = val.to_s
1328
2803
  end
2804
+ # @deprecated Use {#prompt_message} instead. Will be removed in 0.2.0.
1329
2805
  alias prompt prompt_message
2806
+ # @deprecated Use {#prompt_message=} instead. Will be removed in 0.2.0.
1330
2807
  alias prompt= prompt_message=
1331
2808
 
2809
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#error_style=} instead.
1332
2810
  #: (?untyped val) -> untyped
1333
2811
  def error_style(val = nil)
1334
2812
  if val
@@ -1348,4 +2826,596 @@ module Xlsxrb
1348
2826
  @options.dup
1349
2827
  end
1350
2828
  end
2829
+
2830
+ # Builder context for configuring conditional formatting rules in block form.
2831
+ #
2832
+ # @api public
2833
+ class ConditionalFormatBuilder
2834
+ # @param sqref [String, nil] Target cell or range reference.
2835
+ # @param opts [Hash] Additional conditional formatting properties.
2836
+ #: (?String? sqref, **untyped opts) -> void
2837
+ def initialize(sqref = nil, **opts)
2838
+ @options = opts.dup
2839
+ @options[:sqref] = sqref if sqref
2840
+ end
2841
+
2842
+ # @deprecated Use dedicated property accessors instead. Will be removed in 0.2.0.
2843
+ # @param key [Symbol, String]
2844
+ # @return [Object, nil]
2845
+ # @api public
2846
+ #: (untyped key) -> untyped
2847
+ def [](key)
2848
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#[] is deprecated; use dedicated property accessors instead.", uplevel: 1
2849
+ @options[key.to_sym]
2850
+ end
2851
+
2852
+ # @deprecated Use dedicated property accessors instead. Will be removed in 0.2.0.
2853
+ # @param key [Symbol, String]
2854
+ # @param value [Object]
2855
+ # @return [Object]
2856
+ # @api public
2857
+ #: (untyped key, untyped value) -> untyped
2858
+ def []=(key, value)
2859
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#[]= is deprecated; use dedicated property accessors instead.", uplevel: 1
2860
+ @options[key.to_sym] = value
2861
+ end
2862
+
2863
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sqref=} instead.
2864
+ #: (?String? val) -> String?
2865
+ def sqref(val = nil)
2866
+ if val
2867
+ @options[:sqref] = val.to_s
2868
+ else
2869
+ @options[:sqref]
2870
+ end
2871
+ end
2872
+
2873
+ #: (String val) -> String
2874
+ def sqref=(val)
2875
+ @options[:sqref] = val.to_s
2876
+ end
2877
+ # @deprecated Use {#sqref} instead. Will be removed in 0.2.0.
2878
+ alias range sqref
2879
+ # @deprecated Use {#sqref=} instead. Will be removed in 0.2.0.
2880
+ alias range= sqref=
2881
+
2882
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#columns=} instead.
2883
+ #: (?untyped val) -> untyped
2884
+ def columns(val = nil)
2885
+ if val
2886
+ @options[:columns] = val
2887
+ else
2888
+ @options[:columns]
2889
+ end
2890
+ end
2891
+
2892
+ #: (untyped val) -> untyped
2893
+ def columns=(val)
2894
+ @options[:columns] = val
2895
+ end
2896
+ # @deprecated Use {#columns} instead. Will be removed in 0.2.0.
2897
+ alias col columns
2898
+ # @deprecated Use {#columns=} instead. Will be removed in 0.2.0.
2899
+ alias col= columns=
2900
+
2901
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#rows=} instead.
2902
+ #: (?untyped val) -> untyped
2903
+ def rows(val = nil)
2904
+ if val
2905
+ @options[:rows] = val
2906
+ else
2907
+ @options[:rows]
2908
+ end
2909
+ end
2910
+
2911
+ #: (untyped val) -> untyped
2912
+ def rows=(val)
2913
+ @options[:rows] = val
2914
+ end
2915
+ # @deprecated Use {#rows} instead. Will be removed in 0.2.0.
2916
+ alias row rows
2917
+ # @deprecated Use {#rows=} instead. Will be removed in 0.2.0.
2918
+ alias row= rows=
2919
+
2920
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#except_rows=} instead.
2921
+ #: (?untyped val) -> untyped
2922
+ def except_rows(val = nil)
2923
+ if val
2924
+ @options[:except_rows] = val
2925
+ else
2926
+ @options[:except_rows]
2927
+ end
2928
+ end
2929
+
2930
+ #: (untyped val) -> untyped
2931
+ def except_rows=(val)
2932
+ @options[:except_rows] = val
2933
+ end
2934
+
2935
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#type=} instead.
2936
+ #: (?untyped val) -> untyped
2937
+ def type(val = nil)
2938
+ if val
2939
+ @options[:type] = val
2940
+ else
2941
+ @options[:type]
2942
+ end
2943
+ end
2944
+
2945
+ #: (untyped val) -> untyped
2946
+ def type=(val)
2947
+ @options[:type] = val
2948
+ end
2949
+
2950
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#operator=} instead.
2951
+ #: (?untyped val) -> untyped
2952
+ def operator(val = nil)
2953
+ if val
2954
+ @options[:operator] = val
2955
+ else
2956
+ @options[:operator]
2957
+ end
2958
+ end
2959
+
2960
+ #: (untyped val) -> untyped
2961
+ def operator=(val)
2962
+ @options[:operator] = val
2963
+ end
2964
+
2965
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#formula=} instead.
2966
+ #: (?untyped val) -> untyped
2967
+ def formula(val = nil)
2968
+ if val
2969
+ @options[:formula] = val
2970
+ else
2971
+ @options[:formula]
2972
+ end
2973
+ end
2974
+
2975
+ #: (untyped val) -> untyped
2976
+ def formula=(val)
2977
+ @options[:formula] = val
2978
+ end
2979
+
2980
+ # @deprecated Use {#formula} instead. Will be removed in 0.2.0.
2981
+ # @return [Object]
2982
+ # @api public
2983
+ #: (*untyped vals) -> untyped
2984
+ def formulas(*vals)
2985
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#formulas is deprecated; use #formula instead.", uplevel: 1
2986
+ if vals.empty?
2987
+ @options[:formulas]
2988
+ elsif vals.size == 1 && vals.first.is_a?(Array)
2989
+ @options[:formulas] = vals.first
2990
+ else
2991
+ @options[:formulas] = vals
2992
+ end
2993
+ end
2994
+
2995
+ # @deprecated Use {#formula=} instead. Will be removed in 0.2.0.
2996
+ # @param vals [Array, Object]
2997
+ # @return [Array]
2998
+ # @api public
2999
+ #: (untyped vals) -> untyped
3000
+ def formulas=(vals)
3001
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#formulas= is deprecated; use #formula= instead.", uplevel: 1
3002
+ @options[:formulas] = vals.is_a?(Array) ? vals : [vals]
3003
+ end
3004
+
3005
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#font=} instead.
3006
+ #: (?untyped val) -> untyped
3007
+ def font(val = nil)
3008
+ if val
3009
+ @options[:font] = val
3010
+ else
3011
+ @options[:font]
3012
+ end
3013
+ end
3014
+
3015
+ #: (untyped val) -> untyped
3016
+ def font=(val)
3017
+ @options[:font] = val
3018
+ end
3019
+
3020
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fill=} instead.
3021
+ #: (?untyped val) -> untyped
3022
+ def fill(val = nil)
3023
+ if val
3024
+ @options[:fill] = val
3025
+ else
3026
+ @options[:fill]
3027
+ end
3028
+ end
3029
+
3030
+ #: (untyped val) -> untyped
3031
+ def fill=(val)
3032
+ @options[:fill] = val
3033
+ end
3034
+
3035
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fill_color=} instead.
3036
+ #: (?untyped val) -> untyped
3037
+ def fill_color(val = nil)
3038
+ if val
3039
+ @options[:fill_color] = val
3040
+ else
3041
+ @options[:fill_color]
3042
+ end
3043
+ end
3044
+
3045
+ #: (untyped val) -> untyped
3046
+ def fill_color=(val)
3047
+ @options[:fill_color] = val
3048
+ end
3049
+
3050
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#font_color=} instead.
3051
+ #: (?untyped val) -> untyped
3052
+ def font_color(val = nil)
3053
+ if val
3054
+ @options[:font_color] = val
3055
+ else
3056
+ @options[:font_color]
3057
+ end
3058
+ end
3059
+
3060
+ #: (untyped val) -> untyped
3061
+ def font_color=(val)
3062
+ @options[:font_color] = val
3063
+ end
3064
+
3065
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#bold=} instead.
3066
+ #: (?bool? val) -> bool?
3067
+ def bold(val = nil)
3068
+ if val.nil?
3069
+ @options[:bold]
3070
+ else
3071
+ @options[:bold] = val ? true : false
3072
+ end
3073
+ end
3074
+
3075
+ #: (bool val) -> bool
3076
+ def bold=(val)
3077
+ @options[:bold] = val ? true : false
3078
+ end
3079
+
3080
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#italic=} instead.
3081
+ #: (?bool? val) -> bool?
3082
+ def italic(val = nil)
3083
+ if val.nil?
3084
+ @options[:italic]
3085
+ else
3086
+ @options[:italic] = val ? true : false
3087
+ end
3088
+ end
3089
+
3090
+ #: (bool val) -> bool
3091
+ def italic=(val)
3092
+ @options[:italic] = val ? true : false
3093
+ end
3094
+
3095
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#underline=} instead.
3096
+ #: (?untyped val) -> untyped
3097
+ def underline(val = nil)
3098
+ if val.nil?
3099
+ @options[:underline]
3100
+ else
3101
+ @options[:underline] = val
3102
+ end
3103
+ end
3104
+
3105
+ #: (untyped val) -> untyped
3106
+ def underline=(val)
3107
+ @options[:underline] = val
3108
+ end
3109
+
3110
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#font_name=} instead.
3111
+ #: (?String? val) -> String?
3112
+ def font_name(val = nil)
3113
+ if val
3114
+ @options[:font_name] = val.to_s
3115
+ else
3116
+ @options[:font_name]
3117
+ end
3118
+ end
3119
+
3120
+ #: (String val) -> String
3121
+ def font_name=(val)
3122
+ @options[:font_name] = val.to_s
3123
+ end
3124
+
3125
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#font_size=} instead.
3126
+ #: (?untyped val) -> untyped
3127
+ def font_size(val = nil)
3128
+ if val
3129
+ @options[:font_size] = val
3130
+ @options[:size] = val
3131
+ else
3132
+ @options[:font_size] || @options[:size]
3133
+ end
3134
+ end
3135
+
3136
+ #: (untyped val) -> untyped
3137
+ def font_size=(val)
3138
+ @options[:font_size] = val
3139
+ @options[:size] = val
3140
+ end
3141
+
3142
+ # @deprecated Use {#font_size} instead. Will be removed in 0.2.0.
3143
+ def size(val = nil)
3144
+ warn "[DEPRECATION] `size` is deprecated; use `font_size` instead.", uplevel: 1
3145
+ font_size(val)
3146
+ end
3147
+
3148
+ # @deprecated Use {#font_size=} instead. Will be removed in 0.2.0.
3149
+ def size=(val)
3150
+ warn "[DEPRECATION] `size=` is deprecated; use `font_size=` instead.", uplevel: 1
3151
+ self.font_size = val
3152
+ end
3153
+
3154
+ # @deprecated Use {#font_size} instead. Will be removed in 0.2.0.
3155
+ def sz(val = nil)
3156
+ warn "[DEPRECATION] `sz` is deprecated; use `font_size` instead.", uplevel: 1
3157
+ font_size(val)
3158
+ end
3159
+
3160
+ # @deprecated Use {#font_size=} instead. Will be removed in 0.2.0.
3161
+ def sz=(val)
3162
+ warn "[DEPRECATION] `sz=` is deprecated; use `font_size=` instead.", uplevel: 1
3163
+ self.font_size = val
3164
+ end
3165
+
3166
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#stop_if_true=} instead.
3167
+ #: (?bool? val) -> bool?
3168
+ def stop_if_true(val = nil)
3169
+ if val.nil?
3170
+ @options[:stop_if_true]
3171
+ else
3172
+ @options[:stop_if_true] = val ? true : false
3173
+ end
3174
+ end
3175
+
3176
+ #: (bool val) -> bool
3177
+ def stop_if_true=(val)
3178
+ @options[:stop_if_true] = val ? true : false
3179
+ end
3180
+
3181
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#priority=} instead.
3182
+ #: (?Integer? val) -> Integer?
3183
+ def priority(val = nil)
3184
+ if val
3185
+ @options[:priority] = val.to_i
3186
+ else
3187
+ @options[:priority]
3188
+ end
3189
+ end
3190
+
3191
+ #: (Integer val) -> Integer
3192
+ def priority=(val)
3193
+ @options[:priority] = val.to_i
3194
+ end
3195
+
3196
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#above_average=} instead.
3197
+ #: (?bool? val) -> bool?
3198
+ def above_average(val = nil)
3199
+ if val.nil?
3200
+ @options[:above_average]
3201
+ else
3202
+ @options[:above_average] = val ? true : false
3203
+ end
3204
+ end
3205
+
3206
+ #: (bool val) -> bool
3207
+ def above_average=(val)
3208
+ @options[:above_average] = val ? true : false
3209
+ end
3210
+
3211
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#equal_average=} instead.
3212
+ #: (?bool? val) -> bool?
3213
+ def equal_average(val = nil)
3214
+ if val.nil?
3215
+ @options[:equal_average]
3216
+ else
3217
+ @options[:equal_average] = val ? true : false
3218
+ end
3219
+ end
3220
+
3221
+ #: (bool val) -> bool
3222
+ def equal_average=(val)
3223
+ @options[:equal_average] = val ? true : false
3224
+ end
3225
+
3226
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#std_dev=} instead.
3227
+ #: (?Integer? val) -> Integer?
3228
+ def std_dev(val = nil)
3229
+ if val
3230
+ @options[:std_dev] = val.to_i
3231
+ else
3232
+ @options[:std_dev]
3233
+ end
3234
+ end
3235
+
3236
+ #: (Integer val) -> Integer
3237
+ def std_dev=(val)
3238
+ @options[:std_dev] = val.to_i
3239
+ end
3240
+
3241
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#rank=} instead.
3242
+ #: (?Integer? val) -> Integer?
3243
+ def rank(val = nil)
3244
+ if val
3245
+ @options[:rank] = val.to_i
3246
+ else
3247
+ @options[:rank]
3248
+ end
3249
+ end
3250
+
3251
+ #: (Integer val) -> Integer
3252
+ def rank=(val)
3253
+ @options[:rank] = val.to_i
3254
+ end
3255
+
3256
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#percent=} instead.
3257
+ #: (?bool? val) -> bool?
3258
+ def percent(val = nil)
3259
+ if val.nil?
3260
+ @options[:percent]
3261
+ else
3262
+ @options[:percent] = val ? true : false
3263
+ end
3264
+ end
3265
+
3266
+ #: (bool val) -> bool
3267
+ def percent=(val)
3268
+ @options[:percent] = val ? true : false
3269
+ end
3270
+
3271
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#bottom=} instead.
3272
+ #: (?bool? val) -> bool?
3273
+ def bottom(val = nil)
3274
+ if val.nil?
3275
+ @options[:bottom]
3276
+ else
3277
+ @options[:bottom] = val ? true : false
3278
+ end
3279
+ end
3280
+
3281
+ #: (bool val) -> bool
3282
+ def bottom=(val)
3283
+ @options[:bottom] = val ? true : false
3284
+ end
3285
+
3286
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#text=} instead.
3287
+ #: (?String? val) -> String?
3288
+ def text(val = nil)
3289
+ if val
3290
+ @options[:text] = val.to_s
3291
+ else
3292
+ @options[:text]
3293
+ end
3294
+ end
3295
+
3296
+ #: (String val) -> String
3297
+ def text=(val)
3298
+ @options[:text] = val.to_s
3299
+ end
3300
+
3301
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#time_period=} instead.
3302
+ #: (?untyped val) -> untyped
3303
+ def time_period(val = nil)
3304
+ if val
3305
+ @options[:time_period] = val
3306
+ else
3307
+ @options[:time_period]
3308
+ end
3309
+ end
3310
+
3311
+ #: (untyped val) -> untyped
3312
+ def time_period=(val)
3313
+ @options[:time_period] = val
3314
+ end
3315
+
3316
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#color_scale=} instead.
3317
+ #: (?untyped val) -> untyped
3318
+ def color_scale(val = nil)
3319
+ if val
3320
+ @options[:color_scale] = val
3321
+ else
3322
+ @options[:color_scale]
3323
+ end
3324
+ end
3325
+
3326
+ #: (untyped val) -> untyped
3327
+ def color_scale=(val)
3328
+ @options[:color_scale] = val
3329
+ end
3330
+
3331
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#data_bar=} instead.
3332
+ #: (?untyped val) -> untyped
3333
+ def data_bar(val = nil)
3334
+ if val
3335
+ @options[:data_bar] = val
3336
+ else
3337
+ @options[:data_bar]
3338
+ end
3339
+ end
3340
+
3341
+ #: (untyped val) -> untyped
3342
+ def data_bar=(val)
3343
+ @options[:data_bar] = val
3344
+ end
3345
+
3346
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#icon_set=} instead.
3347
+ #: (?untyped val) -> untyped
3348
+ def icon_set(val = nil)
3349
+ if val
3350
+ @options[:icon_set] = val
3351
+ else
3352
+ @options[:icon_set]
3353
+ end
3354
+ end
3355
+
3356
+ #: (untyped val) -> untyped
3357
+ def icon_set=(val)
3358
+ @options[:icon_set] = val
3359
+ end
3360
+
3361
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#dxf=} instead.
3362
+ #: (?untyped val) -> untyped
3363
+ def dxf(val = nil)
3364
+ if val
3365
+ @options[:dxf] = val
3366
+ else
3367
+ @options[:dxf]
3368
+ end
3369
+ end
3370
+
3371
+ #: (untyped val) -> untyped
3372
+ def dxf=(val)
3373
+ @options[:dxf] = val
3374
+ end
3375
+
3376
+ # Gets or sets the differential format identifier (dxfId).
3377
+ #
3378
+ # @param val [Integer, nil]
3379
+ # @return [Integer, nil]
3380
+ # @api public
3381
+ #: (?Integer? val) -> Integer?
3382
+ def dxf_id(val = nil)
3383
+ if val
3384
+ @options[:dxf_id] = val.to_i
3385
+ @options[:format_id] = val.to_i
3386
+ else
3387
+ @options[:dxf_id] || @options[:format_id]
3388
+ end
3389
+ end
3390
+
3391
+ # Sets the differential format identifier (dxfId).
3392
+ #
3393
+ # @param val [Integer]
3394
+ # @return [Integer]
3395
+ # @api public
3396
+ #: (Integer val) -> Integer
3397
+ def dxf_id=(val)
3398
+ @options[:dxf_id] = val.to_i
3399
+ @options[:format_id] = val.to_i
3400
+ end
3401
+
3402
+ # @deprecated Use {#dxf_id} instead. Will be removed in 0.2.0.
3403
+ #: (?Integer? val) -> Integer?
3404
+ def format_id(val = nil)
3405
+ warn "[DEPRECATION] `format_id` is deprecated; use `dxf_id` instead.", uplevel: 1
3406
+ dxf_id(val)
3407
+ end
3408
+
3409
+ # @deprecated Use {#dxf_id=} instead. Will be removed in 0.2.0.
3410
+ #: (Integer val) -> Integer
3411
+ def format_id=(val)
3412
+ warn "[DEPRECATION] `format_id=` is deprecated; use `dxf_id=` instead.", uplevel: 1
3413
+ self.dxf_id = val
3414
+ end
3415
+
3416
+ #: () -> Hash[Symbol, untyped]
3417
+ def to_h
3418
+ @options.dup
3419
+ end
3420
+ end
1351
3421
  end