xlsxrb 0.1.17 → 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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +93 -1
  3. data/README.md +79 -19
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +595 -113
  6. data/lib/xlsxrb/dsl_helpers.rb +72 -20
  7. data/lib/xlsxrb/elements/cell.rb +243 -56
  8. data/lib/xlsxrb/elements/column.rb +94 -5
  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 +242 -7
  15. data/lib/xlsxrb/elements/workbook.rb +171 -82
  16. data/lib/xlsxrb/elements/worksheet.rb +598 -102
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +12 -4
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -2
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +264 -17
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
  22. data/lib/xlsxrb/ooxml/reader.rb +4 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +10 -3
  24. data/lib/xlsxrb/ooxml/workbook_writer.rb +90 -36
  25. data/lib/xlsxrb/ooxml/worksheet_parser.rb +2 -2
  26. data/lib/xlsxrb/ooxml/worksheet_writer.rb +64 -19
  27. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +5 -2
  28. data/lib/xlsxrb/ooxml/writer/features_xml.rb +26 -5
  29. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +19 -9
  30. data/lib/xlsxrb/ooxml/writer.rb +22 -6
  31. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  32. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  33. data/lib/xlsxrb/stream_row.rb +97 -18
  34. data/lib/xlsxrb/stream_sheet.rb +706 -190
  35. data/lib/xlsxrb/stream_writer.rb +1893 -374
  36. data/lib/xlsxrb/style_builder.rb +774 -111
  37. data/lib/xlsxrb/utils.rb +66 -106
  38. data/lib/xlsxrb/version.rb +1 -1
  39. data/lib/xlsxrb/workbook_builder.rb +380 -83
  40. data/lib/xlsxrb/worksheet_builder.rb +1210 -233
  41. data/lib/xlsxrb.rb +1266 -326
  42. data/sig/generated/xlsxrb/chart_builder.rbs +319 -90
  43. data/sig/generated/xlsxrb/dsl_helpers.rbs +20 -2
  44. data/sig/generated/xlsxrb/elements/cell.rbs +92 -20
  45. data/sig/generated/xlsxrb/elements/column.rbs +61 -2
  46. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  47. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  48. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  49. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  50. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  51. data/sig/generated/xlsxrb/elements/types.rbs +27 -0
  52. data/sig/generated/xlsxrb/elements/workbook.rbs +63 -52
  53. data/sig/generated/xlsxrb/elements/worksheet.rbs +192 -51
  54. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -0
  55. data/sig/generated/xlsxrb/ooxml/reader.rbs +3 -0
  56. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
  57. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +1 -1
  58. data/sig/generated/xlsxrb/ooxml/writer.rbs +3 -0
  59. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  60. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  61. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  62. data/sig/generated/xlsxrb/stream_sheet.rbs +324 -115
  63. data/sig/generated/xlsxrb/stream_writer.rbs +1068 -255
  64. data/sig/generated/xlsxrb/style_builder.rbs +389 -79
  65. data/sig/generated/xlsxrb/utils.rbs +34 -18
  66. data/sig/generated/xlsxrb/workbook_builder.rbs +234 -34
  67. data/sig/generated/xlsxrb/worksheet_builder.rbs +628 -126
  68. data/sig/generated/xlsxrb.rbs +257 -49
  69. metadata +3 -1
@@ -9,14 +9,18 @@ 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
20
24
  @next_row_index = 0
21
25
  @rows = []
22
26
  @columns = []
@@ -64,7 +68,24 @@ module Xlsxrb
64
68
  @pending_row_attributes = {}
65
69
  end
66
70
 
67
- attr_reader :name, :defined_names
71
+ #: String
72
+ attr_reader :name
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
68
89
 
69
90
  # Defines or configures a named cell style.
70
91
  #
@@ -87,27 +108,73 @@ module Xlsxrb
87
108
  style_builder
88
109
  end
89
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
+
90
146
  # Appends a row of cells to the worksheet.
91
147
  #
92
148
  # @example Add a row with values and array styles
93
- # sheet.row(["ID", "Name", "Total"], styles: [:header, :header, :header])
149
+ # sheet.row(["ID", "Name", "Total"], cell_styles: [:header, :header, :header])
94
150
  #
95
151
  # @example Add a row with a hash of column keys
96
152
  # sheet.row({ "A" => "Invoice", "C" => 12345 })
97
153
  #
98
154
  # @param values [Array<Object>, Hash{String, Integer => Object}] The cell values.
99
- # @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.
100
157
  # @param height [Float, Integer, nil] The row height in points (0 to 409).
101
158
  # @param hidden [Boolean] Whether the row is hidden.
102
159
  # @param custom_height [Boolean] Whether custom row height is enforced.
103
160
  # @param outline_level [Integer, nil] Grouping/outline hierarchy level.
104
161
  # @param collapsed [Boolean] Whether the row is collapsed.
105
- # @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.
106
164
  # @return [void]
107
165
  # @raise [ArgumentError] If limits are exceeded when strict_excel_mode is enabled.
108
166
  # @api public
109
- #: (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
110
- def row(values, styles: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil, style: nil)
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
+
111
178
  row_index = @next_row_index
112
179
  DslHelpers.validate_row_bounds!(row_index, height, strict_excel_mode: @strict_excel_mode)
113
180
  @next_row_index += 1
@@ -119,32 +186,32 @@ module Xlsxrb
119
186
  height ||= pending[:height]
120
187
 
121
188
  values = DslHelpers.normalize_row_values(values)
122
- styles = DslHelpers.normalize_row_styles(styles)
189
+ cell_styles = DslHelpers.normalize_row_styles(cell_styles)
123
190
 
124
191
  # Auto-detect Date / Time for built-in styles
125
192
  values.each_with_index do |val, idx|
126
- cell_style = styles.is_a?(Array) ? styles[idx] : styles
193
+ cell_style = cell_styles.is_a?(Array) ? cell_styles[idx] : cell_styles
127
194
 
128
195
  if val.is_a?(Date) && cell_style.nil?
129
- style("__xlsxrb_date", number_format: "yyyy-mm-dd") unless @styles.key?("__xlsxrb_date")
130
- styles = [] if styles.nil?
131
- styles = Array.new(values.size, styles) unless styles.is_a?(Array)
132
- 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"
133
200
  elsif val.is_a?(Time) && cell_style.nil?
134
- style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss") unless @styles.key?("__xlsxrb_time")
135
- styles = [] if styles.nil?
136
- styles = Array.new(values.size, styles) unless styles.is_a?(Array)
137
- 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"
138
205
  end
139
206
  end
140
207
 
141
208
  max_len = values.size
142
- 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)
143
210
  # See: https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
144
211
  raise ArgumentError, "Row contains #{max_len} columns, exceeding Excel limit of 16_384 columns" if @strict_excel_mode && max_len > 16_384
145
212
 
146
213
  cells = Array.new(max_len)
147
- style_lookup = styles.is_a?(Array)
214
+ style_lookup = cell_styles.is_a?(Array)
148
215
 
149
216
  col_index = 0
150
217
  while col_index < max_len
@@ -164,14 +231,14 @@ module Xlsxrb
164
231
  end
165
232
 
166
233
  style_name = if style_lookup
167
- col_index < styles.size ? styles[col_index] : nil
234
+ col_index < cell_styles.size ? cell_styles[col_index] : nil
168
235
  else
169
- styles
236
+ cell_styles
170
237
  end
171
238
 
172
239
  if style_name.is_a?(Hash)
173
240
  inline_name = "__inline_#{style_name.hash}"
174
- style(inline_name, **style_name) unless @styles.key?(inline_name)
241
+ self.style(inline_name, **style_name) unless @styles.key?(inline_name)
175
242
  style_name = inline_name
176
243
  end
177
244
  if val.nil? && style_name.nil?
@@ -179,8 +246,8 @@ module Xlsxrb
179
246
  next
180
247
  end
181
248
  sb = @styles[style_name]
182
- fmt_code = if sb&.num_fmt_id
183
- 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]
184
251
  end
185
252
  # If value is a Formula object or Hash with :formula, store it as the cell's formula
186
253
  cells[col_index] = if val.is_a?(Elements::Formula)
@@ -189,7 +256,7 @@ module Xlsxrb
189
256
  column_index: col_index,
190
257
  value: val.cached_value,
191
258
  formula: val,
192
- style_index: style_name,
259
+ style: style_name,
193
260
  raw_value: val.cached_value&.to_s,
194
261
  format_code: fmt_code
195
262
  )
@@ -210,7 +277,7 @@ module Xlsxrb
210
277
  column_index: col_index,
211
278
  value: cached_val,
212
279
  formula: f_obj,
213
- style_index: style_name,
280
+ style: style_name,
214
281
  raw_value: cached_val&.to_s,
215
282
  format_code: fmt_code
216
283
  )
@@ -219,7 +286,7 @@ module Xlsxrb
219
286
  row_index: row_index,
220
287
  column_index: col_index,
221
288
  value: val,
222
- style_index: style_name,
289
+ style: style_name,
223
290
  raw_value: val&.to_s,
224
291
  format_code: fmt_code
225
292
  )
@@ -228,7 +295,7 @@ module Xlsxrb
228
295
  end
229
296
 
230
297
  cells.compact!
231
- unmapped = style ? { style_index: style } : {}
298
+ unmapped = row_style ? { style_index: row_style } : {}
232
299
  @rows << Elements::Row.new(
233
300
  index: row_index,
234
301
  cells: cells,
@@ -237,9 +304,11 @@ module Xlsxrb
237
304
  custom_height: custom_height || !height.nil?,
238
305
  collapsed: collapsed,
239
306
  outline_level: outline_level,
307
+ style_index: row_style,
240
308
  unmapped_data: unmapped
241
309
  )
242
310
  end
311
+ # @deprecated Use {#row} instead. Will be removed in 0.2.0 (available via xlsxrb-adapters).
243
312
  alias add_row row
244
313
 
245
314
  # Appends a row to the worksheet and returns self for chaining.
@@ -273,6 +342,7 @@ module Xlsxrb
273
342
 
274
343
  @next_row_index += count
275
344
  end
345
+ # @deprecated Use {#skip_rows} instead. Will be removed in 0.2.0.
276
346
  alias skip_row skip_rows
277
347
 
278
348
  # Sets column formatting and properties for one or multiple columns.
@@ -290,8 +360,8 @@ module Xlsxrb
290
360
  # @return [void]
291
361
  # @raise [ArgumentError] If width exceeds 255 in strict mode.
292
362
  # @api public
293
- #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
294
- def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, collapsed: false, 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)
295
365
  raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
296
366
 
297
367
  DslHelpers.normalize_column_indices(index).each do |idx|
@@ -306,6 +376,7 @@ module Xlsxrb
306
376
  unmapped = prev.unmapped_data ? prev.unmapped_data.dup : {}
307
377
  unmapped[:style_index] = new_style if new_style
308
378
  unmapped[:collapsed] = true if collapsed || prev.unmapped_data&.[](:collapsed)
379
+ unmapped[:best_fit] = true if best_fit || prev.unmapped_data&.[](:best_fit)
309
380
  @columns[existing_idx] = Elements::Column.new(
310
381
  index: idx,
311
382
  width: new_width,
@@ -318,6 +389,7 @@ module Xlsxrb
318
389
  else
319
390
  unmapped = style ? { style_index: style } : {}
320
391
  unmapped[:collapsed] = true if collapsed
392
+ unmapped[:best_fit] = true if best_fit
321
393
  @columns << Elements::Column.new(
322
394
  index: idx,
323
395
  width: width,
@@ -330,6 +402,16 @@ module Xlsxrb
330
402
  end
331
403
  end
332
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) }
333
415
  end
334
416
 
335
417
  # Groups multiple columns together with outline hierarchy.
@@ -352,8 +434,11 @@ module Xlsxrb
352
434
  def group_columns(index, level: 1, collapsed: false, hidden: false, width: nil, style: nil)
353
435
  column(index, outline_level: level, collapsed: collapsed, hidden: hidden, width: width, style: style)
354
436
  end
437
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
355
438
  alias group_column group_columns
439
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
356
440
  alias group_cols group_columns
441
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
357
442
  alias group_col group_columns
358
443
 
359
444
  # Groups multiple rows with outline hierarchy, either by range or with a block.
@@ -408,6 +493,7 @@ module Xlsxrb
408
493
  custom_height: existing_row.custom_height,
409
494
  collapsed: collapsed || existing_row.collapsed,
410
495
  outline_level: level,
496
+ style_index: existing_row.style_index,
411
497
  unmapped_data: existing_row.unmapped_data
412
498
  )
413
499
  else
@@ -416,6 +502,7 @@ module Xlsxrb
416
502
  end
417
503
  end
418
504
  end
505
+ # @deprecated Use {#group_rows} instead. Will be removed in 0.2.0.
419
506
  alias group_row group_rows
420
507
 
421
508
  # Configures worksheet-level outline and grouping view properties.
@@ -426,13 +513,16 @@ module Xlsxrb
426
513
  # @param summary_below [Boolean, nil] Flag indicating if summary rows appear below detail rows.
427
514
  # @param summary_right [Boolean, nil] Flag indicating if summary columns appear to the right of detail columns.
428
515
  # @param show_outline_symbols [Boolean, nil] Flag indicating whether outline symbols are visible.
429
- # @param show_symbols [Boolean, nil] Alias for show_outline_symbols.
516
+ # @param show_symbols [Boolean, nil] Deprecated alias for show_outline_symbols.
430
517
  # @param apply_styles [Boolean, nil] Flag indicating whether automatic styles apply to outlines.
431
518
  # @param opts [Hash] Additional options.
432
- # @return [Hash]
519
+ # @return [Hash<Symbol, untyped>, void]
433
520
  # @api public
434
- #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> Hash[Symbol, untyped]
521
+ #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> (Hash[Symbol, untyped] | void)
435
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?
436
526
  props = (@sheet_properties[:outline_properties] || {}).dup
437
527
  props[:summary_below] = summary_below unless summary_below.nil?
438
528
  props[:summary_right] = summary_right unless summary_right.nil?
@@ -443,25 +533,43 @@ module Xlsxrb
443
533
  @sheet_properties[:outline_properties] = props
444
534
  @sheet_properties[:summary_below] = props[:summary_below] unless props[:summary_below].nil?
445
535
  @sheet_properties[:summary_right] = props[:summary_right] unless props[:summary_right].nil?
446
- props
536
+ nil
447
537
  end
538
+ # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
448
539
  alias outline_pr outline_properties
449
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=
553
+
450
554
  # Adds a chart to the worksheet.
451
555
  #
556
+ # @param type [Symbol, String, nil] Optional chart type (e.g. :bar, :line).
452
557
  # @param options [Hash] Chart configuration options.
453
558
  # @yield [builder]
454
559
  # @yieldparam builder [Xlsxrb::ChartBuilder]
455
560
  # @return [void]
456
561
  # @api public
457
- #: (**untyped options) ?{ (ChartBuilder) -> void } -> void
458
- 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
459
565
  if block_given?
460
566
  builder = ChartBuilder.new
567
+ builder.type(type) if type
461
568
  yield builder
462
569
  options = builder.options.merge(options)
463
570
  end
464
571
  @charts << options
572
+ nil
465
573
  end
466
574
 
467
575
  # Adds a hyperlink to a cell.
@@ -494,23 +602,37 @@ module Xlsxrb
494
602
 
495
603
  # Sets an auto-filter range on the sheet.
496
604
  #
497
- # @param range [String] The cell range (e.g. "A1:E100").
498
- # @return [String]
605
+ # @param range [String, nil] The cell range (e.g. "A1:E100").
606
+ # @return [void]
499
607
  # @api public
500
- #: (String range) -> String
608
+ #: (String? range) -> void
501
609
  def auto_filter(range)
502
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
503
623
  end
504
624
 
505
625
  # Configures filtering rules on a specific column of an auto-filter.
506
626
  #
507
- # @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).
508
628
  # @param filter [Hash] Filter criteria (e.g. values, custom filters).
509
- # @return [Hash]
629
+ # @return [void]
510
630
  # @api public
511
- #: (Integer col_id, Hash[untyped, untyped] filter) -> Hash[untyped, untyped]
631
+ #: (Integer | String | Symbol col_id, untyped filter) -> void
512
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)
513
634
  @filter_columns[col_id] = filter
635
+ nil
514
636
  end
515
637
 
516
638
  # Configures column sort state for the sheet.
@@ -518,26 +640,52 @@ module Xlsxrb
518
640
  # @param ref [String] The sorted range.
519
641
  # @param sort_conditions [Array<Hash>] List of sort condition definitions.
520
642
  # @param opts [Hash] Additional sort state options.
521
- # @return [Hash]
643
+ # @return [Elements::SortState, Hash<Symbol, untyped>, nil, void]
522
644
  # @api public
523
- #: (String ref, Array[Hash[untyped, untyped]] sort_conditions, **untyped opts) -> Hash[untyped, untyped]
524
- 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
+
525
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
526
667
  end
527
668
 
528
669
  # Adds a data validation rule to a cell, range, or coordinates.
529
670
  #
530
671
  # @param sqref [String, nil] Target cell or range reference (e.g. "B2:B100").
531
- # @param opts [Hash] Validation configuration (e.g. type: :list, formula1: '"Option1,Option2"', or coordinate options `columns:`, `rows:`, `except_rows:`, `in:`).
672
+ # @param opts [Hash] Validation configuration (e.g. type: :list, formula1: '"Option1,Option2"', or coordinate options `columns:`, `rows:`, `except_rows:`, `list:`, `in:`).
532
673
  # @yield [data_validation_builder] Optional configuration block.
533
674
  # @return [void]
534
675
  # @api public
535
676
  #: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
536
- def validate_data(sqref = nil, **opts, &)
677
+ def data_validation(sqref = nil, **opts, &)
537
678
  normalized_list = DslHelpers.normalize_data_validation(sqref, **opts, &)
538
679
  @data_validations.concat(normalized_list)
539
680
  end
540
681
 
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(...)
687
+ end
688
+
541
689
  # Adds a conditional formatting rule to a cell range.
542
690
  # Supports block configuration via {ConditionalFormatBuilder} and coordinate targeting (:columns, :rows).
543
691
  #
@@ -594,17 +742,27 @@ module Xlsxrb
594
742
  # @param name [String, nil] Pivot table name.
595
743
  # @param field_names [Array<String>, nil] Custom field display names.
596
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.
597
749
  # @return [void]
598
750
  # @api public
599
- #: (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
600
- 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"
601
757
  @pivot_tables ||= []
602
- @pivot_tables << {
758
+ entry = {
603
759
  source_ref: source_ref, row_fields: row_fields,
604
- data_fields: data_fields, col_fields: col_fields,
605
- 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,
606
763
  field_names: field_names, items: items
607
- }
764
+ }.merge(opts)
765
+ @pivot_tables << entry
608
766
  end
609
767
 
610
768
  # Adds a cell comment / note.
@@ -616,7 +774,9 @@ module Xlsxrb
616
774
  # @api public
617
775
  #: (String | Integer cell, String text, ?author: ::String) -> void
618
776
  def comment(cell, text, author: "Author")
619
- @comments << { cell: cell, text: text, author: author }
777
+ ref_str = cell.to_s
778
+ @comments << { ref: ref_str, text: text, author: author }
779
+ nil
620
780
  end
621
781
 
622
782
  # Adds a threaded comment to a cell.
@@ -634,8 +794,9 @@ module Xlsxrb
634
794
  # @api public
635
795
  #: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
636
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
637
798
  entry = {
638
- cell: cell,
799
+ ref: ref_str,
639
800
  text: text,
640
801
  author: author,
641
802
  timestamp: timestamp,
@@ -646,7 +807,9 @@ module Xlsxrb
646
807
  provider_id: provider_id
647
808
  }.compact
648
809
  @threaded_comments << entry
810
+ nil
649
811
  end
812
+ # @deprecated Use {#threaded_comment} instead. Will be removed in 0.2.0.
650
813
  alias add_threaded_comment threaded_comment
651
814
 
652
815
  # Adds a sparkline group to the sheet.
@@ -675,6 +838,7 @@ module Xlsxrb
675
838
  # @example Add a win/loss sparkline
676
839
  # sheet.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
677
840
  #
841
+ # @deprecated Use {#sparkline_group} instead. Will be removed in 0.2.0.
678
842
  # @param location [String, nil] Target cell for the sparkline (e.g. "F1").
679
843
  # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
680
844
  # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
@@ -683,6 +847,7 @@ module Xlsxrb
683
847
  # @api public
684
848
  #: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
685
849
  def add_sparkline(location: nil, range: nil, type: nil, **opts)
850
+ warn "[DEPRECATION] #add_sparkline is deprecated; use #sparkline_group instead.", uplevel: 1
686
851
  loc = location || opts.delete(:location_ref)
687
852
  rng = range || opts.delete(:data_ref) || opts.delete(:data)
688
853
  raise ArgumentError, "Missing required location: parameter for sparkline" unless loc
@@ -701,9 +866,7 @@ module Xlsxrb
701
866
  # @example Merge with string range
702
867
  # sheet.merge("A1:C1")
703
868
  #
704
- # @example Merge with row and column bounds
705
- # sheet.merge(row_start: 0, row_end: 2, col_start: "A", col_end: "C")
706
- #
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.
707
870
  # @param range [String, Hash, nil] Cell range (e.g. "A1:B2") or hash of coordinates.
708
871
  # @param row [Integer, nil] Single row index.
709
872
  # @param col_start [Integer, String, nil] Starting column.
@@ -723,44 +886,150 @@ module Xlsxrb
723
886
  @merge_cells_ranges << canonical unless @merge_cells_ranges.include?(canonical)
724
887
  end
725
888
 
726
- # Freezes window panes at the specified row and column.
889
+ # Freezes window panes at the specified row and column, or queries freeze pane settings.
727
890
  #
728
- # @param row [Integer] Number of rows to freeze from top (0-based split position).
729
- # @param col [Integer, String] Number of columns to freeze from left (0-based or letter).
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.
912
+ #
913
+ # @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
730
914
  # @return [void]
731
915
  # @api public
732
- #: (?row: Integer, ?col: (Integer | String)) -> void
733
- def freeze_pane(row: 0, col: 0)
734
- col = Elements::Cell.column_index(col)
735
- @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
736
927
  end
737
928
 
738
- # Splits window panes without freezing.
929
+ # Splits window panes without freezing or queries split pane settings.
739
930
  #
740
- # @param x_split [Integer] Horizontal split offset in points.
741
- # @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.
742
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.
743
957
  # @return [void]
744
958
  # @api public
745
- #: (?x_split: ::Integer, ?y_split: ::Integer, ?top_left_cell: String?) -> void
746
- def split_pane(x_split: 0, y_split: 0, top_left_cell: nil)
747
- @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
748
971
  end
749
972
 
750
- # Sets the active cell and selection area for the worksheet.
973
+ # Sets or queries the active cell and selection area (<selection>).
751
974
  #
752
- # @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").
753
976
  # @param sqref [String, nil] Selected range reference (e.g. "A1:D10").
754
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]
755
1008
  # @return [void]
756
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.
757
1023
  #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
758
- def select_cell(active_cell, sqref: nil, pane: nil)
759
- @selection = { active_cell: active_cell, sqref: sqref || active_cell }
760
- @selection[:pane] = pane if pane
1024
+ def select_cell(...)
1025
+ warn "[DEPRECATION] `select_cell` is deprecated; use `selection` instead.", uplevel: 1
1026
+ selection(...)
761
1027
  end
762
1028
 
763
- # 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.
764
1033
  #
765
1034
  # @param left [Float, nil] Left margin.
766
1035
  # @param right [Float, nil] Right margin.
@@ -768,68 +1037,176 @@ module Xlsxrb
768
1037
  # @param bottom [Float, nil] Bottom margin.
769
1038
  # @param header [Float, nil] Header margin.
770
1039
  # @param footer [Float, nil] Footer margin.
771
- # @return [void]
1040
+ # @return [Elements::PageMargins, Hash<Symbol, untyped>, nil, void]
772
1041
  # @api public
773
- #: (?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)
774
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
+
775
1051
  @page_margins = DslHelpers.normalize_page_margins(
776
1052
  left: left, right: right, top: top, bottom: bottom, header: header, footer: footer
777
1053
  )
1054
+ nil
778
1055
  end
779
1056
 
780
- # Sets page setup configuration (orientation, paper size, fit to page, scaling).
1057
+ # Sets or clears page margins configuration.
781
1058
  #
782
- # @param opts [Hash] Page setup options (e.g. orientation: :landscape, paper_size: 9).
1059
+ # @param opts [Hash, Elements::PageMargins, nil]
783
1060
  # @return [void]
784
1061
  # @api public
785
- #: (**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)
786
1082
  def page_setup(**opts)
1083
+ if opts.empty?
1084
+ return defined?(Elements::PageSetup) ? Elements::PageSetup.new(**@page_setup) : @page_setup
1085
+ end
1086
+
787
1087
  @page_setup.merge!(opts)
788
- return unless (opts.key?(:fit_to_width) || opts.key?(:fit_to_height)) && !@sheet_properties.key?(:fit_to_page)
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
1090
+ end
789
1091
 
790
- @sheet_properties[:fit_to_page] = true
1092
+ # Sets page setup configuration.
1093
+ #
1094
+ # @param opts [Hash, Elements::PageSetup]
1095
+ # @return [void]
1096
+ # @api public
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
791
1102
  end
792
1103
 
793
1104
  # Configures whether page setup fits content to page width/height.
794
1105
  # When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
795
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.
796
1108
  # @param enabled [Boolean, nil] Whether to fit to page.
797
1109
  # @param width [Integer, nil] Pages wide to fit to.
798
1110
  # @param height [Integer, nil] Pages tall to fit to.
799
1111
  # @return [Boolean, void]
800
1112
  # @api public
801
1113
  #: (?bool? enabled, ?width: Integer?, ?height: Integer?) -> (bool | void)
802
- def fit_to_page(enabled = nil, width: nil, height: nil)
803
- if enabled.nil? && width.nil? && height.nil?
1114
+ def fit_to_page(enabled = OMITTED, width: nil, height: nil)
1115
+ if enabled.equal?(OMITTED) && width.nil? && height.nil?
804
1116
  return @sheet_properties[:fit_to_page] ? true : false
805
1117
  end
806
1118
 
807
- @sheet_properties[:fit_to_page] = (enabled.nil? || (enabled ? true : false))
1119
+ @sheet_properties[:fit_to_page] = if enabled.equal?(OMITTED)
1120
+ true
1121
+ else
1122
+ enabled ? true : false
1123
+ end
808
1124
  page_setup(fit_to_width: width) if width
809
1125
  page_setup(fit_to_height: height) if height
810
1126
  end
811
- alias fit_to_page= fit_to_page
812
- alias fit_to_page? fit_to_page
813
1127
 
814
- # Configures headers and footers for printing.
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.
815
1151
  #
816
1152
  # @param opts [Hash] Header and footer options (e.g. odd_header: "&CHeader Text").
817
- # @return [void]
1153
+ # @return [Elements::HeaderFooter, Hash<Symbol, untyped>, void]
818
1154
  # @api public
819
- #: (**untyped opts) -> void
1155
+ #: (**untyped opts) -> (untyped | void)
820
1156
  def header_footer(**opts)
1157
+ if opts.empty?
1158
+ return defined?(Elements::HeaderFooter) ? Elements::HeaderFooter.new(**@header_footer) : @header_footer
1159
+ end
1160
+
821
1161
  @header_footer.merge!(opts)
1162
+ nil
822
1163
  end
823
1164
 
824
- # Sets a print option (e.g. grid_lines: true, headings: true).
1165
+ # Sets header and footer configuration.
825
1166
  #
826
- # @param name [Symbol] Option name.
827
- # @param value [Object] Option value.
1167
+ # @param opts [Hash, Elements::HeaderFooter]
828
1168
  # @return [void]
829
1169
  # @api public
830
- #: (Symbol name, untyped value) -> void
831
- def print_options(name, value)
832
- @print_options[name] = value
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
833
1210
  end
834
1211
 
835
1212
  # Adds a defined name (named range or formula) scoped to this sheet or workbook.
@@ -838,18 +1215,35 @@ module Xlsxrb
838
1215
  # @param name [String] Defined name identifier.
839
1216
  # @param value [Object, nil] Cell reference, formula, or constant.
840
1217
  # @param hidden [Boolean] Whether the defined name is hidden from Excel's UI.
841
- # @param col [Integer, String, nil] Column index or letter for coordinate-based reference.
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.
842
1222
  # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
843
1223
  # @param range [String, nil] Cell range reference (e.g. "A1:A10").
844
- # @param sheet [String, nil] Target sheet name (defaults to current sheet).
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.
845
1227
  # @return [void]
846
1228
  # @api public
847
- #: (String name, ?untyped value, ?hidden: bool, ?col: untyped, ?rows: untyped, ?range: untyped, ?sheet: String?, ?local: bool) -> void
848
- def defined_name(name, value = nil, hidden: false, col: nil, rows: nil, range: nil, sheet: nil, local: false)
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
849
1237
  ref_sheet = sheet || @name
850
- normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: ref_sheet, col: col, rows: rows, range: range)
1238
+ normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: ref_sheet, col: c_arg, rows: r_arg, range: range)
851
1239
  entry = { name: name, value: normalized_val, hidden: hidden }
852
- local_sheet = local ? (@name || sheet) : sheet
1240
+ local_sheet = if scope
1241
+ scope == :workbook ? nil : scope.to_s
1242
+ elsif local
1243
+ @name || sheet
1244
+ else
1245
+ sheet
1246
+ end
853
1247
  entry[:local_sheet_name] = local_sheet if local_sheet
854
1248
  @defined_names << entry
855
1249
  end
@@ -863,13 +1257,24 @@ module Xlsxrb
863
1257
  # sheet.print_area #=> "A1:H50"
864
1258
  #
865
1259
  # @param range [String, nil] Cell range (e.g. "A1:H50").
866
- # @return [String, nil]
1260
+ # @return [String, nil, void]
867
1261
  # @api public
868
- #: (?String? range) -> String?
1262
+ #: (?String? range) -> (String | nil | void)
869
1263
  def print_area(range = nil)
870
1264
  return @print_area if range.nil?
871
1265
 
872
- @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
873
1278
  end
874
1279
 
875
1280
  # Sets or gets repeating print titles (rows and/or columns) for pagination.
@@ -878,17 +1283,44 @@ module Xlsxrb
878
1283
  # sheet.print_titles(rows: "1:2")
879
1284
  #
880
1285
  # @example Get repeating print titles
881
- # sheet.print_titles #=> { rows: "1:2", cols: nil }
1286
+ # sheet.print_titles #=> { rows: "1:2", columns: nil, cols: nil }
882
1287
  #
883
1288
  # @param rows [String, nil] Repeating row range (e.g. "1:2").
884
- # @param cols [String, nil] Repeating column range (e.g. "A:B").
885
- # @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]
886
1293
  # @api public
887
- #: (?rows: String?, ?cols: String?) -> Hash[Symbol, untyped]?
888
- def print_titles(rows: nil, cols: nil)
889
- 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
890
1298
 
891
- @print_titles = { rows: rows, cols: cols }
1299
+ return Elements::PrintTitles.new(**@print_titles)
1300
+ end
1301
+
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
892
1324
  end
893
1325
 
894
1326
  # Sets repeating title rows to appear at the top of each printed page.
@@ -912,7 +1344,8 @@ module Xlsxrb
912
1344
  last ||= first
913
1345
  "#{first + 1}:#{last + 1}"
914
1346
  end
915
- @print_titles = (@print_titles || {}).merge(rows: rows_str)
1347
+ existing_cols = @print_titles&.columns
1348
+ print_titles(rows: rows_str, columns: existing_cols)
916
1349
  end
917
1350
 
918
1351
  # Sets repeating title columns to appear at the left of each printed page.
@@ -933,9 +1366,9 @@ module Xlsxrb
933
1366
  cols_str = if first.is_a?(String)
934
1367
  first.include?(":") ? first : "#{first}:#{last || first}"
935
1368
  else
936
- first_name = Utils.col_index_to_name(first)
1369
+ first_name = Elements::Cell._column_letter(first)
937
1370
  last_name = if last.is_a?(Integer)
938
- Utils.col_index_to_name(last)
1371
+ Elements::Cell._column_letter(last)
939
1372
  elsif last
940
1373
  last.to_s
941
1374
  else
@@ -943,33 +1376,76 @@ module Xlsxrb
943
1376
  end
944
1377
  "#{first_name}:#{last_name}"
945
1378
  end
946
- @print_titles = (@print_titles || {}).merge(cols: cols_str)
1379
+ existing_rows = @print_titles&.rows
1380
+ print_titles(rows: existing_rows, columns: cols_str)
947
1381
  end
948
1382
 
949
- # 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.
950
1387
  #
951
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]
952
1407
  # @return [void]
953
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.
954
1423
  #: (**untyped opts) -> void
955
- def protect_sheet(**opts)
956
- @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(...)
957
1427
  end
958
1428
 
959
1429
  # Inserts an embedded image from raw binary data.
960
1430
  #
961
1431
  # @param file_data [String] Binary image data.
962
1432
  # @param ext [String] File extension ("png", "jpeg", etc.).
963
- # @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.
964
1435
  # @param from_row [Integer] Top-left starting row (0-based).
965
- # @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.
966
1438
  # @param to_row [Integer] Bottom-right ending row (0-based).
967
1439
  # @param opts [Hash] Additional image anchoring options.
968
1440
  # @return [void]
969
1441
  # @api public
970
- #: (String file_data, ?ext: ::String, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, **untyped opts) -> void
971
- def image(file_data, ext: "png", from_col: 0, from_row: 0, to_col: 5, to_row: 10, **opts)
972
- 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 }
973
1449
  img.merge!(opts)
974
1450
  @images << img
975
1451
  end
@@ -982,14 +1458,19 @@ module Xlsxrb
982
1458
  # @example Set background image from file path
983
1459
  # sheet.background_image("path/to/background.png")
984
1460
  #
1461
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#background_image=} instead.
985
1462
  # @param file_data [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
986
1463
  # @param ext [String, nil] Image extension ("png", "jpeg", "jpg", "gif", etc.).
987
1464
  # @param opts [Hash] Additional image options.
988
1465
  # @return [Hash, nil]
989
1466
  # @api public
990
- #: (?untyped file_data, ?ext: ::String?, **untyped opts) -> Hash[Symbol, untyped]?
1467
+ #: (?untyped file_data, ?ext: ::String?, **untyped opts) -> (Elements::BackgroundImage | Hash[Symbol, untyped] | nil)
991
1468
  def background_image(file_data = nil, ext: nil, **opts)
992
- return @background_image if file_data.nil? && ext.nil? && opts.empty?
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
993
1474
 
994
1475
  data = file_data
995
1476
  inferred_ext = nil
@@ -1023,36 +1504,53 @@ module Xlsxrb
1023
1504
  content_type: mime
1024
1505
  }.merge(opts).freeze
1025
1506
  end
1507
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1026
1508
  alias background_picture background_image
1509
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1027
1510
  alias picture background_image
1028
1511
 
1512
+ #: (untyped val) -> untyped
1029
1513
  def background_image=(val)
1030
- background_image(val)
1514
+ if val.nil?
1515
+ @background_image = nil
1516
+ else
1517
+ background_image(val)
1518
+ end
1519
+ val
1031
1520
  end
1521
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1032
1522
  alias background_picture= background_image=
1523
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1033
1524
  alias picture= background_image=
1034
1525
 
1035
1526
  # Inserts a drawing shape (e.g. rectangle, callout, arrow).
1036
1527
  #
1037
1528
  # @param preset [String] Shape preset name (e.g. "rect", "roundRect").
1038
1529
  # @param text [String, nil] Shape label text.
1039
- # @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.
1040
1532
  # @param from_row [Integer] Top-left row.
1041
- # @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.
1042
1535
  # @param to_row [Integer] Bottom-right row.
1043
1536
  # @param opts [Hash] Additional shape formatting options.
1044
1537
  # @return [void]
1045
1538
  # @api public
1046
1539
  #: (**untyped opts) -> void
1047
- def shape(preset: "rect", text: nil, from_col: 0, from_row: 0, to_col: 5, to_row: 5, **opts)
1048
- shape = { preset: preset, text: text, from_col: from_col, from_row: from_row, to_col: to_col, to_row: to_row }
1049
- shape[:name] = opts.delete(:name) || "Shape #{@shapes.size + 1}"
1050
- shape.merge!(opts)
1051
- @shapes << shape
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
1052
1549
  end
1053
1550
 
1054
1551
  # Gets or sets the sheet visibility state (:visible, :hidden, or :very_hidden).
1055
1552
  #
1553
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#state=} instead.
1056
1554
  # @param new_state [Symbol, nil] The new state.
1057
1555
  # @return [Symbol]
1058
1556
  # @api public
@@ -1068,8 +1566,22 @@ module Xlsxrb
1068
1566
  end
1069
1567
  end
1070
1568
 
1569
+ # Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
1570
+ #
1571
+ # @param new_state [Symbol, String] The new state.
1572
+ # @return [Symbol]
1573
+ # @api public
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
1580
+ end
1581
+
1071
1582
  # Gets or sets the worksheet tab color.
1072
1583
  #
1584
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_color=} instead.
1073
1585
  # @overload tab_color()
1074
1586
  # Returns the current tab color specification.
1075
1587
  # @return [String, Hash, nil]
@@ -1080,8 +1592,8 @@ module Xlsxrb
1080
1592
  # @return [String, Hash, nil]
1081
1593
  # @api public
1082
1594
  #: (?String | Symbol | Hash[Symbol, untyped] | nil spec, **untyped opts) -> (String | Hash[Symbol, untyped] | nil)
1083
- def tab_color(spec = nil, **opts)
1084
- if spec.nil? && opts.empty?
1595
+ def tab_color(spec = OMITTED, **opts)
1596
+ if spec.equal?(OMITTED) && opts.empty?
1085
1597
  @sheet_properties[:tab_color]
1086
1598
  else
1087
1599
  color = if opts.empty?
@@ -1092,85 +1604,199 @@ module Xlsxrb
1092
1604
  @sheet_properties[:tab_color] = color
1093
1605
  end
1094
1606
  end
1095
- alias tab_color= tab_color
1096
1607
 
1097
- # Sets a sheet-level property (e.g. tab_color: "FF0000").
1608
+ # Sets the tab color of this worksheet.
1098
1609
  #
1099
- # @param name [Symbol] Property name.
1610
+ # @param spec [String, Hash, Symbol, nil] Tab color hex string (e.g. "FF0000") or hash options.
1611
+ # @return [String, Hash, nil]
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.
1100
1621
  # @param value [Object] Property value.
1101
1622
  # @return [void]
1102
1623
  # @api public
1103
- #: (Symbol name, untyped value) -> void
1104
- def sheet_properties(name, value)
1105
- sym = name.to_sym
1106
- if sym == :state
1107
- val = value.to_sym
1108
- raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
1624
+ #: (Symbol | String name, untyped value) -> void
1625
+ def sheet_property(name, value)
1626
+ sheet_properties(name, value)
1627
+ end
1109
1628
 
1110
- @state = val
1111
- return
1112
- elsif sym == :hidden
1113
- @state = value ? :hidden : :visible
1114
- return
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
1115
1660
  end
1661
+ opts.each { |k, v| sheet_properties(k, v) }
1662
+ nil
1663
+ end
1116
1664
 
1117
- @sheet_properties[name] = value
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
1118
1676
  end
1119
1677
 
1120
- # Sets a sheet view display property (e.g. show_grid_lines: true, zoom_scale: 120).
1678
+ # Configures or queries sheet view display properties (<sheetView>).
1121
1679
  #
1122
- # @param name [Symbol] View property name.
1123
- # @param value [Object] View property value.
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]
1124
1704
  # @return [void]
1125
1705
  # @api public
1126
- #: (Symbol name, untyped value) -> void
1127
- def sheet_view(name, value)
1128
- @sheet_view[name] = value
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
1129
1711
  end
1130
1712
 
1131
- # Configures sheet format properties (e.g. default_row_height, default_col_width).
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.
1132
1717
  #
1133
1718
  # @example Using keyword arguments
1134
- # sheet.sheet_format(default_row_height: 24, default_col_width: 15)
1719
+ # sheet.sheet_format(default_row_height: 24, default_column_width: 15)
1135
1720
  #
1136
1721
  # @example Using property name and value
1137
1722
  # sheet.sheet_format(:default_row_height, 24)
1138
1723
  #
1139
- # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
1724
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
1140
1725
  # @param value [Object, nil] Property value when name is provided.
1141
1726
  # @param opts [Hash] Keyword arguments for sheet format properties.
1142
- # @return [Hash]
1727
+ # @return [Elements::SheetFormat, void]
1143
1728
  # @api public
1144
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
1729
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetFormat | void)
1145
1730
  def sheet_format(name = nil, value = nil, **opts)
1146
- if name.is_a?(Hash)
1147
- @sheet_format.merge!(name)
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)
1148
1735
  elsif name && value
1149
1736
  @sheet_format[name.to_sym] = value
1150
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
1151
1750
  @sheet_format.merge!(opts) unless opts.empty?
1152
- @sheet_format
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
1153
1765
  end
1154
1766
 
1155
- # Inserts a horizontal page break before the specified row.
1767
+ # Inserts a horizontal page break after the specified 0-based row.
1156
1768
  #
1157
- # @param row_num [Integer] 1-based row number.
1769
+ # @param row_index [Integer] 0-based row index.
1158
1770
  # @return [void]
1159
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.
1160
1778
  #: (Integer row_num) -> void
1161
1779
  def page_break_row(row_num)
1162
- @row_breaks << row_num
1780
+ warn "[DEPRECATION] `page_break_row` is deprecated; use `row_break` instead.", uplevel: 1
1781
+ row_break(row_num)
1163
1782
  end
1164
1783
 
1165
- # Inserts a vertical page break before the specified column.
1784
+ # Inserts a vertical page break after the specified column.
1166
1785
  #
1167
- # @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).
1168
1787
  # @return [void]
1169
1788
  # @api public
1170
- #: (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
1171
1797
  def page_break_col(col_index)
1172
- col_index = Elements::Cell.column_index(col_index)
1173
- @col_breaks << col_index
1798
+ warn "[DEPRECATION] `page_break_col` is deprecated; use `column_break` instead.", uplevel: 1
1799
+ column_break(col_index)
1174
1800
  end
1175
1801
 
1176
1802
  # Adds a protected range to the worksheet.
@@ -1188,6 +1814,7 @@ module Xlsxrb
1188
1814
  entry.merge!(opts) unless opts.empty?
1189
1815
  @protected_ranges << DslHelpers.normalize_protection_options(entry)
1190
1816
  end
1817
+ # @deprecated Use {#protected_range} instead. Will be removed in 0.2.0.
1191
1818
  alias add_protected_range protected_range
1192
1819
 
1193
1820
  # Adds a cell watch to the worksheet.
@@ -1199,6 +1826,7 @@ module Xlsxrb
1199
1826
  def cell_watch(ref)
1200
1827
  @cell_watches << ref.to_s
1201
1828
  end
1829
+ # @deprecated Use {#cell_watch} instead. Will be removed in 0.2.0.
1202
1830
  alias add_cell_watch cell_watch
1203
1831
 
1204
1832
  # Adds an ignored error entry for the worksheet.
@@ -1208,10 +1836,23 @@ module Xlsxrb
1208
1836
  # @return [void]
1209
1837
  # @api public
1210
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
1211
- def ignore_error(sqref, **opts)
1839
+ def ignored_error(sqref, **opts)
1212
1840
  @ignored_errors << { sqref: sqref.to_s }.merge(opts)
1213
1841
  end
1214
- alias add_ignored_error ignore_error
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
1215
1856
 
1216
1857
  # Returns ignored error rules configured for this worksheet.
1217
1858
  #
@@ -1219,11 +1860,12 @@ module Xlsxrb
1219
1860
  # @api public
1220
1861
  #: () -> Array[Hash[Symbol, untyped]]
1221
1862
  def ignored_errors
1222
- @ignored_errors.dup
1863
+ @ignored_errors.map { |ie| ie.is_a?(Elements::IgnoredError) ? ie : Elements::IgnoredError.new(**ie) }.freeze
1223
1864
  end
1224
1865
 
1225
1866
  # Gets or sets phonetic (furigana) guide properties for the worksheet.
1226
1867
  #
1868
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#phonetic_properties=} instead.
1227
1869
  # @overload phonetic_properties()
1228
1870
  # Returns the current phonetic properties.
1229
1871
  # @return [Hash, nil]
@@ -1235,10 +1877,14 @@ module Xlsxrb
1235
1877
  # @param alignment [Symbol, String, nil]
1236
1878
  # @return [Hash, nil]
1237
1879
  # @api public
1238
- #: (?Hash[Symbol, untyped] | Integer | nil spec, ?font_id: Integer?, ?type: (Symbol | String)?, ?alignment: (Symbol | String)?, **untyped opts) -> Hash[Symbol, untyped]?
1239
- def phonetic_properties(spec = nil, font_id: nil, type: nil, alignment: nil, **opts)
1240
- if spec.nil? && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
1241
- @phonetic_properties
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
1242
1888
  else
1243
1889
  props = if spec.is_a?(Hash)
1244
1890
  spec.merge(opts)
@@ -1251,14 +1897,38 @@ module Xlsxrb
1251
1897
  @phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
1252
1898
  end
1253
1899
  end
1254
- alias phonetic_properties= phonetic_properties
1900
+ # @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
1255
1901
  alias phonetic_pr phonetic_properties
1256
- 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=
1257
1926
 
1258
1927
  # Normalizes phonetic properties to OOXML schema values.
1259
1928
  #
1260
1929
  # @param props [Hash, nil]
1261
1930
  # @return [Hash[Symbol, untyped], nil]
1931
+ # @api private
1262
1932
  #: (Hash[untyped, untyped]? props) -> Hash[Symbol, untyped]?
1263
1933
  def self.normalize_phonetic_properties(props)
1264
1934
  return nil if props.nil? || props.empty?
@@ -1290,30 +1960,50 @@ module Xlsxrb
1290
1960
 
1291
1961
  # Sets or gets the internal code name of the worksheet.
1292
1962
  #
1963
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
1293
1964
  # @param val [String, Symbol, nil] The code name.
1294
1965
  # @return [String, nil]
1295
1966
  # @api public
1296
1967
  #: (?String | Symbol | nil val) -> String?
1297
- def code_name(val = nil)
1298
- return @sheet_properties[:code_name] if val.nil?
1968
+ def code_name(val = OMITTED)
1969
+ return @sheet_properties[:code_name] if val.equal?(OMITTED)
1299
1970
 
1300
- @sheet_properties[:code_name] = val.to_s
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
1301
1982
  end
1302
- alias code_name= code_name
1303
1983
 
1304
1984
  # Configures worksheet calculation properties (<sheetCalcPr>).
1305
1985
  #
1306
1986
  # @example Instruct Excel to recalculate formulas when loading sheet
1307
- # sheet.sheet_calc_pr(full_calc_on_load: true)
1987
+ # sheet.sheet_calc_properties = { full_calc_on_load: true }
1308
1988
  #
1989
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sheet_calc_properties=} instead.
1309
1990
  # @param spec [Hash, nil] Calculation properties hash.
1310
1991
  # @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
1311
1992
  # @return [Hash, nil]
1312
1993
  # @api public
1313
- #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> Hash[Symbol, untyped]?
1314
- def sheet_calc_pr(spec = nil, full_calc_on_load: nil, **opts)
1315
- if spec.nil? && full_calc_on_load.nil? && opts.empty?
1316
- return @sheet_calc_pr || (@sheet_properties[:full_calc_on_load] ? { full_calc_on_load: true } : nil)
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
1317
2007
  end
1318
2008
 
1319
2009
  pr = spec.is_a?(Hash) ? spec.dup : {}
@@ -1322,9 +2012,52 @@ module Xlsxrb
1322
2012
  @sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
1323
2013
  @sheet_calc_pr = pr
1324
2014
  end
1325
- alias sheet_calc_pr= sheet_calc_pr
1326
- alias calc_pr sheet_calc_pr
1327
- alias calc_pr= sheet_calc_pr
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
1328
2061
 
1329
2062
  # Builds and returns the in-memory {Elements::Worksheet}.
1330
2063
  #
@@ -1371,25 +2104,37 @@ module Xlsxrb
1371
2104
 
1372
2105
  hl_hash = {}
1373
2106
  @hyperlinks.each do |h|
1374
- ref = h[:cell].to_s.upcase
1375
- entry = {}
1376
- entry[:url] = h[:url] if h[:url]
1377
- entry[:display] = h[:display] if h[:display]
1378
- entry[:tooltip] = h[:tooltip] if h[:tooltip]
1379
- entry[:location] = h[:location] if h[:location]
1380
- 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
1381
2124
  end
1382
2125
 
1383
2126
  cm_hash = {}
1384
2127
  @comments.each do |c|
1385
- ref = (c[:ref] || c[:cell]).to_s.upcase
1386
- 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
1387
2131
  end
1388
2132
 
1389
2133
  tc_hash = {}
1390
2134
  @threaded_comments.each do |c|
1391
- ref = (c[:ref] || c[:cell]).to_s.upcase
1392
- (tc_hash[ref] ||= []) << 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
1393
2138
  end
1394
2139
 
1395
2140
  rows = if hl_hash.empty? && cm_hash.empty? && tc_hash.empty?
@@ -1416,7 +2161,7 @@ module Xlsxrb
1416
2161
 
1417
2162
  Elements::Worksheet.new(
1418
2163
  name: @name, rows: rows, columns: @columns, charts: @charts,
1419
- conditional_formatting: @conditional_formats,
2164
+ conditional_formats: @conditional_formats,
1420
2165
  data_validations: @data_validations,
1421
2166
  unmapped_data: facade_meta.empty? ? {} : { facade: facade_meta },
1422
2167
  state: @state,
@@ -1440,13 +2185,13 @@ module Xlsxrb
1440
2185
  sheet_properties: @sheet_properties,
1441
2186
  sheet_format: @sheet_format,
1442
2187
  row_breaks: @row_breaks,
1443
- col_breaks: @col_breaks,
2188
+ column_breaks: @col_breaks,
1444
2189
  protected_ranges: @protected_ranges,
1445
2190
  cell_watches: @cell_watches,
1446
2191
  ignored_errors: @ignored_errors,
1447
2192
  phonetic_properties: @phonetic_properties,
1448
2193
  selection: @selection,
1449
- sheet_calc_pr: @sheet_calc_pr,
2194
+ sheet_calc_properties: @sheet_calc_pr,
1450
2195
  background_image: @background_image
1451
2196
  )
1452
2197
  end
@@ -1461,6 +2206,8 @@ module Xlsxrb
1461
2206
  #
1462
2207
  # @api public
1463
2208
  class TableBuilder
2209
+ OMITTED = Object.new.freeze
2210
+ private_constant :OMITTED
1464
2211
  # @param ref [String, nil] Table range (e.g. "A1:D10").
1465
2212
  # @param columns [Array, nil] Column header names or definition hashes.
1466
2213
  # @param name [String, nil] Table name identifier.
@@ -1477,16 +2224,21 @@ module Xlsxrb
1477
2224
  @options[:style] = style if style
1478
2225
  end
1479
2226
 
2227
+ # @deprecated Use explicit getter methods instead.
1480
2228
  #: (untyped key) -> untyped
1481
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
1482
2231
  @options[key.to_sym]
1483
2232
  end
1484
2233
 
2234
+ # @deprecated Use explicit setter methods instead.
1485
2235
  #: (untyped key, untyped value) -> untyped
1486
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
1487
2238
  @options[key.to_sym] = value
1488
2239
  end
1489
2240
 
2241
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#ref=} instead.
1490
2242
  #: (?String? val) -> String?
1491
2243
  def ref(val = nil)
1492
2244
  if val
@@ -1501,6 +2253,7 @@ module Xlsxrb
1501
2253
  @options[:ref] = val.to_s
1502
2254
  end
1503
2255
 
2256
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#columns=} instead.
1504
2257
  #: (*untyped cols) -> untyped
1505
2258
  def columns(*cols)
1506
2259
  if cols.empty?
@@ -1532,7 +2285,9 @@ module Xlsxrb
1532
2285
  opts.merge(name: col.to_s)
1533
2286
  end
1534
2287
  (@options[:columns] ||= []) << col_spec
2288
+ nil
1535
2289
  end
2290
+ # @deprecated Use {#column} instead. Will be removed in 0.2.0.
1536
2291
  alias add_column column
1537
2292
 
1538
2293
  # Appends a calculated column with formula and options.
@@ -1546,6 +2301,7 @@ module Xlsxrb
1546
2301
  column(name, formula: formula, **opts)
1547
2302
  end
1548
2303
 
2304
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#name=} instead.
1549
2305
  #: (?String? val) -> String?
1550
2306
  def name(val = nil)
1551
2307
  if val
@@ -1560,6 +2316,7 @@ module Xlsxrb
1560
2316
  @options[:name] = val.to_s
1561
2317
  end
1562
2318
 
2319
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#display_name=} instead.
1563
2320
  #: (?String? val) -> String?
1564
2321
  def display_name(val = nil)
1565
2322
  if val
@@ -1574,6 +2331,7 @@ module Xlsxrb
1574
2331
  @options[:display_name] = val.to_s
1575
2332
  end
1576
2333
 
2334
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#style=} instead.
1577
2335
  #: (?String? val) -> String?
1578
2336
  def style(val = nil)
1579
2337
  if val
@@ -1588,6 +2346,7 @@ module Xlsxrb
1588
2346
  @options[:style] = val.to_s
1589
2347
  end
1590
2348
 
2349
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_row_stripes=} instead.
1591
2350
  #: (?bool? val) -> bool?
1592
2351
  def show_row_stripes(val = nil)
1593
2352
  if val.nil?
@@ -1602,6 +2361,7 @@ module Xlsxrb
1602
2361
  @options[:show_row_stripes] = val ? true : false
1603
2362
  end
1604
2363
 
2364
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_column_stripes=} instead.
1605
2365
  #: (?bool? val) -> bool?
1606
2366
  def show_column_stripes(val = nil)
1607
2367
  if val.nil?
@@ -1616,6 +2376,7 @@ module Xlsxrb
1616
2376
  @options[:show_column_stripes] = val ? true : false
1617
2377
  end
1618
2378
 
2379
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_first_column=} instead.
1619
2380
  #: (?bool? val) -> bool?
1620
2381
  def show_first_column(val = nil)
1621
2382
  if val.nil?
@@ -1630,6 +2391,7 @@ module Xlsxrb
1630
2391
  @options[:show_first_column] = val ? true : false
1631
2392
  end
1632
2393
 
2394
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_last_column=} instead.
1633
2395
  #: (?bool? val) -> bool?
1634
2396
  def show_last_column(val = nil)
1635
2397
  if val.nil?
@@ -1644,36 +2406,70 @@ module Xlsxrb
1644
2406
  @options[:show_last_column] = val ? true : false
1645
2407
  end
1646
2408
 
2409
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#totals_row_count=} instead.
1647
2410
  #: (?Integer? val) -> Integer?
1648
- def total_row_count(val = nil)
2411
+ def totals_row_count(val = nil)
1649
2412
  if val.nil?
1650
2413
  @options[:totals_row_count] || @options[:total_row_count]
1651
2414
  else
1652
2415
  @options[:totals_row_count] = val.to_i
1653
2416
  end
1654
2417
  end
1655
- alias totals_row_count total_row_count
1656
2418
 
1657
2419
  #: (Integer val) -> Integer
1658
- def total_row_count=(val)
2420
+ def totals_row_count=(val)
1659
2421
  @options[:totals_row_count] = val.to_i
1660
2422
  end
1661
- alias totals_row_count= total_row_count=
1662
2423
 
1663
- #: (?bool? val) -> bool?
1664
- def total_row(val = nil)
1665
- if val.nil?
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.
2432
+ #: (Integer val) -> Integer
2433
+ def total_row_count=(val)
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)
1666
2444
  rc = @options[:totals_row_count] || @options[:total_row_count]
1667
- rc ? rc.positive? : @options[:total_row]
2445
+ rc ? rc.positive? : @options[:totals_row]
1668
2446
  else
1669
2447
  @options[:totals_row_count] = val ? 1 : 0
1670
2448
  val ? true : false
1671
2449
  end
1672
2450
  end
1673
- alias total_row= total_row
1674
- alias totals_row total_row
1675
- alias totals_row= total_row
1676
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.
1677
2473
  #: (?bool? val) -> bool?
1678
2474
  def auto_filter(val = nil)
1679
2475
  if val.nil?
@@ -1706,16 +2502,28 @@ module Xlsxrb
1706
2502
  @options[:sqref] = sqref if sqref
1707
2503
  end
1708
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
1709
2509
  #: (untyped key) -> untyped
1710
2510
  def [](key)
2511
+ warn "[Xlsxrb DEPRECATION] DataValidationBuilder#[] is deprecated; use dedicated property accessors instead.", uplevel: 1
1711
2512
  @options[key.to_sym]
1712
2513
  end
1713
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
1714
2520
  #: (untyped key, untyped value) -> untyped
1715
2521
  def []=(key, value)
2522
+ warn "[Xlsxrb DEPRECATION] DataValidationBuilder#[]= is deprecated; use dedicated property accessors instead.", uplevel: 1
1716
2523
  @options[key.to_sym] = value
1717
2524
  end
1718
2525
 
2526
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sqref=} instead.
1719
2527
  #: (?String? val) -> String?
1720
2528
  def sqref(val = nil)
1721
2529
  if val
@@ -1729,9 +2537,12 @@ module Xlsxrb
1729
2537
  def sqref=(val)
1730
2538
  @options[:sqref] = val.to_s
1731
2539
  end
2540
+ # @deprecated Use {#sqref} instead. Will be removed in 0.2.0.
1732
2541
  alias range sqref
2542
+ # @deprecated Use {#sqref=} instead. Will be removed in 0.2.0.
1733
2543
  alias range= sqref=
1734
2544
 
2545
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#columns=} instead.
1735
2546
  #: (?untyped val) -> untyped
1736
2547
  def columns(val = nil)
1737
2548
  if val
@@ -1745,9 +2556,12 @@ module Xlsxrb
1745
2556
  def columns=(val)
1746
2557
  @options[:columns] = val
1747
2558
  end
2559
+ # @deprecated Use {#columns} instead. Will be removed in 0.2.0.
1748
2560
  alias col columns
2561
+ # @deprecated Use {#columns=} instead. Will be removed in 0.2.0.
1749
2562
  alias col= columns=
1750
2563
 
2564
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#rows=} instead.
1751
2565
  #: (?untyped val) -> untyped
1752
2566
  def rows(val = nil)
1753
2567
  if val
@@ -1761,9 +2575,12 @@ module Xlsxrb
1761
2575
  def rows=(val)
1762
2576
  @options[:rows] = val
1763
2577
  end
2578
+ # @deprecated Use {#rows} instead. Will be removed in 0.2.0.
1764
2579
  alias row rows
2580
+ # @deprecated Use {#rows=} instead. Will be removed in 0.2.0.
1765
2581
  alias row= rows=
1766
2582
 
2583
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#except_rows=} instead.
1767
2584
  #: (?untyped val) -> untyped
1768
2585
  def except_rows(val = nil)
1769
2586
  if val
@@ -1778,20 +2595,45 @@ module Xlsxrb
1778
2595
  @options[:except_rows] = val
1779
2596
  end
1780
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
1781
2606
  #: (?Array[untyped]? val) -> untyped
1782
- def in(val = nil)
2607
+ def list(val = nil)
1783
2608
  if val
2609
+ @options[:list] = val
1784
2610
  @options[:in] = val
1785
2611
  else
1786
- @options[:in]
2612
+ @options[:list] || @options[:in]
1787
2613
  end
1788
2614
  end
1789
2615
 
1790
2616
  #: (Array[untyped] val) -> untyped
1791
- def in=(val)
2617
+ def list=(val)
2618
+ @options[:list] = val
1792
2619
  @options[:in] = val
1793
2620
  end
1794
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.
1795
2637
  #: (?untyped val) -> untyped
1796
2638
  def type(val = nil)
1797
2639
  if val
@@ -1806,6 +2648,7 @@ module Xlsxrb
1806
2648
  @options[:type] = val
1807
2649
  end
1808
2650
 
2651
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#operator=} instead.
1809
2652
  #: (?untyped val) -> untyped
1810
2653
  def operator(val = nil)
1811
2654
  if val
@@ -1820,6 +2663,7 @@ module Xlsxrb
1820
2663
  @options[:operator] = val
1821
2664
  end
1822
2665
 
2666
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#formula1=} instead.
1823
2667
  #: (?untyped val) -> untyped
1824
2668
  def formula1(val = nil)
1825
2669
  if val
@@ -1834,6 +2678,7 @@ module Xlsxrb
1834
2678
  @options[:formula1] = val
1835
2679
  end
1836
2680
 
2681
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#formula2=} instead.
1837
2682
  #: (?untyped val) -> untyped
1838
2683
  def formula2(val = nil)
1839
2684
  if val
@@ -1848,6 +2693,7 @@ module Xlsxrb
1848
2693
  @options[:formula2] = val
1849
2694
  end
1850
2695
 
2696
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#allow_blank=} instead.
1851
2697
  #: (?bool? val) -> bool?
1852
2698
  def allow_blank(val = nil)
1853
2699
  if val.nil?
@@ -1862,6 +2708,7 @@ module Xlsxrb
1862
2708
  @options[:allow_blank] = val ? true : false
1863
2709
  end
1864
2710
 
2711
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_input_message=} instead.
1865
2712
  #: (?bool? val) -> bool?
1866
2713
  def show_input_message(val = nil)
1867
2714
  if val.nil?
@@ -1876,6 +2723,7 @@ module Xlsxrb
1876
2723
  @options[:show_input_message] = val ? true : false
1877
2724
  end
1878
2725
 
2726
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_error_message=} instead.
1879
2727
  #: (?bool? val) -> bool?
1880
2728
  def show_error_message(val = nil)
1881
2729
  if val.nil?
@@ -1890,6 +2738,7 @@ module Xlsxrb
1890
2738
  @options[:show_error_message] = val ? true : false
1891
2739
  end
1892
2740
 
2741
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#error_title=} instead.
1893
2742
  #: (?String? val) -> String?
1894
2743
  def error_title(val = nil)
1895
2744
  if val
@@ -1904,6 +2753,7 @@ module Xlsxrb
1904
2753
  @options[:error_title] = val.to_s
1905
2754
  end
1906
2755
 
2756
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#error_message=} instead.
1907
2757
  #: (?String? val) -> String?
1908
2758
  def error_message(val = nil)
1909
2759
  if val
@@ -1917,9 +2767,12 @@ module Xlsxrb
1917
2767
  def error_message=(val)
1918
2768
  @options[:error] = val.to_s
1919
2769
  end
2770
+ # @deprecated Use {#error_message} instead. Will be removed in 0.2.0.
1920
2771
  alias error error_message
2772
+ # @deprecated Use {#error_message=} instead. Will be removed in 0.2.0.
1921
2773
  alias error= error_message=
1922
2774
 
2775
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#prompt_title=} instead.
1923
2776
  #: (?String? val) -> String?
1924
2777
  def prompt_title(val = nil)
1925
2778
  if val
@@ -1934,6 +2787,7 @@ module Xlsxrb
1934
2787
  @options[:prompt_title] = val.to_s
1935
2788
  end
1936
2789
 
2790
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#prompt_message=} instead.
1937
2791
  #: (?String? val) -> String?
1938
2792
  def prompt_message(val = nil)
1939
2793
  if val
@@ -1947,9 +2801,12 @@ module Xlsxrb
1947
2801
  def prompt_message=(val)
1948
2802
  @options[:prompt] = val.to_s
1949
2803
  end
2804
+ # @deprecated Use {#prompt_message} instead. Will be removed in 0.2.0.
1950
2805
  alias prompt prompt_message
2806
+ # @deprecated Use {#prompt_message=} instead. Will be removed in 0.2.0.
1951
2807
  alias prompt= prompt_message=
1952
2808
 
2809
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#error_style=} instead.
1953
2810
  #: (?untyped val) -> untyped
1954
2811
  def error_style(val = nil)
1955
2812
  if val
@@ -1982,16 +2839,28 @@ module Xlsxrb
1982
2839
  @options[:sqref] = sqref if sqref
1983
2840
  end
1984
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
1985
2846
  #: (untyped key) -> untyped
1986
2847
  def [](key)
2848
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#[] is deprecated; use dedicated property accessors instead.", uplevel: 1
1987
2849
  @options[key.to_sym]
1988
2850
  end
1989
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
1990
2857
  #: (untyped key, untyped value) -> untyped
1991
2858
  def []=(key, value)
2859
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#[]= is deprecated; use dedicated property accessors instead.", uplevel: 1
1992
2860
  @options[key.to_sym] = value
1993
2861
  end
1994
2862
 
2863
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sqref=} instead.
1995
2864
  #: (?String? val) -> String?
1996
2865
  def sqref(val = nil)
1997
2866
  if val
@@ -2005,9 +2874,12 @@ module Xlsxrb
2005
2874
  def sqref=(val)
2006
2875
  @options[:sqref] = val.to_s
2007
2876
  end
2877
+ # @deprecated Use {#sqref} instead. Will be removed in 0.2.0.
2008
2878
  alias range sqref
2879
+ # @deprecated Use {#sqref=} instead. Will be removed in 0.2.0.
2009
2880
  alias range= sqref=
2010
2881
 
2882
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#columns=} instead.
2011
2883
  #: (?untyped val) -> untyped
2012
2884
  def columns(val = nil)
2013
2885
  if val
@@ -2021,9 +2893,12 @@ module Xlsxrb
2021
2893
  def columns=(val)
2022
2894
  @options[:columns] = val
2023
2895
  end
2896
+ # @deprecated Use {#columns} instead. Will be removed in 0.2.0.
2024
2897
  alias col columns
2898
+ # @deprecated Use {#columns=} instead. Will be removed in 0.2.0.
2025
2899
  alias col= columns=
2026
2900
 
2901
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#rows=} instead.
2027
2902
  #: (?untyped val) -> untyped
2028
2903
  def rows(val = nil)
2029
2904
  if val
@@ -2037,9 +2912,12 @@ module Xlsxrb
2037
2912
  def rows=(val)
2038
2913
  @options[:rows] = val
2039
2914
  end
2915
+ # @deprecated Use {#rows} instead. Will be removed in 0.2.0.
2040
2916
  alias row rows
2917
+ # @deprecated Use {#rows=} instead. Will be removed in 0.2.0.
2041
2918
  alias row= rows=
2042
2919
 
2920
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#except_rows=} instead.
2043
2921
  #: (?untyped val) -> untyped
2044
2922
  def except_rows(val = nil)
2045
2923
  if val
@@ -2054,6 +2932,7 @@ module Xlsxrb
2054
2932
  @options[:except_rows] = val
2055
2933
  end
2056
2934
 
2935
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#type=} instead.
2057
2936
  #: (?untyped val) -> untyped
2058
2937
  def type(val = nil)
2059
2938
  if val
@@ -2068,6 +2947,7 @@ module Xlsxrb
2068
2947
  @options[:type] = val
2069
2948
  end
2070
2949
 
2950
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#operator=} instead.
2071
2951
  #: (?untyped val) -> untyped
2072
2952
  def operator(val = nil)
2073
2953
  if val
@@ -2082,6 +2962,7 @@ module Xlsxrb
2082
2962
  @options[:operator] = val
2083
2963
  end
2084
2964
 
2965
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#formula=} instead.
2085
2966
  #: (?untyped val) -> untyped
2086
2967
  def formula(val = nil)
2087
2968
  if val
@@ -2096,8 +2977,12 @@ module Xlsxrb
2096
2977
  @options[:formula] = val
2097
2978
  end
2098
2979
 
2980
+ # @deprecated Use {#formula} instead. Will be removed in 0.2.0.
2981
+ # @return [Object]
2982
+ # @api public
2099
2983
  #: (*untyped vals) -> untyped
2100
2984
  def formulas(*vals)
2985
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#formulas is deprecated; use #formula instead.", uplevel: 1
2101
2986
  if vals.empty?
2102
2987
  @options[:formulas]
2103
2988
  elsif vals.size == 1 && vals.first.is_a?(Array)
@@ -2107,11 +2992,17 @@ module Xlsxrb
2107
2992
  end
2108
2993
  end
2109
2994
 
2995
+ # @deprecated Use {#formula=} instead. Will be removed in 0.2.0.
2996
+ # @param vals [Array, Object]
2997
+ # @return [Array]
2998
+ # @api public
2110
2999
  #: (untyped vals) -> untyped
2111
3000
  def formulas=(vals)
3001
+ warn "[Xlsxrb DEPRECATION] ConditionalFormatBuilder#formulas= is deprecated; use #formula= instead.", uplevel: 1
2112
3002
  @options[:formulas] = vals.is_a?(Array) ? vals : [vals]
2113
3003
  end
2114
3004
 
3005
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#font=} instead.
2115
3006
  #: (?untyped val) -> untyped
2116
3007
  def font(val = nil)
2117
3008
  if val
@@ -2126,6 +3017,7 @@ module Xlsxrb
2126
3017
  @options[:font] = val
2127
3018
  end
2128
3019
 
3020
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fill=} instead.
2129
3021
  #: (?untyped val) -> untyped
2130
3022
  def fill(val = nil)
2131
3023
  if val
@@ -2140,6 +3032,7 @@ module Xlsxrb
2140
3032
  @options[:fill] = val
2141
3033
  end
2142
3034
 
3035
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#fill_color=} instead.
2143
3036
  #: (?untyped val) -> untyped
2144
3037
  def fill_color(val = nil)
2145
3038
  if val
@@ -2154,6 +3047,7 @@ module Xlsxrb
2154
3047
  @options[:fill_color] = val
2155
3048
  end
2156
3049
 
3050
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#font_color=} instead.
2157
3051
  #: (?untyped val) -> untyped
2158
3052
  def font_color(val = nil)
2159
3053
  if val
@@ -2168,6 +3062,7 @@ module Xlsxrb
2168
3062
  @options[:font_color] = val
2169
3063
  end
2170
3064
 
3065
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#bold=} instead.
2171
3066
  #: (?bool? val) -> bool?
2172
3067
  def bold(val = nil)
2173
3068
  if val.nil?
@@ -2182,6 +3077,7 @@ module Xlsxrb
2182
3077
  @options[:bold] = val ? true : false
2183
3078
  end
2184
3079
 
3080
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#italic=} instead.
2185
3081
  #: (?bool? val) -> bool?
2186
3082
  def italic(val = nil)
2187
3083
  if val.nil?
@@ -2196,6 +3092,7 @@ module Xlsxrb
2196
3092
  @options[:italic] = val ? true : false
2197
3093
  end
2198
3094
 
3095
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#underline=} instead.
2199
3096
  #: (?untyped val) -> untyped
2200
3097
  def underline(val = nil)
2201
3098
  if val.nil?
@@ -2210,22 +3107,63 @@ module Xlsxrb
2210
3107
  @options[:underline] = val
2211
3108
  end
2212
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.
2213
3126
  #: (?untyped val) -> untyped
2214
- def size(val = nil)
3127
+ def font_size(val = nil)
2215
3128
  if val
3129
+ @options[:font_size] = val
2216
3130
  @options[:size] = val
2217
3131
  else
2218
- @options[:size]
3132
+ @options[:font_size] || @options[:size]
2219
3133
  end
2220
3134
  end
2221
3135
 
2222
3136
  #: (untyped val) -> untyped
2223
- def size=(val)
3137
+ def font_size=(val)
3138
+ @options[:font_size] = val
2224
3139
  @options[:size] = val
2225
3140
  end
2226
- alias sz size
2227
- alias sz= size=
2228
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.
2229
3167
  #: (?bool? val) -> bool?
2230
3168
  def stop_if_true(val = nil)
2231
3169
  if val.nil?
@@ -2240,6 +3178,7 @@ module Xlsxrb
2240
3178
  @options[:stop_if_true] = val ? true : false
2241
3179
  end
2242
3180
 
3181
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#priority=} instead.
2243
3182
  #: (?Integer? val) -> Integer?
2244
3183
  def priority(val = nil)
2245
3184
  if val
@@ -2254,6 +3193,7 @@ module Xlsxrb
2254
3193
  @options[:priority] = val.to_i
2255
3194
  end
2256
3195
 
3196
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#above_average=} instead.
2257
3197
  #: (?bool? val) -> bool?
2258
3198
  def above_average(val = nil)
2259
3199
  if val.nil?
@@ -2268,6 +3208,7 @@ module Xlsxrb
2268
3208
  @options[:above_average] = val ? true : false
2269
3209
  end
2270
3210
 
3211
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#equal_average=} instead.
2271
3212
  #: (?bool? val) -> bool?
2272
3213
  def equal_average(val = nil)
2273
3214
  if val.nil?
@@ -2282,6 +3223,7 @@ module Xlsxrb
2282
3223
  @options[:equal_average] = val ? true : false
2283
3224
  end
2284
3225
 
3226
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#std_dev=} instead.
2285
3227
  #: (?Integer? val) -> Integer?
2286
3228
  def std_dev(val = nil)
2287
3229
  if val
@@ -2296,6 +3238,7 @@ module Xlsxrb
2296
3238
  @options[:std_dev] = val.to_i
2297
3239
  end
2298
3240
 
3241
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#rank=} instead.
2299
3242
  #: (?Integer? val) -> Integer?
2300
3243
  def rank(val = nil)
2301
3244
  if val
@@ -2310,6 +3253,7 @@ module Xlsxrb
2310
3253
  @options[:rank] = val.to_i
2311
3254
  end
2312
3255
 
3256
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#percent=} instead.
2313
3257
  #: (?bool? val) -> bool?
2314
3258
  def percent(val = nil)
2315
3259
  if val.nil?
@@ -2324,6 +3268,7 @@ module Xlsxrb
2324
3268
  @options[:percent] = val ? true : false
2325
3269
  end
2326
3270
 
3271
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#bottom=} instead.
2327
3272
  #: (?bool? val) -> bool?
2328
3273
  def bottom(val = nil)
2329
3274
  if val.nil?
@@ -2338,6 +3283,7 @@ module Xlsxrb
2338
3283
  @options[:bottom] = val ? true : false
2339
3284
  end
2340
3285
 
3286
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#text=} instead.
2341
3287
  #: (?String? val) -> String?
2342
3288
  def text(val = nil)
2343
3289
  if val
@@ -2352,6 +3298,7 @@ module Xlsxrb
2352
3298
  @options[:text] = val.to_s
2353
3299
  end
2354
3300
 
3301
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#time_period=} instead.
2355
3302
  #: (?untyped val) -> untyped
2356
3303
  def time_period(val = nil)
2357
3304
  if val
@@ -2366,6 +3313,7 @@ module Xlsxrb
2366
3313
  @options[:time_period] = val
2367
3314
  end
2368
3315
 
3316
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#color_scale=} instead.
2369
3317
  #: (?untyped val) -> untyped
2370
3318
  def color_scale(val = nil)
2371
3319
  if val
@@ -2380,6 +3328,7 @@ module Xlsxrb
2380
3328
  @options[:color_scale] = val
2381
3329
  end
2382
3330
 
3331
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#data_bar=} instead.
2383
3332
  #: (?untyped val) -> untyped
2384
3333
  def data_bar(val = nil)
2385
3334
  if val
@@ -2394,6 +3343,7 @@ module Xlsxrb
2394
3343
  @options[:data_bar] = val
2395
3344
  end
2396
3345
 
3346
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#icon_set=} instead.
2397
3347
  #: (?untyped val) -> untyped
2398
3348
  def icon_set(val = nil)
2399
3349
  if val
@@ -2408,6 +3358,7 @@ module Xlsxrb
2408
3358
  @options[:icon_set] = val
2409
3359
  end
2410
3360
 
3361
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#dxf=} instead.
2411
3362
  #: (?untyped val) -> untyped
2412
3363
  def dxf(val = nil)
2413
3364
  if val
@@ -2422,20 +3373,46 @@ module Xlsxrb
2422
3373
  @options[:dxf] = val
2423
3374
  end
2424
3375
 
3376
+ # Gets or sets the differential format identifier (dxfId).
3377
+ #
3378
+ # @param val [Integer, nil]
3379
+ # @return [Integer, nil]
3380
+ # @api public
2425
3381
  #: (?Integer? val) -> Integer?
2426
- def format_id(val = nil)
3382
+ def dxf_id(val = nil)
2427
3383
  if val
3384
+ @options[:dxf_id] = val.to_i
2428
3385
  @options[:format_id] = val.to_i
2429
3386
  else
2430
- @options[:format_id]
3387
+ @options[:dxf_id] || @options[:format_id]
2431
3388
  end
2432
3389
  end
2433
3390
 
3391
+ # Sets the differential format identifier (dxfId).
3392
+ #
3393
+ # @param val [Integer]
3394
+ # @return [Integer]
3395
+ # @api public
2434
3396
  #: (Integer val) -> Integer
2435
- def format_id=(val)
3397
+ def dxf_id=(val)
3398
+ @options[:dxf_id] = val.to_i
2436
3399
  @options[:format_id] = val.to_i
2437
3400
  end
2438
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
+
2439
3416
  #: () -> Hash[Symbol, untyped]
2440
3417
  def to_h
2441
3418
  @options.dup