xlsxrb 0.1.16 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/README.md +81 -21
  4. data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
  5. data/lib/xlsxrb/chart_builder.rb +619 -98
  6. data/lib/xlsxrb/dsl_helpers.rb +583 -15
  7. data/lib/xlsxrb/elements/cell.rb +265 -53
  8. data/lib/xlsxrb/elements/column.rb +95 -6
  9. data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
  10. data/lib/xlsxrb/elements/image.rb +81 -15
  11. data/lib/xlsxrb/elements/metadata.rb +2733 -0
  12. data/lib/xlsxrb/elements/row.rb +130 -46
  13. data/lib/xlsxrb/elements/styles.rb +184 -76
  14. data/lib/xlsxrb/elements/types.rb +243 -7
  15. data/lib/xlsxrb/elements/workbook.rb +202 -65
  16. data/lib/xlsxrb/elements/worksheet.rb +728 -85
  17. data/lib/xlsxrb/elements.rb +1 -0
  18. data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +32 -3
  19. data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +194 -26
  20. data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +372 -18
  21. data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +33 -14
  22. data/lib/xlsxrb/ooxml/reader.rb +92 -0
  23. data/lib/xlsxrb/ooxml/styles_parser.rb +29 -14
  24. data/lib/xlsxrb/ooxml/workbook_parser.rb +18 -3
  25. data/lib/xlsxrb/ooxml/workbook_writer.rb +351 -77
  26. data/lib/xlsxrb/ooxml/worksheet_parser.rb +18 -4
  27. data/lib/xlsxrb/ooxml/worksheet_writer.rb +349 -103
  28. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +584 -443
  29. data/lib/xlsxrb/ooxml/writer/features_xml.rb +52 -14
  30. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +42 -18
  31. data/lib/xlsxrb/ooxml/writer.rb +288 -35
  32. data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
  33. data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
  34. data/lib/xlsxrb/ooxml/zip_writer.rb +15 -5
  35. data/lib/xlsxrb/stream_row.rb +97 -18
  36. data/lib/xlsxrb/stream_sheet.rb +827 -157
  37. data/lib/xlsxrb/stream_writer.rb +2766 -375
  38. data/lib/xlsxrb/style_builder.rb +821 -105
  39. data/lib/xlsxrb/utils.rb +82 -57
  40. data/lib/xlsxrb/version.rb +1 -1
  41. data/lib/xlsxrb/workbook_builder.rb +542 -62
  42. data/lib/xlsxrb/worksheet_builder.rb +2279 -209
  43. data/lib/xlsxrb.rb +1539 -344
  44. data/sig/generated/xlsxrb/chart_builder.rbs +336 -79
  45. data/sig/generated/xlsxrb/dsl_helpers.rbs +137 -4
  46. data/sig/generated/xlsxrb/elements/cell.rbs +104 -15
  47. data/sig/generated/xlsxrb/elements/column.rbs +62 -3
  48. data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
  49. data/sig/generated/xlsxrb/elements/image.rbs +30 -8
  50. data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
  51. data/sig/generated/xlsxrb/elements/row.rbs +61 -21
  52. data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
  53. data/sig/generated/xlsxrb/elements/types.rbs +29 -0
  54. data/sig/generated/xlsxrb/elements/workbook.rbs +92 -44
  55. data/sig/generated/xlsxrb/elements/worksheet.rbs +259 -38
  56. data/sig/generated/xlsxrb/ooxml/reader/listeners/core_listeners.rbs +2 -0
  57. data/sig/generated/xlsxrb/ooxml/reader/listeners/drawing_listeners.rbs +74 -2
  58. data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +97 -0
  59. data/sig/generated/xlsxrb/ooxml/reader/listeners/style_listeners.rbs +3 -0
  60. data/sig/generated/xlsxrb/ooxml/reader.rbs +20 -0
  61. data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +3 -0
  62. data/sig/generated/xlsxrb/ooxml/workbook_parser.rbs +8 -0
  63. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +8 -4
  64. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +1 -1
  65. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +12 -1
  66. data/sig/generated/xlsxrb/ooxml/writer/drawing_xml.rbs +16 -0
  67. data/sig/generated/xlsxrb/ooxml/writer.rbs +45 -8
  68. data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
  69. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
  70. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -2
  71. data/sig/generated/xlsxrb/stream_row.rbs +48 -14
  72. data/sig/generated/xlsxrb/stream_sheet.rbs +398 -89
  73. data/sig/generated/xlsxrb/stream_writer.rbs +1601 -219
  74. data/sig/generated/xlsxrb/style_builder.rbs +403 -75
  75. data/sig/generated/xlsxrb/utils.rbs +49 -13
  76. data/sig/generated/xlsxrb/workbook_builder.rbs +308 -26
  77. data/sig/generated/xlsxrb/worksheet_builder.rbs +1142 -96
  78. data/sig/generated/xlsxrb.rbs +321 -52
  79. metadata +3 -1
@@ -24,28 +24,81 @@ module Xlsxrb
24
24
  #
25
25
  # @api public
26
26
  class StreamWriter
27
+ OMITTED = Object.new.freeze
28
+ private_constant :OMITTED
29
+
27
30
  # @return [String, nil] Name of the currently active worksheet.
31
+ # @api private
28
32
  #: String?
29
33
  attr_reader :current_sheet
30
34
 
31
35
  # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
36
+ #: bool
32
37
  attr_accessor :escape_formulas
33
38
 
39
+ # Returns whether formula escaping is enabled.
40
+ #
41
+ # @return [Boolean]
42
+ # @api public
43
+ #: () -> bool
44
+ def escape_formulas?
45
+ @escape_formulas ? true : false
46
+ end
47
+
48
+ # Returns whether the shared strings table is enabled.
49
+ #
50
+ # @return [Boolean]
51
+ # @api public
52
+ #: () -> bool
53
+ def shared_strings?
54
+ @shared_strings ? true : false
55
+ end
56
+
57
+ # @deprecated Use {#shared_strings?} instead. Will be removed in 0.2.0.
58
+ #: () -> bool
59
+ def shared_strings
60
+ warn "[DEPRECATION] StreamWriter#shared_strings is deprecated; use #shared_strings? instead.", uplevel: 1
61
+ shared_strings?
62
+ end
63
+
64
+ # @return [Integer] The ZIP deflate compression level (0..9).
65
+ #: Integer
66
+ attr_reader :compression_level
67
+
68
+ # @return [Hash{String => StyleBuilder}]
69
+ #: Hash[String, StyleBuilder]
70
+ attr_reader :styles
71
+
34
72
  # Initializes a streaming writer context.
35
73
  #
36
74
  # @param target [String, IO, StringIO] Destination file path or writable IO stream.
37
75
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
38
76
  # @param escape_formulas [Boolean] Whether to treat strings starting with formula prefixes as plain text.
39
- #: (untyped target, ?strict_excel_mode: bool, ?escape_formulas: bool) -> void
40
- def initialize(target, strict_excel_mode: true, escape_formulas: false)
77
+ # @param default_font [Hash, nil] Optional default font options (e.g. `{ name: "Arial", size: 12 }`).
78
+ # @param shared_strings [Boolean] Whether to intern strings into a shared strings table (`xl/sharedStrings.xml`).
79
+ # When set to `false`, strings are written directly as inline strings (`<c t="inlineStr">`), maintaining flat
80
+ # $O(1)$ constant memory regardless of row count or unique string cardinality. Note that disabling shared strings
81
+ # may slightly increase archive size (typically 3-5%) on datasets with high repetition.
82
+ # @param compression_level [Integer, nil] ZIP deflate compression level (0..9, or Zlib::DEFAULT_COMPRESSION).
83
+ # Level 6 is standard. Level 4 accelerates compression by 20-40% with an ~10% size tradeoff,
84
+ # recommended for high-throughput streaming exports. Level 0 disables compression (store only).
85
+ #: (untyped target, ?strict_excel_mode: bool, ?escape_formulas: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) -> void
86
+ def initialize(target, strict_excel_mode: true, escape_formulas: false, default_font: nil, shared_strings: true, compression_level: Zlib::DEFAULT_COMPRESSION)
41
87
  @target = target
42
88
  @strict_excel_mode = strict_excel_mode
43
89
  @escape_formulas = escape_formulas ? true : false
90
+ @shared_strings = shared_strings ? true : false
91
+ @compression_level = compression_level || Zlib::DEFAULT_COMPRESSION
44
92
  @io = target.is_a?(String) ? File.open(target, "wb") : target
45
93
  @owns_io = target.is_a?(String)
46
- @zip = Ooxml::ZipWriter.new(@io)
47
- @sst = []
48
- @sst_index = {}
94
+ @zip = Ooxml::ZipWriter.new(@io, compression_level: @compression_level)
95
+ if @shared_strings
96
+ @sst = []
97
+ @sst_index = {}
98
+ else
99
+ @sst = nil
100
+ @sst_index = nil
101
+ end
49
102
  @sheets = []
50
103
  @current_sheet = nil
51
104
  @current_sheet_index = 0
@@ -64,6 +117,7 @@ module Xlsxrb
64
117
  @current_pivot_tables = []
65
118
  @current_sparkline_groups = []
66
119
  @current_comments = []
120
+ @current_threaded_comments = []
67
121
  @current_merge_cells = []
68
122
  @current_freeze_pane = nil
69
123
  @current_split_pane = nil
@@ -82,9 +136,18 @@ module Xlsxrb
82
136
  @current_col_breaks = []
83
137
  @current_protected_ranges = []
84
138
  @current_cell_watches = []
139
+ @current_ignored_errors = []
140
+ @current_phonetic_properties = nil
141
+ @current_sheet_calc_pr = nil
142
+ @current_background_image = nil
143
+ @current_print_area = nil
144
+ @current_print_titles = nil
145
+ @current_row_outline_level = nil
146
+ @current_row_collapsed = false
147
+ @current_row_hidden = false
85
148
  @current_cells = {}
86
149
  @styles = {} # { style_name => StyleBuilder }
87
- @style_writer = Ooxml::Writer.new
150
+ @style_writer = Ooxml::Writer.new(default_font: default_font)
88
151
  @style_name_to_id = {}
89
152
  style("__xlsxrb_date", number_format: "yyyy-mm-dd")
90
153
  style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss")
@@ -95,8 +158,109 @@ module Xlsxrb
95
158
  @custom_properties = []
96
159
  @workbook_protection = nil
97
160
  @workbook_properties = { update_links: "never" }
161
+ @active_sheet = nil
162
+ @first_sheet = nil
163
+ @show_sheet_tabs = nil
164
+ @tab_ratio = nil
165
+ end
166
+
167
+ # Gets or sets the active worksheet tab in the workbook window.
168
+ #
169
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
170
+ # @return [String, Symbol, Integer, nil]
171
+ # @api public
172
+ # Gets or sets the active worksheet tab in the workbook window.
173
+ #
174
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#active_sheet=} instead.
175
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
176
+ # @return [String, Symbol, Integer, nil]
177
+ # @api public
178
+ #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
179
+ def active_sheet(name_or_index = OMITTED)
180
+ if name_or_index.equal?(OMITTED)
181
+ @active_sheet
182
+ else
183
+ @active_sheet = name_or_index
184
+ end
185
+ end
186
+ # @deprecated Use {#active_sheet} instead. Will be removed in 0.2.0.
187
+ alias active_tab active_sheet
188
+
189
+ # Sets the active worksheet tab in the workbook window.
190
+ #
191
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
192
+ # @return [String, Symbol, Integer, nil]
193
+ # @api public
194
+ attr_writer :active_sheet #: (String | Symbol | Integer | nil)
195
+ # @deprecated Use {#active_sheet=} instead. Will be removed in 0.2.0.
196
+ alias active_tab= active_sheet=
197
+
198
+ # Gets or sets the first sheet tab visible in the sheet tab scroll area.
199
+ #
200
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#first_sheet=} instead.
201
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
202
+ # @return [String, Symbol, Integer, nil]
203
+ # @api public
204
+ #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
205
+ def first_sheet(name_or_index = OMITTED)
206
+ if name_or_index.equal?(OMITTED)
207
+ @first_sheet
208
+ else
209
+ @first_sheet = name_or_index
210
+ end
211
+ end
212
+
213
+ # Sets the first sheet tab visible in the sheet tab scroll area.
214
+ #
215
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
216
+ # @return [String, Symbol, Integer, nil]
217
+ # @api public
218
+ attr_writer :first_sheet #: (String | Symbol | Integer | nil)
219
+
220
+ # Gets or sets whether sheet tabs are visible in the workbook window.
221
+ #
222
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_sheet_tabs=} instead.
223
+ # @param visible [Boolean, nil]
224
+ # @return [Boolean, nil]
225
+ # @api public
226
+ #: (?bool? visible) -> bool?
227
+ def show_sheet_tabs(visible = OMITTED)
228
+ if visible.equal?(OMITTED)
229
+ @show_sheet_tabs
230
+ else
231
+ @show_sheet_tabs = visible
232
+ end
233
+ end
234
+
235
+ # Sets whether sheet tabs are visible in the workbook window.
236
+ #
237
+ # @param visible [Boolean, nil]
238
+ # @return [Boolean, nil]
239
+ # @api public
240
+ attr_writer :show_sheet_tabs #: bool?
241
+
242
+ # Gets or sets the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
243
+ #
244
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_ratio=} instead.
245
+ # @param ratio [Integer, nil]
246
+ # @return [Integer, nil]
247
+ # @api public
248
+ #: (?Integer? ratio) -> Integer?
249
+ def tab_ratio(ratio = OMITTED)
250
+ if ratio.equal?(OMITTED)
251
+ @tab_ratio
252
+ else
253
+ @tab_ratio = ratio
254
+ end
98
255
  end
99
256
 
257
+ # Sets the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
258
+ #
259
+ # @param ratio [Integer, nil]
260
+ # @return [Integer, nil]
261
+ # @api public
262
+ attr_writer :tab_ratio #: Integer?
263
+
100
264
  # Sets a workbook property.
101
265
  #
102
266
  # @note **SECURITY WARNING:** If you set `:update_links` to anything other than `"never"`,
@@ -111,6 +275,25 @@ module Xlsxrb
111
275
  @workbook_properties[name] = value
112
276
  end
113
277
 
278
+ # Returns workbook-level properties.
279
+ #
280
+ # @return [Elements::WorkbookProperties]
281
+ # @api public
282
+ #: () -> Elements::WorkbookProperties
283
+ def workbook_properties
284
+ Elements::WorkbookProperties.new(**@workbook_properties)
285
+ end
286
+
287
+ # Sets workbook-level properties.
288
+ #
289
+ # @param props [Hash, Elements::MetadataRecord]
290
+ # @return [void]
291
+ # @api public
292
+ #: (untyped props) -> void
293
+ def workbook_properties=(props)
294
+ @workbook_properties = props.is_a?(Elements::MetadataRecord) ? props.to_h : props
295
+ end
296
+
114
297
  # Defines or configures a named cell style.
115
298
  #
116
299
  # @param name [String, Symbol] The name of the style.
@@ -132,6 +315,55 @@ module Xlsxrb
132
315
  style_builder
133
316
  end
134
317
 
318
+ # Sets or configures the workbook-wide default font.
319
+ #
320
+ # @param name [String, Hash, nil] Font name or font options Hash.
321
+ # @param size [Float, Integer, nil] Font size in points.
322
+ # @param opts [Hash] Additional font options (e.g. `bold:`, `italic:`, `family:`, `charset:`, `color:`).
323
+ # @return [void]
324
+ # @api public
325
+ #: (?String | Hash[Symbol, untyped]? name, ?Float | Integer | nil size, **untyped opts) -> void
326
+ def default_font(name = nil, size = nil, **opts)
327
+ @style_writer.default_font(name, size, **opts)
328
+ end
329
+ # @deprecated Use {#default_font} instead. Will be removed in 0.2.0.
330
+ alias set_default_font default_font
331
+
332
+ # Creates an {Elements::Formula} object.
333
+ # @api public
334
+ #: (String expression, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), ?type: (Symbol | String)?, ?ref: String?, ?shared_index: Integer?) -> Elements::Formula
335
+ def formula(...)
336
+ Xlsxrb.formula(...)
337
+ end
338
+
339
+ # Creates an array or dynamic array {Elements::Formula} object.
340
+ # @api public
341
+ #: (String expression, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), **untyped attrs) -> Elements::Formula
342
+ def array_formula(...)
343
+ Xlsxrb.array_formula(...)
344
+ end
345
+
346
+ # Creates a shared formula {Elements::Formula} object.
347
+ # @api public
348
+ #: (?String? expression, ?shared_index: Integer?, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil)) -> Elements::Formula
349
+ def shared_formula(...)
350
+ Xlsxrb.shared_formula(...)
351
+ end
352
+
353
+ # Creates an {Elements::RichText} object.
354
+ # @api public
355
+ #: (*(Hash[Symbol, untyped] | Elements::RichTextRun | String | Array[untyped] | untyped) runs, ?text: String?, ?base_font: untyped, **untyped font_props) -> Elements::RichText
356
+ def rich_text(...)
357
+ Xlsxrb.rich_text(...)
358
+ end
359
+
360
+ # Creates or returns an {Elements::CellError} object.
361
+ # @api public
362
+ #: (String | Symbol | Elements::CellError code) -> Elements::CellError
363
+ def cell_error(...)
364
+ Xlsxrb.cell_error(...)
365
+ end
366
+
135
367
  # Proxy object yielded by the `sheet` method to prevent writing to inactive sheets in streaming mode.
136
368
  #
137
369
  # @api public
@@ -143,6 +375,107 @@ module Xlsxrb
143
375
  @sheet_name = sheet_name
144
376
  end
145
377
 
378
+ # Sets or configures the workbook-wide default font.
379
+ #
380
+ # @param name [String, Hash, nil] Font name or font options Hash.
381
+ # @param size [Float, Integer, nil] Font size in points.
382
+ # @param opts [Hash] Additional font options.
383
+ # @return [void]
384
+ # @api public
385
+ #: (?String | Hash[Symbol, untyped]? name, ?Float | Integer | nil size, **untyped opts) -> void
386
+ def default_font(...)
387
+ @writer.default_font(...)
388
+ end
389
+ # @deprecated Use {#default_font} instead. Will be removed in 0.2.0.
390
+ alias set_default_font default_font
391
+
392
+ # Creates an {Elements::Formula} object.
393
+ # @api public
394
+ #: (String expression, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), ?type: (Symbol | String)?, ?ref: String?, ?shared_index: Integer?) -> Elements::Formula
395
+ def formula(...)
396
+ Xlsxrb.formula(...)
397
+ end
398
+
399
+ # Creates an array or dynamic array {Elements::Formula} object.
400
+ # @api public
401
+ #: (String expression, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), **untyped attrs) -> Elements::Formula
402
+ def array_formula(...)
403
+ Xlsxrb.array_formula(...)
404
+ end
405
+
406
+ # Creates a shared formula {Elements::Formula} object.
407
+ # @api public
408
+ #: (?String? expression, ?shared_index: Integer?, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil)) -> Elements::Formula
409
+ def shared_formula(...)
410
+ Xlsxrb.shared_formula(...)
411
+ end
412
+
413
+ # Creates an {Elements::RichText} object.
414
+ # @api public
415
+ #: (*(Hash[Symbol, untyped] | Elements::RichTextRun | String | Array[untyped] | untyped) runs, ?text: String?, ?base_font: untyped, **untyped font_props) -> Elements::RichText
416
+ def rich_text(...)
417
+ Xlsxrb.rich_text(...)
418
+ end
419
+
420
+ # Creates or returns an {Elements::CellError} object.
421
+ # @api public
422
+ #: (String | Symbol | Elements::CellError code) -> Elements::CellError
423
+ def cell_error(...)
424
+ Xlsxrb.cell_error(...)
425
+ end
426
+
427
+ # Returns the worksheet name.
428
+ #
429
+ # @return [String]
430
+ # @api public
431
+ #: () -> String
432
+ def name
433
+ @sheet_name
434
+ end
435
+
436
+ # Returns column configurations defined for this worksheet.
437
+ #
438
+ # @return [Array<Elements::Column>]
439
+ # @api public
440
+ #: () -> Array[Elements::Column]
441
+ def columns
442
+ @writer.columns
443
+ end
444
+
445
+ # Returns the list of worksheet names created in this workbook so far.
446
+ #
447
+ # @return [Array<String>] Worksheet names.
448
+ # @api public
449
+ #: () -> Array[String]
450
+ def sheet_names
451
+ @writer.sheet_names
452
+ end
453
+
454
+ # Returns whether formula escaping is enabled.
455
+ #
456
+ # @return [Boolean]
457
+ # @api public
458
+ #: () -> bool
459
+ def escape_formulas?
460
+ @writer.escape_formulas?
461
+ end
462
+
463
+ # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
464
+ #: bool
465
+ def escape_formulas
466
+ @writer.escape_formulas
467
+ end
468
+
469
+ # Sets whether to treat strings starting with formula prefixes as plain text.
470
+ #
471
+ # @param val [Boolean]
472
+ # @return [Boolean]
473
+ # @api public
474
+ #: (bool val) -> bool
475
+ def escape_formulas=(val, ...)
476
+ @writer.escape_formulas = val
477
+ end
478
+
146
479
  # Defines or configures a named cell style on the active sheet.
147
480
  #
148
481
  # @example
@@ -166,10 +499,8 @@ module Xlsxrb
166
499
  # @example Merge with cell reference string
167
500
  # s.merge("A1:C1")
168
501
  #
169
- # @example Merge with coordinates
170
- # s.merge(row: 0, col_start: 0, col_end: 2)
171
- #
172
- # @param range [String, nil] The cell range (e.g. "A1:B2").
502
+ # @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.
503
+ # @param range [String, Hash, nil] The cell range (e.g. "A1:B2").
173
504
  # @param row [Integer, nil] 0-based row index.
174
505
  # @param col_start [Integer, String, nil] 0-based start column index or letter.
175
506
  # @param col_end [Integer, String, nil] 0-based end column index or letter.
@@ -177,7 +508,7 @@ module Xlsxrb
177
508
  # @param row_end [Integer, nil] 0-based end row index.
178
509
  # @return [void]
179
510
  # @api public
180
- #: (?String? range, ?row: Integer | nil, ?col_start: (Integer | String)?, ?col_end: (Integer | String)?, ?row_start: Integer | nil, ?row_end: Integer | nil) -> void
511
+ #: (?(String | Hash[Symbol, Integer | String])? range, ?row: Integer | nil, ?col_start: (Integer | String)?, ?col_end: (Integer | String)?, ?row_start: Integer | nil, ?row_end: Integer | nil) -> void
181
512
  def merge(...)
182
513
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
183
514
 
@@ -191,14 +522,16 @@ module Xlsxrb
191
522
  #
192
523
  # @param preset [String] Preset shape type (e.g. "rect", "ellipse").
193
524
  # @param text [String, nil] Shape label text.
194
- # @param from_col [Integer] Starting column index (0-based).
525
+ # @param from_column [Integer, nil] Starting column index (0-based).
526
+ # @param from_col [Integer, nil] Deprecated alias for from_column.
195
527
  # @param from_row [Integer] Starting row index (0-based).
196
- # @param to_col [Integer] Ending column index (0-based).
528
+ # @param to_column [Integer, nil] Ending column index (0-based).
529
+ # @param to_col [Integer, nil] Deprecated alias for to_column.
197
530
  # @param to_row [Integer] Ending row index (0-based).
198
531
  # @param opts [Hash] Additional shape formatting options.
199
532
  # @return [void]
200
533
  # @api public
201
- #: (?preset: String, ?text: String?, ?from_col: Integer, ?from_row: Integer, ?to_col: Integer, ?to_row: Integer, **untyped opts) -> void
534
+ #: (?preset: String, ?text: String?, ?from_column: Integer?, ?from_col: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_col: Integer?, ?to_row: Integer, **untyped opts) -> void
202
535
  def shape(...)
203
536
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
204
537
 
@@ -207,6 +540,7 @@ module Xlsxrb
207
540
 
208
541
  # simplecov:disable
209
542
  # Edge case / untested delegation block
543
+ # @api private
210
544
  #: (*untyped args, **untyped kwargs) ?{ (*untyped) -> untyped } -> untyped
211
545
  def internal_sheet_setup(...)
212
546
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
@@ -221,24 +555,36 @@ module Xlsxrb
221
555
  # s.row(["Name", "Age", "City"])
222
556
  #
223
557
  # @example Write with explicit column keys and styles
224
- # s.row({ A: "Header", C: 100 }, styles: { A: :bold })
558
+ # s.row({ A: "Header", C: 100 }, cell_styles: { A: :bold })
225
559
  #
226
560
  # @param values [Array, Hash] The cell values (e.g. `[1, 2, 3]` or `{ A: 1, C: 3 }`).
227
- # @param styles [String, Symbol, Array, Hash, nil] Style names or hashes to apply.
561
+ # @param cell_styles [String, Symbol, Array, Hash, nil] Style names or hashes to apply to cells.
562
+ # @param row_style [Integer, Symbol, String, Hash, nil] Row style format or index.
228
563
  # @param height [Float, Integer, nil] The row height in points (0 - 409).
229
564
  # @param hidden [Boolean] Whether the row is hidden.
230
565
  # @param custom_height [Boolean] Whether to flag as custom height.
231
566
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
232
567
  # @param collapsed [Boolean] Whether the row is collapsed.
233
- # @param style [Integer, Symbol, String, Hash, nil] Row style format or index.
568
+ # @param styles [String, Symbol, Array, Hash, nil] Deprecated. Use cell_styles: instead.
569
+ # @param style [Integer, Symbol, String, Hash, nil] Deprecated. Use row_style: instead.
234
570
  # @return [void]
235
571
  # @api public
236
- #: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: untyped) -> void
237
- def row(values, styles: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil, style: nil)
572
+ #: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?styles: untyped, ?style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
573
+ 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)
238
574
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
239
575
 
240
- @writer.row(values, styles: styles, height: height, hidden: hidden, custom_height: custom_height, collapsed: collapsed, outline_level: outline_level, style: style)
576
+ if styles
577
+ warn "[DEPRECATION] WorksheetProxy#row keyword :styles is deprecated; use :cell_styles instead.", uplevel: 1
578
+ cell_styles ||= styles
579
+ end
580
+ if style
581
+ warn "[DEPRECATION] WorksheetProxy#row keyword :style is deprecated; use :row_style instead.", uplevel: 1
582
+ row_style ||= style
583
+ end
584
+
585
+ @writer.row(values, cell_styles: cell_styles, row_style: row_style, height: height, hidden: hidden, custom_height: custom_height, collapsed: collapsed, outline_level: outline_level)
241
586
  end
587
+ # @deprecated Use {#row} instead. Will be removed in 0.2.0.
242
588
  alias add_row row
243
589
 
244
590
  # Appends a row to the worksheet and returns self for chaining.
@@ -255,28 +601,128 @@ module Xlsxrb
255
601
  self
256
602
  end
257
603
 
604
+ # Advances the row cursor by count without writing empty row elements.
605
+ #
606
+ # @example Skip one row
607
+ # s.skip_row
608
+ #
609
+ # @example Skip multiple rows
610
+ # s.skip_rows(3)
611
+ #
612
+ # @param count [Integer] Number of rows to skip (must be >= 1).
613
+ # @return [void]
614
+ # @api public
615
+ #: (?Integer count) -> void
616
+ def skip_rows(count = 1)
617
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
618
+
619
+ @writer.skip_rows(count)
620
+ end
621
+ # @deprecated Use {#skip_rows} instead. Will be removed in 0.2.0.
622
+ alias skip_row skip_rows
623
+
258
624
  # Configures column width and properties.
259
625
  #
260
626
  # @example Set column A width
261
627
  # s.column(0, width: 25.0)
262
628
  #
263
- # @param col_index [Integer, String, Symbol] 0-based column index or letter (e.g. 0 or "A" or :A).
629
+ # @param index [Integer, String, Symbol, Range, Array] 0-based column index, letter ("A", :A), range, or array.
264
630
  # @param width [Float, Integer, nil] Column width in characters.
265
631
  # @param hidden [Boolean] Whether the column is hidden.
266
- # @param best_fit [Boolean] Whether the column automatically fits content.
267
632
  # @param custom_width [Boolean] Whether to flag as custom width.
268
633
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
269
634
  # @param collapsed [Boolean] Whether the outline group is collapsed.
270
635
  # @param style [Integer, Symbol, String, Hash, nil] Column style format or index.
636
+ # @param best_fit [Boolean] Whether the column automatically fits content.
271
637
  # @return [void]
272
638
  # @api public
273
- #: (Integer | String | Symbol | Range[Integer | String] | Array[Integer | String] col_index, ?width: Float | Integer | nil, ?hidden: bool, ?best_fit: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
639
+ #: (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
274
640
  def column(...)
275
641
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
276
642
 
277
643
  @writer.column(...)
278
644
  end
279
645
 
646
+ # Groups multiple columns together with outline hierarchy.
647
+ #
648
+ # @param index [Integer, String, Range, Array] Column index, letter, range, or array.
649
+ # @param level [Integer] Grouping outline level (1 to 7).
650
+ # @param collapsed [Boolean] Whether the group is collapsed.
651
+ # @param hidden [Boolean] Whether the columns are hidden.
652
+ # @param width [Float, Integer, nil] Optional column width.
653
+ # @param style [Integer, Symbol, String, nil] Optional column style.
654
+ # @return [void]
655
+ # @api public
656
+ #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?level: Integer, ?collapsed: bool, ?hidden: bool, ?width: Float | Integer | nil, ?style: untyped) -> void
657
+ def group_columns(...)
658
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
659
+
660
+ @writer.group_columns(...)
661
+ end
662
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
663
+ alias group_column group_columns
664
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
665
+ alias group_cols group_columns
666
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
667
+ alias group_col group_columns
668
+
669
+ # Groups multiple rows with outline hierarchy with a block.
670
+ #
671
+ # @param rows [Range, Array, Integer, nil] Unused in streaming write.
672
+ # @param level [Integer] Grouping outline level (1 to 7).
673
+ # @param collapsed [Boolean] Whether the group is collapsed.
674
+ # @param hidden [Boolean] Whether the rows are hidden.
675
+ # @yield Optional block executed with active group outline settings.
676
+ # @return [void]
677
+ # @api public
678
+ #: (?untyped rows, ?level: Integer, ?collapsed: bool, ?hidden: bool) ?{ (self) -> void } -> void
679
+ def group_rows(rows = nil, level: 1, collapsed: false, hidden: false)
680
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
681
+
682
+ if block_given?
683
+ @writer.group_rows(rows, level: level, collapsed: collapsed, hidden: hidden) do
684
+ yield self
685
+ end
686
+ else
687
+ @writer.group_rows(rows, level: level, collapsed: collapsed, hidden: hidden)
688
+ end
689
+ end
690
+ # @deprecated Use {#group_rows} instead. Will be removed in 0.2.0.
691
+ alias group_row group_rows
692
+
693
+ # Configures worksheet-level outline and grouping view properties.
694
+ #
695
+ # @param summary_below [Boolean, nil] Summary rows below detail rows.
696
+ # @param summary_right [Boolean, nil] Summary columns to the right of detail columns.
697
+ # @param show_outline_symbols [Boolean, nil] Outline symbols visible.
698
+ # @param show_symbols [Boolean, nil] Deprecated alias for show_outline_symbols.
699
+ # @param apply_styles [Boolean, nil] Automatic styles applied.
700
+ # @param opts [Hash] Additional options.
701
+ # @return [void]
702
+ # @api public
703
+ #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
704
+ def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, show_symbols: nil, apply_styles: nil, **opts)
705
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
706
+
707
+ warn "[Xlsxrb DEPRECATION] outline_properties keyword show_symbols: is deprecated; use show_outline_symbols: instead.", uplevel: 1 unless show_symbols.nil?
708
+ @writer.outline_properties(summary_below: summary_below, summary_right: summary_right, show_outline_symbols: show_outline_symbols || show_symbols, apply_styles: apply_styles, **opts)
709
+ end
710
+ # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
711
+ alias outline_pr outline_properties
712
+
713
+ # Sets worksheet outline and grouping view properties.
714
+ #
715
+ # @param opts [Hash] Outline properties.
716
+ # @return [void]
717
+ # @api public
718
+ #: (Hash[Symbol, untyped] opts) -> void
719
+ def outline_properties=(opts)
720
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
721
+
722
+ @writer.outline_properties = opts
723
+ end
724
+ alias outline_pr= outline_properties=
725
+
280
726
  # Adds a chart to the active sheet.
281
727
  #
282
728
  # @example
@@ -286,12 +732,12 @@ module Xlsxrb
286
732
  # end
287
733
  #
288
734
  # @param type [Symbol, String, nil] The chart type (:bar, :col, :line, :pie, :scatter, :area, :doughnut, :radar).
289
- # @param opts [Hash] Additional chart options.
735
+ # @param options [Hash] Additional chart options.
290
736
  # @yield [chart_builder]
291
737
  # @yieldparam chart_builder [Xlsxrb::ChartBuilder]
292
738
  # @return [void]
293
739
  # @api public
294
- #: (?Symbol | String? type, **untyped opts) ?{ (Xlsxrb::ChartBuilder) -> void } -> void
740
+ #: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
295
741
  def chart(...)
296
742
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
297
743
 
@@ -325,26 +771,38 @@ module Xlsxrb
325
771
  # @example
326
772
  # s.auto_filter("A1:D100")
327
773
  #
328
- # @param ref [String] The cell range (e.g. "A1:D10").
774
+ # @param range [String, nil] The cell range (e.g. "A1:D10").
329
775
  # @return [void]
330
776
  # @api public
331
- #: (String ref) -> void
777
+ #: (String? range) -> void
332
778
  def auto_filter(...)
333
779
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
334
780
 
335
781
  @writer.auto_filter(...)
336
782
  end
337
783
 
784
+ # Sets the auto-filter range on the active sheet.
785
+ #
786
+ # @param range [String, nil] The cell range (e.g. "A1:D10").
787
+ # @return [String, nil]
788
+ # @api public
789
+ #: (String? range) -> String?
790
+ def auto_filter=(range)
791
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
792
+
793
+ @writer.auto_filter = range
794
+ end
795
+
338
796
  # Sets filter criteria for a column in the auto-filter.
339
797
  #
340
798
  # @example Simple values filter
341
799
  # s.filter_column(0, ["Active", "Pending"])
342
800
  #
343
- # @param col_id [Integer] 0-based column index relative to auto-filter range.
344
- # @param filter_values [Array<String>, Hash] Values or filter specification hash.
801
+ # @param col_id [Integer, String, Symbol] 0-based column index relative to auto-filter range or column letter.
802
+ # @param filter [Hash] Values or filter specification hash.
345
803
  # @return [void]
346
804
  # @api public
347
- #: (Integer col_id, Array[String] | Hash[Symbol, untyped] filter_values) -> void
805
+ #: (Integer | String | Symbol col_id, Hash[untyped, untyped] filter) -> void
348
806
  def filter_column(...)
349
807
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
350
808
 
@@ -357,26 +815,36 @@ module Xlsxrb
357
815
  # s.sort_state("A1:A10", [{ ref: "A1:A10", descending: true }])
358
816
  #
359
817
  # @param ref [String] The range to sort.
360
- # @param sort_conditions [Array<Hash>, Hash] Sort conditions array or options hash.
818
+ # @param sort_conditions [Array<Hash>] Sort conditions array.
361
819
  # @param opts [Hash] Additional sort options.
362
820
  # @return [void]
363
821
  # @api public
364
- #: (String ref, Array[Hash[Symbol, untyped]] | Hash[Symbol, untyped] sort_conditions, **untyped opts) -> void
822
+ #: (String ref, Array[Hash[untyped, untyped]] sort_conditions, **untyped opts) -> void
365
823
  def sort_state(...)
366
824
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
367
825
 
368
826
  @writer.sort_state(...)
369
827
  end
370
828
 
371
- # Adds data validation rules to a range.
829
+ # Sets column sort state for the sheet.
372
830
  #
373
- # Adds data validation to a cell or range.
831
+ # @param opts [Elements::SortState, Hash, nil] Sort state options.
832
+ # @return [void]
833
+ # @api public
834
+ #: (untyped opts) -> void
835
+ def sort_state=(opts)
836
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
837
+
838
+ @writer.sort_state = opts
839
+ end
840
+
841
+ # Adds data validation rules to a range.
374
842
  #
375
843
  # @example Dropdown list validation
376
- # s.validate_data("B2:B100", type: "list", formula1: '"High,Medium,Low"')
844
+ # s.data_validation("B2:B100", type: "list", formula1: '"High,Medium,Low"')
377
845
  #
378
846
  # @example Block syntax
379
- # s.validate_data("B2:B100") do |dv|
847
+ # s.data_validation("B2:B100") do |dv|
380
848
  # dv.type :list
381
849
  # dv.formula1 '"High,Medium,Low"'
382
850
  # end
@@ -388,10 +856,17 @@ module Xlsxrb
388
856
  # @return [void]
389
857
  # @api public
390
858
  #: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
391
- def validate_data(...)
859
+ def data_validation(...)
392
860
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
393
861
 
394
- @writer.validate_data(...)
862
+ @writer.data_validation(...)
863
+ end
864
+
865
+ # @deprecated Use {#data_validation} instead.
866
+ #: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
867
+ def validate_data(...)
868
+ warn "[DEPRECATION] `validate_data` is deprecated; use `data_validation` instead.", uplevel: 1
869
+ data_validation(...)
395
870
  end
396
871
 
397
872
  # Adds conditional formatting to a range.
@@ -399,16 +874,23 @@ module Xlsxrb
399
874
  # @example Highlight values greater than 100
400
875
  # s.conditional_format("A1:A10", type: "cellIs", operator: "greaterThan", formula: 100, style: :highlight)
401
876
  #
402
- # @param range [String] The cell range (e.g. "A1:A10").
403
- # @param type [String, Symbol] Rule type ("cellIs", "colorScale", "dataBar", "expression").
877
+ # @example Hierarchical differential format (dxf)
878
+ # s.conditional_format("B2:B20", type: :cell_is, operator: "equal", formula: "0",
879
+ # dxf: { font: { bold: false, color: { auto: true } }, fill: { pattern: "none", bg_color: "FFFF00" } })
880
+ #
881
+ # @param sqref [String, nil] The cell range (e.g. "A1:A10").
882
+ # @param type [String, Symbol, nil] Rule type ("cellIs", "colorScale", "dataBar", "expression").
404
883
  # @param opts [Hash] Rule options.
884
+ # @option opts [Hash] :dxf Hierarchical differential format specification.
885
+ # @option opts [Integer] :format_id Pre-registered differential format index (dxfId).
886
+ # @yield [conditional_format_builder] Optional block for configuration.
405
887
  # @return [void]
406
888
  # @api public
407
- #: (String range, ?type: String | Symbol, **untyped opts) -> void
408
- def conditional_format(...)
889
+ #: (?String? sqref, ?type: String | Symbol, **untyped opts) ?{ (ConditionalFormatBuilder) -> void } -> void
890
+ def conditional_format(sqref = nil, **opts, &)
409
891
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
410
892
 
411
- @writer.conditional_format(...)
893
+ @writer.conditional_format(sqref, **opts, &)
412
894
  end
413
895
 
414
896
  # Adds a formatted Excel Table to the sheet.
@@ -440,6 +922,7 @@ module Xlsxrb
440
922
 
441
923
  # simplecov:disable
442
924
  # Edge case / untested delegation block
925
+ # @api private
443
926
  #: () -> void
444
927
  def cleanup!(...)
445
928
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
@@ -465,20 +948,39 @@ module Xlsxrb
465
948
  @writer.comment(...)
466
949
  end
467
950
 
951
+ # Adds a threaded comment to a cell.
952
+ #
953
+ # @param cell [String, Integer] The cell reference (e.g. "A1").
954
+ # @param text [String] The comment text.
955
+ # @param author [String] The author name.
956
+ # @param opts [Hash] Options: timestamp, id, parent_id, done, user_id, provider_id.
957
+ # @return [void]
958
+ # @api public
959
+ #: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
960
+ def threaded_comment(...)
961
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
962
+
963
+ @writer.threaded_comment(...)
964
+ end
965
+ # @deprecated Use {#threaded_comment} instead. Will be removed in 0.2.0.
966
+ alias add_threaded_comment threaded_comment
967
+
468
968
  # Adds a Pivot Table to the sheet.
469
969
  #
470
970
  # @param source_ref [String] Source data range reference (e.g. "Sheet1!A1:D100").
471
971
  # @param row_fields [Array<String>] Field names for rows.
472
972
  # @param data_fields [Array<String>] Field names for data values.
473
- # @param col_fields [Array<String>] Field names for columns.
474
- # @param dest_ref [String] Target top-left cell reference (default: "E1").
973
+ # @param column_fields [Array<String>] Field names for columns.
974
+ # @param col_fields [Array<String>] Deprecated alias for column_fields.
975
+ # @param ref [String] Target top-left cell reference (default: "E1").
976
+ # @param dest_ref [String] Deprecated alias for ref.
475
977
  # @param name [String, nil] Pivot table name.
476
978
  # @param field_names [Array<String>, nil] Override field names.
477
979
  # @param items [Array, nil] Items configuration.
478
980
  # @param opts [Hash] Additional options.
479
981
  # @return [void]
480
982
  # @api public
481
- #: (String source_ref, row_fields: untyped, data_fields: untyped, ?col_fields: untyped, ?dest_ref: String, ?name: String?, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
983
+ #: (String source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?col_fields: untyped, ?ref: String?, ?dest_ref: String?, ?name: String?, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
482
984
  def pivot_table(...)
483
985
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
484
986
 
@@ -517,10 +1019,12 @@ module Xlsxrb
517
1019
  # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
518
1020
  # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
519
1021
  # @param opts [Hash] Additional sparkline options.
1022
+ # @deprecated Use {#sparkline_group} instead. Will be removed in 0.2.0.
520
1023
  # @return [void]
521
1024
  # @api public
522
1025
  #: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
523
1026
  def add_sparkline(...)
1027
+ warn "[DEPRECATION] #add_sparkline is deprecated; use #sparkline_group instead.", uplevel: 1
524
1028
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
525
1029
 
526
1030
  @writer.add_sparkline(...)
@@ -528,166 +1032,434 @@ module Xlsxrb
528
1032
 
529
1033
  # Sets workbook-level properties.
530
1034
  #
531
- # @param opts [Hash] Workbook property options.
1035
+ # @param name [Symbol] Workbook property name.
1036
+ # @param value [String, Integer, Boolean] Property value.
532
1037
  # @return [void]
533
1038
  # @api public
534
- #: (**untyped opts) -> void
1039
+ #: (Symbol name, String | Integer | bool value) -> void
535
1040
  def workbook_property(...)
536
1041
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
537
1042
 
538
1043
  @writer.workbook_property(...)
539
1044
  end
540
1045
 
541
- # Sets sheet properties (e.g. tab color, page setup flags).
542
- #
543
- # @example
544
- # s.sheet_properties(:tab_color, "FF0000")
1046
+ # Sets or gets the active sheet in the workbook window.
1047
+ # If called without arguments on the proxy, marks this sheet as the active sheet.
545
1048
  #
546
- # @param name [Symbol, String] Property name.
547
- # @param value [Object] Property value.
548
- # @return [void]
1049
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#active_sheet=} instead.
1050
+ # @param name_or_index [String, Symbol, Integer, nil]
1051
+ # @return [String, Symbol, Integer, nil]
549
1052
  # @api public
550
- #: (Symbol | String name, untyped value) -> void
551
- def sheet_properties(...)
1053
+ #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1054
+ def active_sheet(name_or_index = @sheet_name)
552
1055
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
553
1056
 
554
- @writer.sheet_properties(...)
1057
+ @writer.active_sheet(name_or_index)
555
1058
  end
1059
+ # @deprecated Use {#active_sheet} instead. Will be removed in 0.2.0.
1060
+ alias active_tab active_sheet
556
1061
 
557
- # Adds a defined named range or formula.
558
- #
559
- # @example
560
- # s.defined_name("TaxRate", "0.10")
1062
+ # Sets the active worksheet tab in the workbook window.
561
1063
  #
562
- # @param name [String] The name.
563
- # @param formula [String] The formula or range expression.
564
- # @param sheet_id [Integer, nil] Optional sheet scope.
565
- # @param hidden [Boolean] Whether the name is hidden.
566
- # @return [void]
1064
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
1065
+ # @return [String, Symbol, Integer, nil]
567
1066
  # @api public
568
- #: (String name, String formula, ?sheet_id: Integer | nil, ?hidden: bool) -> void
569
- def defined_name(...)
1067
+ #: (String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1068
+ def active_sheet=(name_or_index)
570
1069
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
571
1070
 
572
- @writer.defined_name(...)
1071
+ @writer.active_sheet = name_or_index
573
1072
  end
1073
+ # @deprecated Use {#active_sheet=} instead. Will be removed in 0.2.0.
1074
+ alias active_tab= active_sheet=
574
1075
 
575
- # Freezes rows and/or columns for scrolling.
576
- #
577
- # @example Freeze top row
578
- # s.freeze_pane(row: 1)
1076
+ # Sets or gets the first visible sheet in the tab bar.
579
1077
  #
580
- # @example Freeze first column and top 2 rows
581
- # s.freeze_pane(row: 2, col: 1)
582
- #
583
- # @param row [Integer, nil] Number of rows to freeze.
584
- # @param col [Integer, nil] Number of columns to freeze.
585
- # @return [void]
1078
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#first_sheet=} instead.
1079
+ # @param name_or_index [String, Symbol, Integer, nil]
1080
+ # @return [String, Symbol, Integer, nil]
586
1081
  # @api public
587
- #: (?row: Integer | nil, ?col: Integer | nil) -> void
588
- def freeze_pane(...)
1082
+ #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1083
+ def first_sheet(name_or_index = @sheet_name)
589
1084
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
590
1085
 
591
- @writer.freeze_pane(...)
1086
+ @writer.first_sheet(name_or_index)
592
1087
  end
593
1088
 
594
- # simplecov:disable
595
- # Edge case / untested delegation block
596
- # Sets the print area range for the sheet.
1089
+ # Sets the first visible sheet in the tab bar.
597
1090
  #
598
- # @param ref [String] Range reference.
599
- # @return [void]
1091
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
1092
+ # @return [String, Symbol, Integer, nil]
600
1093
  # @api public
601
- #: (String ref) -> void
602
- def print_area(...)
1094
+ #: (String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
1095
+ def first_sheet=(name_or_index)
603
1096
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
604
1097
 
605
- @writer.print_area(...)
1098
+ @writer.first_sheet = name_or_index
606
1099
  end
607
- # simplecov:enable
608
1100
 
609
- # simplecov:disable
610
- # Edge case / untested delegation block
611
- # Configures repeating title rows and columns for printing.
1101
+ # Sets or gets whether sheet tabs are visible in the workbook window.
612
1102
  #
613
- # @param rows [String, nil] Row range to repeat (e.g. "1:2").
614
- # @param cols [String, nil] Column range to repeat (e.g. "A:B").
615
- # @return [void]
1103
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_sheet_tabs=} instead.
1104
+ # @param visible [Boolean, nil]
1105
+ # @return [Boolean, nil]
616
1106
  # @api public
617
- #: (?rows: String?, ?cols: String?) -> void
618
- def print_titles(...)
1107
+ #: (?bool? visible) -> bool?
1108
+ def show_sheet_tabs(visible = nil)
619
1109
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
620
1110
 
621
- @writer.print_titles(...)
1111
+ @writer.show_sheet_tabs(visible)
622
1112
  end
623
1113
 
624
- # Sets repeating title rows to appear at the top of each printed page.
1114
+ # Sets whether sheet tabs are visible in the workbook window.
625
1115
  #
626
- # @param first [Integer, String] First row index (0-based) or range string (e.g. "1:2").
627
- # @param last [Integer, String, nil] Optional last row index (0-based).
628
- # @return [void]
1116
+ # @param visible [Boolean, nil]
1117
+ # @return [Boolean, nil]
629
1118
  # @api public
630
- #: (Integer | String first, ?(Integer | String)? last) -> void
631
- def repeat_rows(first, last = nil)
1119
+ #: (bool? visible) -> bool?
1120
+ def show_sheet_tabs=(visible)
632
1121
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
633
1122
 
634
- @writer.repeat_rows(first, last, sheet: @sheet_name)
1123
+ @writer.show_sheet_tabs = visible
635
1124
  end
636
1125
 
637
- # Sets repeating title columns to appear at the left of each printed page.
1126
+ # Sets or gets the tab ratio between tab bar and horizontal scrollbar (0-1000).
638
1127
  #
639
- # @param first [Integer, String] First column index (0-based) or column name/range.
640
- # @param last [Integer, String, nil] Optional last column index/name.
641
- # @return [void]
1128
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_ratio=} instead.
1129
+ # @param ratio [Integer, nil]
1130
+ # @return [Integer, nil]
642
1131
  # @api public
643
- #: (Integer | String first, ?(Integer | String)? last) -> void
644
- def repeat_columns(first, last = nil)
1132
+ #: (?Integer? ratio) -> Integer?
1133
+ def tab_ratio(ratio = nil)
645
1134
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
646
1135
 
647
- @writer.repeat_columns(first, last, sheet: @sheet_name)
1136
+ @writer.tab_ratio(ratio)
648
1137
  end
649
- # simplecov:enable
650
1138
 
651
- # Splits sheet view into panes.
1139
+ # Sets the tab ratio between tab bar and horizontal scrollbar (0-1000).
652
1140
  #
653
- # @param x_split [Numeric, nil] Horizontal split position.
654
- # @param y_split [Numeric, nil] Vertical split position.
655
- # @param top_left_cell [String, nil] Top-left visible cell in bottom-right pane.
656
- # @param active_pane [String, nil] Active pane identifier.
657
- # @param state [String, nil] Split state.
658
- # @return [void]
1141
+ # @param ratio [Integer, nil]
1142
+ # @return [Integer, nil]
659
1143
  # @api public
660
- #: (?x_split: Numeric | nil, ?y_split: Numeric | nil, ?top_left_cell: String?, ?active_pane: String?, ?state: String?) -> void
661
- def split_pane(...)
1144
+ #: (Integer? ratio) -> Integer?
1145
+ def tab_ratio=(ratio)
662
1146
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
663
1147
 
664
- @writer.split_pane(...)
1148
+ @writer.tab_ratio = ratio
665
1149
  end
666
1150
 
667
- # simplecov:disable
668
- # Edge case / untested delegation block
669
- # Protects the workbook structure.
1151
+ # Gets or sets the sheet visibility state (:visible, :hidden, or :very_hidden).
670
1152
  #
671
- # @param opts [Hash] Protection options.
672
- # @return [void]
1153
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#state=} instead.
1154
+ # @param new_state [Symbol, nil] The new state.
1155
+ # @return [Symbol]
673
1156
  # @api public
674
- #: (**untyped opts) -> void
675
- def protect_workbook(...)
1157
+ #: (?Symbol? new_state) -> Symbol
1158
+ def state(new_state = nil)
676
1159
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
677
1160
 
678
- @writer.protect_workbook(...)
1161
+ @writer.state(new_state)
679
1162
  end
680
- # simplecov:enable
681
1163
 
682
- # simplecov:disable
683
- # Edge case / untested delegation block
684
- # Sets core metadata property.
1164
+ # Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
685
1165
  #
686
- # @param name [String, Symbol] Property name.
1166
+ # @param new_state [Symbol, String] The new state.
1167
+ # @return [Symbol]
1168
+ # @api public
1169
+ #: (Symbol | String new_state) -> Symbol
1170
+ def state=(new_state)
1171
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1172
+
1173
+ @writer.state = new_state
1174
+ @writer.state
1175
+ end
1176
+
1177
+ # Gets or sets the tab color of this worksheet.
1178
+ #
1179
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_color=} instead.
1180
+ # @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
1181
+ # @param opts [Hash] Color keyword arguments (e.g. theme: 1, tint: 0.5).
1182
+ # @return [String, Hash, nil]
1183
+ # @api public
1184
+ #: (?String | Symbol | Hash[Symbol, untyped] | nil spec, **untyped opts) -> (String | Hash[Symbol, untyped] | nil)
1185
+ def tab_color(...)
1186
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1187
+
1188
+ @writer.tab_color(...)
1189
+ end
1190
+
1191
+ # Sets the tab color of this worksheet.
1192
+ #
1193
+ # @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
1194
+ # @return [String, Hash, nil]
1195
+ # @api public
1196
+ #: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
1197
+ def tab_color=(spec)
1198
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1199
+
1200
+ @writer.tab_color = spec
1201
+ end
1202
+
1203
+ # Sets a single sheet property.
1204
+ #
1205
+ # @param name [Symbol, String] Property name.
687
1206
  # @param value [Object] Property value.
688
1207
  # @return [void]
689
1208
  # @api public
690
- #: (String | Symbol name, untyped value) -> void
1209
+ #: (Symbol | String name, untyped value) -> void
1210
+ def sheet_property(...)
1211
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1212
+
1213
+ @writer.sheet_property(...)
1214
+ end
1215
+
1216
+ # Sets sheet properties (e.g. tab color, page setup flags). Accepts kwargs or name/value pair.
1217
+ #
1218
+ # @example
1219
+ # s.sheet_properties(tab_color: "FF0000")
1220
+ #
1221
+ # @param name [Symbol, String, Hash, nil] Property name or hash.
1222
+ # @param value [Object, nil] Property value.
1223
+ # @param opts [Hash] Additional options.
1224
+ # @return [void]
1225
+ # @api public
1226
+ #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> void
1227
+ def sheet_properties(...)
1228
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1229
+
1230
+ @writer.sheet_properties(...)
1231
+ end
1232
+
1233
+ # Replaces worksheet properties.
1234
+ # @param opts [Hash, Elements::SheetProperties]
1235
+ # @return [void]
1236
+ # @api public
1237
+ #: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
1238
+ def sheet_properties=(opts)
1239
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1240
+
1241
+ @writer.sheet_properties = opts
1242
+ end
1243
+
1244
+ # Adds a defined name (named range or formula) scoped to this sheet or workbook.
1245
+ # Bare cell references and coordinate keywords are automatically formatted with sheet quotes and absolute $ references.
1246
+ #
1247
+ # @param name [String] Defined name identifier.
1248
+ # @param value [Object, nil] Value or formula expression.
1249
+ # @param hidden [Boolean] Whether the defined name is hidden.
1250
+ # @param column [Integer, String, nil] Deprecated alias for columns.
1251
+ # @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
1252
+ # @param col [Integer, String, nil] Deprecated alias for column.
1253
+ # @param row [Integer, Range, nil] Deprecated alias for rows.
1254
+ # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
1255
+ # @param range [String, nil] Cell range reference.
1256
+ # @param sheet [String, nil] Reference sheet name (defaults to current sheet).
1257
+ # @param scope [String, Symbol, nil] Scope identifier (:workbook or sheet name).
1258
+ # @param local [Boolean] Deprecated alias for scope: :current.
1259
+ # @return [void]
1260
+ # @api public
1261
+ #: (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
1262
+ 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)
1263
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1264
+
1265
+ warn "[DEPRECATION] `col:` is deprecated; use `column:` (or `columns:`) instead.", uplevel: 1 if col
1266
+ warn "[DEPRECATION] `local:` is deprecated; use `scope:` instead.", uplevel: 1 if local
1267
+ warn "[Xlsxrb DEPRECATION] defined_name keyword column: is deprecated; use columns: instead.", uplevel: 1 unless column.nil?
1268
+ warn "[Xlsxrb DEPRECATION] defined_name keyword row: is deprecated; use rows: instead.", uplevel: 1 unless row.nil?
1269
+ c_arg = column || columns || col
1270
+ r_arg = row || rows
1271
+ ref_sheet = sheet || @sheet_name
1272
+ local_sheet = if scope
1273
+ scope == :workbook ? nil : scope.to_s
1274
+ elsif local
1275
+ @sheet_name || sheet
1276
+ else
1277
+ sheet
1278
+ end
1279
+ @writer.defined_name(name, value, sheet: local_sheet, hidden: hidden, columns: c_arg, rows: r_arg, range: range, ref_sheet: ref_sheet)
1280
+ end
1281
+
1282
+ # Freezes rows and/or columns for scrolling.
1283
+ #
1284
+ # @example Freeze top row
1285
+ # s.freeze_pane(row: 1)
1286
+ #
1287
+ # @example Freeze first column and top 2 rows
1288
+ # s.freeze_pane(row: 2, column: 1)
1289
+ #
1290
+ # @param row [Integer, nil] Number of rows to freeze.
1291
+ # @param column [Integer, String, nil] Number of columns to freeze.
1292
+ # @param col [Integer, String, nil] Deprecated alias for column.
1293
+ # @return [void]
1294
+ # @api public
1295
+ #: (?row: Integer | nil, ?column: (Integer | String)?, ?col: (Integer | String)?) -> void
1296
+ def freeze_pane(...)
1297
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1298
+
1299
+ @writer.freeze_pane(...)
1300
+ end
1301
+
1302
+ # Sets or clears freeze pane configuration.
1303
+ #
1304
+ # @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
1305
+ # @return [void]
1306
+ # @api public
1307
+ #: (untyped opts) -> void
1308
+ def freeze_pane=(opts)
1309
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1310
+
1311
+ @writer.freeze_pane = opts
1312
+ end
1313
+
1314
+ # Sets or gets the print area range for the sheet.
1315
+ #
1316
+ # @param range [String, Object, nil] Range reference.
1317
+ # @return [String, nil, void]
1318
+ # @api public
1319
+ #: (?untyped range) -> (String | nil | void)
1320
+ def print_area(range = OMITTED)
1321
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1322
+
1323
+ if range.equal?(OMITTED)
1324
+ @writer.print_area
1325
+ else
1326
+ @writer.print_area(range, sheet: @sheet_name)
1327
+ end
1328
+ end
1329
+
1330
+ # Sets the print area for this worksheet.
1331
+ #
1332
+ # @param range [String, nil] Cell range (e.g. "A1:G50").
1333
+ # @return [String, nil]
1334
+ # @api public
1335
+ #: (String? range) -> String?
1336
+ def print_area=(range)
1337
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1338
+
1339
+ @writer.print_area(range, sheet: @sheet_name)
1340
+ range
1341
+ end
1342
+
1343
+ # Configures or gets repeating title rows and columns for printing.
1344
+ #
1345
+ # @param rows [String, Integer, Range, Object, nil] Row range to repeat (e.g. "1:2").
1346
+ # @param columns [String, Integer, Symbol, Range, Object, nil] Column range to repeat (e.g. "A:B").
1347
+ # @param cols [String, Integer, Symbol, Range, Object, nil] Deprecated alias for columns.
1348
+ # @return [Elements::PrintTitles, nil, void]
1349
+ # @api public
1350
+ #: (?rows: untyped, ?columns: untyped, ?cols: untyped) -> (Elements::PrintTitles | nil | void)
1351
+ def print_titles(rows: OMITTED, columns: OMITTED, cols: OMITTED)
1352
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1353
+
1354
+ if rows.equal?(OMITTED) && columns.equal?(OMITTED) && cols.equal?(OMITTED)
1355
+ @writer.print_titles
1356
+ else
1357
+ @writer.print_titles(rows: rows, columns: columns, cols: cols, sheet: @sheet_name)
1358
+ end
1359
+ end
1360
+
1361
+ # Sets repeating print titles for this worksheet.
1362
+ #
1363
+ # @param opts [Elements::PrintTitles, Hash, nil] Options with :rows and/or :columns.
1364
+ # @return [Elements::PrintTitles, Hash, nil]
1365
+ # @api public
1366
+ #: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
1367
+ def print_titles=(opts)
1368
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1369
+
1370
+ if opts.nil?
1371
+ @writer.print_titles = nil
1372
+ else
1373
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
1374
+ @writer.print_titles(**h, sheet: @sheet_name)
1375
+ end
1376
+ opts
1377
+ end
1378
+
1379
+ # Sets repeating title rows to appear at the top of each printed page.
1380
+ #
1381
+ # @param first [Integer, String] First row index (0-based) or range string (e.g. "1:2").
1382
+ # @param last [Integer, String, nil] Optional last row index (0-based).
1383
+ # @return [void]
1384
+ # @api public
1385
+ #: (Integer | String first, ?(Integer | String)? last) -> void
1386
+ def repeat_rows(first, last = nil)
1387
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1388
+
1389
+ @writer.repeat_rows(first, last, sheet: @sheet_name)
1390
+ end
1391
+
1392
+ # Sets repeating title columns to appear at the left of each printed page.
1393
+ #
1394
+ # @param first [Integer, String] First column index (0-based) or column name/range.
1395
+ # @param last [Integer, String, nil] Optional last column index/name.
1396
+ # @return [void]
1397
+ # @api public
1398
+ #: (Integer | String first, ?(Integer | String)? last) -> void
1399
+ def repeat_columns(first, last = nil)
1400
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1401
+
1402
+ @writer.repeat_columns(first, last, sheet: @sheet_name)
1403
+ end
1404
+ # simplecov:enable
1405
+
1406
+ # Splits sheet view into panes.
1407
+ #
1408
+ # @param x_split [Integer] Horizontal split position.
1409
+ # @param y_split [Integer] Vertical split position.
1410
+ # @param top_left_cell [String, nil] Top-left visible cell in bottom-right pane.
1411
+ # @param active_pane [String, Symbol, nil] Active pane identifier.
1412
+ # @param state [String, Symbol, nil] Split state.
1413
+ # @return [void]
1414
+ # @api public
1415
+ #: (?x_split: Integer, ?y_split: Integer, ?top_left_cell: String?, ?active_pane: (String | Symbol)?, ?state: (String | Symbol)?) -> void
1416
+ def split_pane(...)
1417
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1418
+
1419
+ @writer.split_pane(...)
1420
+ end
1421
+
1422
+ # Sets or clears split pane configuration.
1423
+ #
1424
+ # @param opts [Elements::SplitPane, Hash, nil] Split pane options.
1425
+ # @return [void]
1426
+ # @api public
1427
+ #: (untyped opts) -> void
1428
+ def split_pane=(opts)
1429
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1430
+
1431
+ @writer.split_pane = opts
1432
+ end
1433
+
1434
+ # simplecov:disable
1435
+ # Edge case / untested delegation block
1436
+ # Sets workbook structure and window protection.
1437
+ #
1438
+ # @param opts [Hash] Protection options.
1439
+ # @return [void]
1440
+ # @api public
1441
+ #: (**untyped opts) -> void
1442
+ def workbook_protection(...)
1443
+ @writer.workbook_protection(...)
1444
+ end
1445
+
1446
+ # @deprecated Use {#workbook_protection} instead.
1447
+ #: (**untyped opts) -> void
1448
+ def protect_workbook(...)
1449
+ warn "[DEPRECATION] `protect_workbook` is deprecated; use `workbook_protection` instead.", uplevel: 1
1450
+ workbook_protection(...)
1451
+ end
1452
+ # simplecov:enable
1453
+
1454
+ # simplecov:disable
1455
+ # Edge case / untested delegation block
1456
+ # Sets core metadata property.
1457
+ #
1458
+ # @param name [Symbol] Property name.
1459
+ # @param value [String, Integer, Time] Property value.
1460
+ # @return [void]
1461
+ # @api public
1462
+ #: (Symbol name, String | Integer | Time value) -> void
691
1463
  def core_property(...)
692
1464
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
693
1465
 
@@ -697,16 +1469,35 @@ module Xlsxrb
697
1469
 
698
1470
  # Sets the active/selected cell on the sheet.
699
1471
  #
700
- # @param active_cell [String] Cell reference (e.g. "A1").
1472
+ # @param active_cell [String] Cell reference (e.g. "A1") or range (e.g. "A1:D10").
701
1473
  # @param sqref [String, nil] Selection range.
702
1474
  # @param pane [String, Symbol, nil] Pane identifier.
703
1475
  # @return [void]
704
1476
  # @api public
705
1477
  #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
706
- def select_cell(...)
1478
+ def selection(...)
1479
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1480
+
1481
+ @writer.selection(...)
1482
+ end
1483
+
1484
+ # Sets or clears the selection configuration.
1485
+ #
1486
+ # @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
1487
+ # @return [void]
1488
+ # @api public
1489
+ #: (untyped opts) -> void
1490
+ def selection=(opts)
707
1491
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
708
1492
 
709
- @writer.select_cell(...)
1493
+ @writer.selection = opts
1494
+ end
1495
+
1496
+ # @deprecated Use {#selection} instead.
1497
+ #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
1498
+ def select_cell(...)
1499
+ warn "[DEPRECATION] `select_cell` is deprecated; use `selection` instead.", uplevel: 1
1500
+ selection(...)
710
1501
  end
711
1502
 
712
1503
  # Configures page margins for printing.
@@ -726,6 +1517,18 @@ module Xlsxrb
726
1517
  @writer.page_margins(...)
727
1518
  end
728
1519
 
1520
+ # Sets page margins configuration.
1521
+ #
1522
+ # @param opts [Hash, Elements::PageMargins, nil]
1523
+ # @return [void]
1524
+ # @api public
1525
+ #: (untyped opts) -> void
1526
+ def page_margins=(opts)
1527
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1528
+
1529
+ @writer.page_margins = opts
1530
+ end
1531
+
729
1532
  # Configures page orientation, paper size, and print setup.
730
1533
  #
731
1534
  # @param orientation [String, Symbol, nil] "portrait" or "landscape" (or :portrait, :landscape).
@@ -740,6 +1543,18 @@ module Xlsxrb
740
1543
  @writer.page_setup(...)
741
1544
  end
742
1545
 
1546
+ # Sets page setup configuration.
1547
+ #
1548
+ # @param opts [Hash, Elements::PageSetup]
1549
+ # @return [void]
1550
+ # @api public
1551
+ #: (untyped opts) -> void
1552
+ def page_setup=(opts)
1553
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1554
+
1555
+ @writer.page_setup = opts
1556
+ end
1557
+
743
1558
  # Configures header and footer text for printing.
744
1559
  #
745
1560
  # @param opts [Hash] Header and footer specifications.
@@ -752,19 +1567,43 @@ module Xlsxrb
752
1567
  @writer.header_footer(...)
753
1568
  end
754
1569
 
1570
+ # Sets header and footer configuration.
1571
+ #
1572
+ # @param opts [Hash, Elements::HeaderFooter]
1573
+ # @return [void]
1574
+ # @api public
1575
+ #: (untyped opts) -> void
1576
+ def header_footer=(opts)
1577
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1578
+
1579
+ @writer.header_footer = opts
1580
+ end
1581
+
755
1582
  # Configures print options (e.g. gridlines, headings).
756
1583
  #
757
- # @param name [Symbol, String] Print option name.
758
- # @param value [Object] Print option value.
1584
+ # @param name [Symbol, String, Hash, nil] Print option name or hash.
1585
+ # @param value [Object, nil] Print option value.
1586
+ # @param opts [Hash] Additional options.
759
1587
  # @return [void]
760
1588
  # @api public
761
- #: (Symbol | String name, untyped value) -> void
1589
+ #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> void
762
1590
  def print_options(...)
763
1591
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
764
1592
 
765
1593
  @writer.print_options(...)
766
1594
  end
767
1595
 
1596
+ # Replaces print options.
1597
+ # @param opts [Hash, Elements::PrintOptions]
1598
+ # @return [void]
1599
+ # @api public
1600
+ #: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
1601
+ def print_options=(opts)
1602
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1603
+
1604
+ @writer.print_options = opts
1605
+ end
1606
+
768
1607
  # simplecov:disable
769
1608
  # Edge case / untested delegation block
770
1609
  # Sets document metadata properties (core, app, custom).
@@ -786,11 +1625,11 @@ module Xlsxrb
786
1625
  # Edge case / untested delegation block
787
1626
  # Sets app metadata property.
788
1627
  #
789
- # @param name [String, Symbol] Property name.
790
- # @param value [Object] Property value.
1628
+ # @param name [Symbol] Property name.
1629
+ # @param value [String, Integer, Time] Property value.
791
1630
  # @return [void]
792
1631
  # @api public
793
- #: (String | Symbol name, untyped value) -> void
1632
+ #: (Symbol name, String | Integer | Time value) -> void
794
1633
  def app_property(...)
795
1634
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
796
1635
 
@@ -798,27 +1637,47 @@ module Xlsxrb
798
1637
  end
799
1638
  # simplecov:enable
800
1639
 
801
- # Protects the worksheet against modifications.
1640
+ # Sets sheet-level protection with optional password hashing.
802
1641
  #
803
1642
  # @param opts [Hash] Protection options.
804
1643
  # @return [void]
805
1644
  # @api public
806
1645
  #: (**untyped opts) -> void
807
- def protect_sheet(...)
1646
+ def sheet_protection(...)
1647
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1648
+
1649
+ @writer.sheet_protection(...)
1650
+ end
1651
+
1652
+ # Sets or clears sheet protection configuration.
1653
+ #
1654
+ # @param opts [Elements::SheetProtection, Hash, Boolean, nil]
1655
+ # @return [void]
1656
+ # @api public
1657
+ #: (untyped opts) -> void
1658
+ def sheet_protection=(opts)
808
1659
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
809
1660
 
810
- @writer.protect_sheet(...)
1661
+ @writer.sheet_protection = opts
1662
+ end
1663
+
1664
+ # @deprecated Use {#sheet_protection} instead.
1665
+ #: (**untyped opts) -> void
1666
+ def protect_sheet(...)
1667
+ warn "[DEPRECATION] `protect_sheet` is deprecated; use `sheet_protection` instead.", uplevel: 1
1668
+ sheet_protection(...)
811
1669
  end
812
1670
 
813
1671
  # simplecov:disable
814
1672
  # Edge case / untested delegation block
815
1673
  # Sets custom metadata property.
816
1674
  #
817
- # @param name [String, Symbol] Property name.
818
- # @param value [Object] Property value.
1675
+ # @param name [String] Property name.
1676
+ # @param value [String, Integer, Float, Boolean, Time] Property value.
1677
+ # @param type [Symbol] Value type.
819
1678
  # @return [void]
820
1679
  # @api public
821
- #: (String | Symbol name, untyped value) -> void
1680
+ #: (String name, String | Integer | Float | bool | Time value, ?type: ::Symbol) -> void
822
1681
  def custom_property(...)
823
1682
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
824
1683
 
@@ -830,33 +1689,80 @@ module Xlsxrb
830
1689
  #
831
1690
  # @param file_data [String] Binary image data or file content.
832
1691
  # @param ext [String] Image extension ("png", "jpeg", etc.).
833
- # @param from_col [Integer] Starting column index (0-based).
1692
+ # @param from_column [Integer, nil] Starting column index (0-based).
1693
+ # @param from_col [Integer, nil] Deprecated alias for from_column.
834
1694
  # @param from_row [Integer] Starting row index (0-based).
835
- # @param to_col [Integer] Ending column index (0-based).
1695
+ # @param to_column [Integer, nil] Ending column index (0-based).
1696
+ # @param to_col [Integer, nil] Deprecated alias for to_column.
836
1697
  # @param to_row [Integer] Ending row index (0-based).
837
1698
  # @param opts [Hash] Additional anchor and sizing options.
838
1699
  # @return [void]
839
1700
  # @api public
840
- #: (String file_data, ?ext: String, ?from_col: Integer, ?from_row: Integer, ?to_col: Integer, ?to_row: Integer, **untyped opts) -> void
1701
+ #: (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
841
1702
  def image(...)
842
1703
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
843
1704
 
844
1705
  @writer.image(...)
845
1706
  end
846
1707
 
1708
+ # Configures the worksheet background image (<picture>).
1709
+ #
1710
+ # @example Set background image from binary data
1711
+ # sheet.background_image(png_bytes, ext: "png")
1712
+ #
1713
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#background_image=} instead.
1714
+ # @param file_data [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
1715
+ # @param ext [String, nil] Image extension.
1716
+ # @param opts [Hash] Additional options.
1717
+ # @return [Hash, nil]
1718
+ # @api public
1719
+ #: (?untyped file_data, ?ext: String?, **untyped opts) -> Hash[Symbol, untyped]?
1720
+ def background_image(...)
1721
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1722
+
1723
+ @writer.background_image(...)
1724
+ end
1725
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1726
+ alias background_picture background_image
1727
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
1728
+ alias picture background_image
1729
+
1730
+ #: (untyped val) -> untyped
1731
+ def background_image=(val)
1732
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1733
+
1734
+ @writer.background_image = val
1735
+ end
1736
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1737
+ alias background_picture= background_image=
1738
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
1739
+ alias picture= background_image=
1740
+
847
1741
  # Configures sheet view settings (zoom scale, grid lines visibility).
848
1742
  #
849
- # @param name [Symbol, String] View setting name.
850
- # @param value [Object] View setting value.
1743
+ # @param name [Symbol, String, Hash, nil] View setting name or hash.
1744
+ # @param value [Object, nil] View setting value.
1745
+ # @param opts [Hash] Additional options.
851
1746
  # @return [void]
852
1747
  # @api public
853
- #: (Symbol | String name, untyped value) -> void
1748
+ #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> void
854
1749
  def sheet_view(...)
855
1750
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
856
1751
 
857
1752
  @writer.sheet_view(...)
858
1753
  end
859
1754
 
1755
+ # Replaces sheet view properties.
1756
+ # @param opts [Hash, Elements::SheetView]
1757
+ # @return [void]
1758
+ # @api public
1759
+ #: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
1760
+ def sheet_view=(opts)
1761
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1762
+
1763
+ @writer.sheet_view = opts
1764
+ end
1765
+
860
1766
  # Configures sheet format properties (e.g. default_row_height, default_col_width).
861
1767
  #
862
1768
  # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
@@ -864,11 +1770,22 @@ module Xlsxrb
864
1770
  # @param opts [Hash] Keyword arguments for sheet format properties.
865
1771
  # @return [Hash[Symbol, untyped]]
866
1772
  # @api public
867
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
868
- def sheet_format(...)
1773
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetFormat | void)
1774
+ def sheet_format(name = nil, value = nil, **opts)
869
1775
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
870
1776
 
871
- @writer.sheet_format(...)
1777
+ @writer.sheet_format(name, value, **opts)
1778
+ end
1779
+
1780
+ # Replaces sheet format properties.
1781
+ # @param opts [Hash, Elements::SheetFormat]
1782
+ # @return [void]
1783
+ # @api public
1784
+ #: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
1785
+ def sheet_format=(opts)
1786
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1787
+
1788
+ @writer.sheet_format = opts
872
1789
  end
873
1790
 
874
1791
  # simplecov:disable
@@ -879,25 +1796,39 @@ module Xlsxrb
879
1796
  # @return [void]
880
1797
  # @api public
881
1798
  #: (Integer row_index) -> void
882
- def page_break_row(...)
1799
+ def row_break(...)
883
1800
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
884
1801
 
885
- @writer.page_break_row(...)
1802
+ @writer.row_break(...)
1803
+ end
1804
+
1805
+ # @deprecated Use {#row_break} instead.
1806
+ #: (Integer row_num) -> void
1807
+ def page_break_row(...)
1808
+ warn "[DEPRECATION] `page_break_row` is deprecated; use `row_break` instead.", uplevel: 1
1809
+ row_break(...)
886
1810
  end
887
1811
  # simplecov:enable
888
1812
 
889
1813
  # simplecov:disable
890
1814
  # Edge case / untested delegation block
891
- # Adds a vertical page break after the given column index.
1815
+ # Adds a vertical page break after the given column.
892
1816
  #
893
- # @param col_index [Integer] 0-based column index.
1817
+ # @param col [Integer, String, Symbol] 0-based column index or column letter.
894
1818
  # @return [void]
895
1819
  # @api public
896
- #: (Integer col_index) -> void
897
- def page_break_col(...)
1820
+ #: (Integer | String | Symbol col) -> void
1821
+ def column_break(...)
898
1822
  raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
899
1823
 
900
- @writer.page_break_col(...)
1824
+ @writer.column_break(...)
1825
+ end
1826
+
1827
+ # @deprecated Use {#column_break} instead.
1828
+ #: (Integer | String | Symbol col_index) -> void
1829
+ def page_break_col(...)
1830
+ warn "[DEPRECATION] `page_break_col` is deprecated; use `column_break` instead.", uplevel: 1
1831
+ column_break(...)
901
1832
  end
902
1833
  # simplecov:enable
903
1834
 
@@ -915,6 +1846,7 @@ module Xlsxrb
915
1846
 
916
1847
  @writer.protected_range(...)
917
1848
  end
1849
+ # @deprecated Use {#protected_range} instead. Will be removed in 0.2.0.
918
1850
  alias add_protected_range protected_range
919
1851
 
920
1852
  # Adds a cell watch to the sheet.
@@ -928,37 +1860,282 @@ module Xlsxrb
928
1860
 
929
1861
  @writer.cell_watch(...)
930
1862
  end
1863
+ # @deprecated Use {#cell_watch} instead. Will be removed in 0.2.0.
931
1864
  alias add_cell_watch cell_watch
1865
+
1866
+ # Adds an ignored error entry to the sheet.
1867
+ #
1868
+ # @param sqref [String] Cell range reference (e.g. "A1" or "A1:B10").
1869
+ # @param opts [Hash] Error check flags to ignore.
1870
+ # @return [void]
1871
+ # @api public
1872
+ #: (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
1873
+ def ignored_error(...)
1874
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1875
+
1876
+ @writer.ignored_error(...)
1877
+ end
1878
+
1879
+ # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
1880
+ #: (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
1881
+ def ignore_error(...)
1882
+ warn "[DEPRECATION] #ignore_error is deprecated; use #ignored_error instead.", uplevel: 1
1883
+ ignored_error(...)
1884
+ end
1885
+
1886
+ # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
1887
+ #: (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
1888
+ def add_ignored_error(...)
1889
+ warn "[DEPRECATION] #add_ignored_error is deprecated; use #ignored_error instead.", uplevel: 1
1890
+ ignored_error(...)
1891
+ end
1892
+
1893
+ # Returns the ignored error entries configured for this sheet.
1894
+ #
1895
+ # @return [Array<Hash[Symbol, untyped]>]
1896
+ # @api public
1897
+ #: () -> Array[Hash[Symbol, untyped]]
1898
+ def ignored_errors
1899
+ @writer.ignored_errors
1900
+ end
1901
+
1902
+ # Gets or sets phonetic (furigana) guide properties for the sheet.
1903
+ #
1904
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#phonetic_properties=} instead.
1905
+ # @api public
1906
+ #: (?untyped spec, ?font_id: Integer?, ?type: (Symbol | String)?, ?alignment: (Symbol | String)?, **untyped opts) -> (Elements::PhoneticProperties | Hash[Symbol, untyped] | nil)
1907
+ def phonetic_properties(...)
1908
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1909
+
1910
+ @writer.phonetic_properties(...)
1911
+ end
1912
+ # @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
1913
+ alias phonetic_pr phonetic_properties
1914
+
1915
+ # Sets phonetic (furigana) guide properties for the sheet.
1916
+ #
1917
+ # @param spec [Hash, Integer, nil] Options hash or font ID integer.
1918
+ # @return [Hash[Symbol, untyped], Integer, nil]
1919
+ # @api public
1920
+ #: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
1921
+ def phonetic_properties=(spec)
1922
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1923
+
1924
+ @writer.phonetic_properties = spec
1925
+ end
1926
+ # @deprecated Use {#phonetic_properties=} instead. Will be removed in 0.2.0.
1927
+ alias phonetic_pr= phonetic_properties=
1928
+
1929
+ # Sets or gets the internal code name of the worksheet.
1930
+ #
1931
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
1932
+ # @param val [String, Symbol, nil] The code name.
1933
+ # @return [String, nil]
1934
+ # @api public
1935
+ #: (?String | Symbol | nil val) -> String?
1936
+ def code_name(...)
1937
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1938
+
1939
+ @writer.code_name(...)
1940
+ end
1941
+
1942
+ # Sets the internal code name of the worksheet.
1943
+ #
1944
+ # @param val [String, Symbol, nil] The code name.
1945
+ # @return [String, nil]
1946
+ # @api public
1947
+ #: (String | Symbol | nil val) -> String?
1948
+ def code_name=(val)
1949
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1950
+
1951
+ @writer.code_name = val
1952
+ end
1953
+
1954
+ # Configures whether page setup fits content to page width/height.
1955
+ # When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
1956
+ #
1957
+ # @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.
1958
+ # @param enabled [Boolean, nil] Whether to fit to page.
1959
+ # @param width [Integer, nil] Pages wide to fit to.
1960
+ # @param height [Integer, nil] Pages tall to fit to.
1961
+ # @return [Boolean, void]
1962
+ # @api public
1963
+ #: (?bool? enabled, ?width: Integer?, ?height: Integer?) -> (bool | void)
1964
+ def fit_to_page(enabled = OMITTED, width: nil, height: nil)
1965
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1966
+
1967
+ @writer.fit_to_page(enabled, width: width, height: height)
1968
+ end
1969
+
1970
+ # @deprecated Use {#fit_to_page} instead. Will be removed in 0.2.0.
1971
+ # @return [Boolean]
1972
+ # @api public
1973
+ #: () -> bool
1974
+ def fit_to_page?
1975
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1976
+
1977
+ warn "[Xlsxrb DEPRECATION] fit_to_page? is deprecated; use fit_to_page instead.", uplevel: 1
1978
+ @writer.fit_to_page
1979
+ end
1980
+
1981
+ # Sets whether page setup fits content to page width/height.
1982
+ #
1983
+ # @param enabled [Boolean, nil] Whether to fit to page.
1984
+ # @return [Boolean]
1985
+ # @api public
1986
+ #: (bool? enabled) -> bool?
1987
+ def fit_to_page=(enabled)
1988
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
1989
+
1990
+ @writer.fit_to_page = enabled
1991
+ end
1992
+
1993
+ # Configures worksheet calculation properties (<sheetCalcPr>).
1994
+ #
1995
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sheet_calc_properties=} instead.
1996
+ # @param spec [Hash, nil] Calculation properties hash.
1997
+ # @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
1998
+ # @return [Hash, nil]
1999
+ # @api public
2000
+ #: (?untyped spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2001
+ def sheet_calc_properties(...)
2002
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
2003
+
2004
+ @writer.sheet_calc_properties(...)
2005
+ end
2006
+
2007
+ # Sets worksheet calculation properties (<sheetCalcPr>).
2008
+ #
2009
+ # @param spec [Hash, nil] Calculation properties hash.
2010
+ # @return [Hash, nil]
2011
+ # @api public
2012
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2013
+ def sheet_calc_properties=(spec)
2014
+ raise Error, "Sheet '#{@sheet_name}' is no longer active. In streaming mode, you cannot write to a previous sheet." if @writer.current_sheet != @sheet_name
2015
+
2016
+ @writer.sheet_calc_properties = spec
2017
+ end
2018
+
2019
+ # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
2020
+ #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2021
+ def sheet_calc_pr(...)
2022
+ warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
2023
+ sheet_calc_properties(...)
2024
+ end
2025
+
2026
+ # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
2027
+ #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
2028
+ def calc_pr(...)
2029
+ warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
2030
+ sheet_calc_properties(...)
2031
+ end
2032
+
2033
+ # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
2034
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2035
+ def sheet_calc_pr=(spec)
2036
+ warn "[DEPRECATION] #sheet_calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
2037
+ self.sheet_calc_properties = spec
2038
+ end
2039
+
2040
+ # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
2041
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
2042
+ def calc_pr=(spec)
2043
+ warn "[DEPRECATION] #calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
2044
+ self.sheet_calc_properties = spec
2045
+ end
2046
+ end
2047
+
2048
+ # Returns the list of worksheet names created in this workbook so far.
2049
+ #
2050
+ # @return [Array<String>] Worksheet names.
2051
+ # @api public
2052
+ #: () -> Array[String]
2053
+ def sheet_names
2054
+ names = @sheets.map { |s| s.respond_to?(:name) ? s.name : s[:name].to_s }
2055
+ names << @current_sheet if @current_sheet
2056
+ names
932
2057
  end
933
2058
 
934
2059
  # Adds a new sheet to the workbook and starts streaming rows into it.
935
2060
  #
936
2061
  # @param name [String, nil] Sheet name (max 31 characters).
2062
+ # @param state [Symbol, String, nil] Sheet visibility state (:visible, :hidden, :very_hidden).
2063
+ # @param tab_color [String, Hash, nil] Tab color hex string or color hash.
2064
+ # @param code_name [String, nil] VBA code name.
2065
+ # @param hidden [Boolean, nil] Deprecated alias for state: :hidden.
937
2066
  # @param opts [Hash] Sheet-level configuration.
938
2067
  # @yield [sheet_proxy]
939
2068
  # @yieldparam sheet_proxy [WorksheetProxy] The streaming sheet proxy.
940
2069
  # @return [String] The sheet name.
941
2070
  # @api public
942
- #: (?String? name, **untyped opts) ?{ (WorksheetProxy) -> void } -> untyped
943
- def sheet(name = nil, **opts)
944
- name ||= "Sheet#{@sheets.size + 1}"
2071
+ #: (?String? name, ?state: (Symbol | String)?, ?tab_color: untyped, ?code_name: String?, ?hidden: bool?, **untyped opts) ?{ (WorksheetProxy) -> void } -> String
2072
+ def sheet(name = nil, state: nil, tab_color: nil, code_name: nil, hidden: nil, **opts)
2073
+ sheet_count = @sheets.size + (@current_sheet ? 1 : 0)
2074
+ name ||= "Sheet#{sheet_count + 1}"
945
2075
  raise ArgumentError, "Sheet name '#{name}' must be <= 31 characters (Excel limitation)" if @strict_excel_mode && name.length > 31
946
- raise ArgumentError, "Sheet name '#{name}' contains invalid characters (ECMA-376 OOXML specification)" if name.match?(%r{[\[\]*?/\\]})
947
- raise ArgumentError, "Sheet name '#{name}' is already used. Excel requires unique sheet names." if @strict_excel_mode && @sheets.map { |s| s.respond_to?(:name) ? s.name.downcase : s.to_s.downcase }.include?(name.downcase)
948
-
949
- internal_sheet_setup(name)
2076
+ raise ArgumentError, "Sheet name '#{name}' contains invalid characters (Excel limitation)" if name.match?(Elements::Worksheet.forbidden_name_chars)
2077
+ raise ArgumentError, "Sheet name '#{name}' cannot start or end with an apostrophe (Excel limitation)" if @strict_excel_mode && (name.start_with?("'") || name.end_with?("'"))
2078
+ raise ArgumentError, "Sheet name '#{name}' is reserved by Excel (Excel limitation)" if @strict_excel_mode && name.casecmp?("History")
2079
+
2080
+ existing_names = @sheets.map { |s| s.respond_to?(:name) ? s.name.downcase : s[:name].to_s.downcase }
2081
+ existing_names << @current_sheet.downcase if @current_sheet
2082
+ raise ArgumentError, "Sheet name '#{name}' is already used. Excel requires unique sheet names." if @strict_excel_mode && existing_names.include?(name.downcase)
2083
+
2084
+ active = opts.delete(:active)
2085
+ state = opts.delete(:state) if opts.key?(:state)
2086
+ hidden = opts.delete(:hidden) if opts.key?(:hidden)
2087
+ code_name = opts.delete(:code_name) if opts.key?(:code_name)
2088
+ tab_color = opts.delete(:tab_color) if opts.key?(:tab_color)
2089
+
2090
+ warn "[Xlsxrb DEPRECATION] sheet keyword hidden: is deprecated; use state: :hidden instead.", uplevel: 1 unless hidden.nil?
2091
+ state ||= :hidden if hidden
2092
+ state ||= :visible
2093
+ state = state.to_sym
2094
+ raise ArgumentError, "Invalid sheet state ':#{state}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(state)
2095
+
2096
+ internal_sheet_setup(name, state: state)
2097
+ if active
2098
+ @active_sheet = name
2099
+ @current_sheet_view[:tab_selected] = true
2100
+ end
2101
+ self.tab_color = tab_color if tab_color
2102
+ self.code_name = code_name if code_name
950
2103
  opts.each { |k, v| sheet_properties(k, v) }
951
2104
 
952
2105
  yield WorksheetProxy.new(self, @current_sheet) if block_given?
953
2106
  @current_sheet
954
2107
  end
955
2108
 
2109
+ # Returns a WorksheetProxy for the current or named sheet.
2110
+ #
2111
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
2112
+ # @yield [proxy]
2113
+ # @yieldparam proxy [WorksheetProxy]
2114
+ # @return [WorksheetProxy]
2115
+ # @api public
2116
+ #: (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetProxy) -> void } -> WorksheetProxy
2117
+ def [](name_or_index = nil)
2118
+ target_name = if name_or_index.nil?
2119
+ @current_sheet || sheet
2120
+ elsif name_or_index.is_a?(Integer)
2121
+ all_names = sheet_names
2122
+ all_names[name_or_index] || raise(ArgumentError, "Sheet index #{name_or_index} out of bounds")
2123
+ else
2124
+ name_or_index.to_s
2125
+ end
2126
+ proxy = WorksheetProxy.new(self, target_name)
2127
+ yield proxy if block_given?
2128
+ proxy
2129
+ end
2130
+
956
2131
  # Internal: Start or switch to a named sheet (internal helper).
957
- #: (?String? name) ?{ (WorksheetProxy) -> void } -> (WorksheetProxy | nil)
958
- def internal_sheet_setup(name = nil)
2132
+ # @api private
2133
+ #: (?String? name, ?state: Symbol) ?{ (WorksheetProxy) -> void } -> (WorksheetProxy | nil)
2134
+ def internal_sheet_setup(name = nil, state: :visible)
959
2135
  flush_current_sheet
960
2136
  name ||= "Sheet#{@sheets.size + 1}"
961
2137
  @current_sheet = name
2138
+ @current_sheet_state = state
962
2139
  @current_sheet_index = @sheets.size + 1
963
2140
  @current_row_index = 0
964
2141
  @sheet_entry_started = false
@@ -980,6 +2157,7 @@ module Xlsxrb
980
2157
  @current_pivot_tables = []
981
2158
  @current_sparkline_groups = []
982
2159
  @current_comments = []
2160
+ @current_threaded_comments = []
983
2161
  @current_merge_cells = []
984
2162
  @current_freeze_pane = nil
985
2163
  @current_split_pane = nil
@@ -998,6 +2176,15 @@ module Xlsxrb
998
2176
  @current_col_breaks = []
999
2177
  @current_protected_ranges = []
1000
2178
  @current_cell_watches = []
2179
+ @current_ignored_errors = []
2180
+ @current_phonetic_properties = nil
2181
+ @current_sheet_calc_pr = nil
2182
+ @current_background_image = nil
2183
+ @current_print_area = nil
2184
+ @current_print_titles = nil
2185
+ @current_row_outline_level = nil
2186
+ @current_row_collapsed = false
2187
+ @current_row_hidden = false
1001
2188
  @current_cells = {}
1002
2189
 
1003
2190
  return unless block_given?
@@ -1009,6 +2196,8 @@ module Xlsxrb
1009
2196
  # simplecov:enable
1010
2197
  end
1011
2198
 
2199
+ # @api private
2200
+ #: () -> void
1012
2201
  def start_sheet_entry
1013
2202
  return if @sheet_entry_started
1014
2203
 
@@ -1050,24 +2239,36 @@ module Xlsxrb
1050
2239
  # Appends a row of values to the active sheet.
1051
2240
  #
1052
2241
  # @param values [Array<Object>, Hash] The cell values.
1053
- # @param styles [String, Symbol, Array, Hash, nil] Style names or inline style definitions.
2242
+ # @param cell_styles [String, Symbol, Array, Hash, nil] Style names or inline style definitions to apply to cells.
2243
+ # @param row_style [Integer, Symbol, String, Hash, nil] Row style format or index.
1054
2244
  # @param height [Float, Integer, nil] The row height in points (0 - 409).
1055
2245
  # @param hidden [Boolean] Whether the row is hidden.
1056
2246
  # @param custom_height [Boolean] Whether custom row height is set.
1057
2247
  # @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
1058
- # @param style [Integer, Symbol, String, Hash, nil] Row style format or index.
2248
+ # @param collapsed [Boolean] Whether the row is collapsed.
2249
+ # @param styles [String, Symbol, Array, Hash, nil] Deprecated. Use cell_styles: instead.
2250
+ # @param style [Integer, Symbol, String, Hash, nil] Deprecated. Use row_style: instead.
1059
2251
  # @return [void]
1060
2252
  # @api public
1061
- #: (Array[untyped] | Hash[untyped, untyped] values, ?styles: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil, ?style: untyped) -> void
1062
- def row(values, styles: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil, style: nil)
2253
+ #: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?styles: untyped, ?style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
2254
+ 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)
1063
2255
  sheet if @current_sheet.nil?
1064
2256
 
2257
+ if styles
2258
+ warn "[DEPRECATION] StreamWriter#row keyword :styles is deprecated; use :cell_styles instead.", uplevel: 1
2259
+ cell_styles ||= styles
2260
+ end
2261
+ if style
2262
+ warn "[DEPRECATION] StreamWriter#row keyword :style is deprecated; use :row_style instead.", uplevel: 1
2263
+ row_style ||= style
2264
+ end
2265
+
1065
2266
  row_index = @current_row_index
1066
2267
  DslHelpers.validate_row_bounds!(row_index, height, strict_excel_mode: @strict_excel_mode)
1067
2268
  @current_row_index += 1
1068
2269
 
1069
2270
  values = DslHelpers.normalize_row_values(values)
1070
- styles = DslHelpers.normalize_row_styles(styles)
2271
+ cell_styles = DslHelpers.normalize_row_styles(cell_styles)
1071
2272
 
1072
2273
  if @current_charts && !@current_charts.empty?
1073
2274
  @current_cells ||= {}
@@ -1075,35 +2276,40 @@ module Xlsxrb
1075
2276
  values.each_with_index do |val, col_idx|
1076
2277
  next if val.nil?
1077
2278
 
1078
- addr = "#{Elements::Cell.column_letter(col_idx)}#{row_num}"
2279
+ addr = "#{Elements::Cell._column_letter(col_idx)}#{row_num}"
1079
2280
  @current_cells[addr] = val
1080
2281
  end
1081
2282
  end
1082
2283
 
1083
2284
  raise ArgumentError, "Row contains #{values.length} columns, exceeding Excel limit of 16_384 columns" if @strict_excel_mode && values.length > 16_384
1084
2285
 
1085
- row_style_id = if style.is_a?(Hash)
1086
- inline_name = "__inline_row_#{style.hash}"
1087
- style(inline_name, **style) unless @style_name_to_id.key?(inline_name)
2286
+ row_style_id = if row_style.is_a?(Hash)
2287
+ inline_name = "__inline_row_#{row_style.hash}"
2288
+ self.style(inline_name, **row_style) unless @style_name_to_id.key?(inline_name)
1088
2289
  @style_name_to_id[inline_name]
1089
2290
  else
1090
- style
2291
+ row_style
1091
2292
  end
1092
2293
 
2294
+ effective_outline = outline_level || @current_row_outline_level
2295
+ effective_collapsed = collapsed || @current_row_collapsed
2296
+ effective_hidden = hidden || @current_row_hidden
2297
+
1093
2298
  attrs = nil
1094
- if height || hidden || outline_level || collapsed || row_style_id
2299
+ if height || effective_hidden || effective_outline || effective_collapsed || row_style_id
1095
2300
  attrs = {}
1096
2301
  attrs[:height] = height if height
1097
- attrs[:hidden] = true if hidden
2302
+ attrs[:hidden] = true if effective_hidden
1098
2303
  attrs[:custom_height] = custom_height || !height.nil?
1099
- attrs[:collapsed] = true if collapsed
1100
- attrs[:outline_level] = outline_level if outline_level
2304
+ attrs[:collapsed] = true if effective_collapsed
2305
+ attrs[:outline_level] = effective_outline if effective_outline
1101
2306
  attrs[:style_index] = row_style_id if row_style_id
1102
2307
  end
1103
2308
 
1104
- @current_row_writer.write_row_values(row_index, values, styles: styles, style_map: @style_name_to_id, sst: @sst, sst_index: @sst_index, attrs: attrs)
2309
+ @current_row_writer.write_row_values(row_index, values, styles: cell_styles, style_map: @style_name_to_id, sst: @sst, sst_index: @sst_index, attrs: attrs)
1105
2310
  start_sheet_entry if !@sheet_entry_started && @current_row_buffer.bytesize >= 65_536
1106
2311
  end
2312
+ # @deprecated Use {#row} instead. Will be removed in 0.2.0.
1107
2313
  alias add_row row
1108
2314
 
1109
2315
  # Appends a row to the worksheet and returns self for chaining.
@@ -1120,16 +2326,41 @@ module Xlsxrb
1120
2326
  self
1121
2327
  end
1122
2328
 
2329
+ # Advances the row cursor by count without writing empty row elements.
2330
+ #
2331
+ # @example Skip one row
2332
+ # w.skip_row
2333
+ #
2334
+ # @example Skip multiple rows
2335
+ # w.skip_rows(3)
2336
+ #
2337
+ # @param count [Integer] Number of rows to skip (must be >= 1).
2338
+ # @return [void]
2339
+ # @api public
2340
+ #: (?Integer count) -> void
2341
+ def skip_rows(count = 1)
2342
+ raise ArgumentError, "count must be positive: #{count.inspect}" if !count.is_a?(Integer) || count < 1
2343
+
2344
+ sheet if @current_sheet.nil?
2345
+ @current_row_index += count
2346
+ end
2347
+ # @deprecated Use {#skip_rows} instead. Will be removed in 0.2.0.
2348
+ alias skip_row skip_rows
2349
+
1123
2350
  # Sets column formatting and properties for one or multiple columns.
1124
2351
  #
1125
- # @param index [Integer, String, Range, Array] Column index (0-based) or letter ("A".."D").
2352
+ # @param index [Integer, String, Symbol, Range, Array] Column index (0-based), letter ("A", :A), range, or array.
1126
2353
  # @param width [Float, Integer, nil] Column width in character units (0 - 255).
1127
2354
  # @param hidden [Boolean] Whether the column is hidden.
2355
+ # @param custom_width [Boolean] Whether custom width flag is set.
2356
+ # @param outline_level [Integer, nil] Grouping/outline level.
2357
+ # @param collapsed [Boolean] Whether the column is collapsed.
1128
2358
  # @param style [Integer, Symbol, String, Hash, nil] Column style format or index.
2359
+ # @param best_fit [Boolean] Whether the column automatically fits content.
1129
2360
  # @return [void]
1130
2361
  # @api public
1131
- #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
1132
- def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, style: nil)
2362
+ #: (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
2363
+ def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, collapsed: false, style: nil, best_fit: false)
1133
2364
  raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
1134
2365
 
1135
2366
  sheet if @current_sheet.nil?
@@ -1144,33 +2375,195 @@ module Xlsxrb
1144
2375
  style
1145
2376
  end
1146
2377
  DslHelpers.normalize_column_indices(index).each do |idx|
1147
- entry = { index: idx, width: width, hidden: hidden, custom_width: custom_width || !width.nil?, outline_level: outline_level }
1148
- if style_id
1149
- entry[:style] = style_id
1150
- @current_row_writer&.set_column_style(idx, style_id)
2378
+ existing = @current_columns.find { |c| c[:index] == idx }
2379
+ if existing
2380
+ existing[:width] = width unless width.nil?
2381
+ existing[:custom_width] = true if custom_width || !width.nil?
2382
+ existing[:hidden] = hidden if hidden
2383
+ existing[:outline_level] = outline_level unless outline_level.nil?
2384
+ existing[:collapsed] = true if collapsed
2385
+ existing[:best_fit] = true if best_fit
2386
+ if style_id
2387
+ existing[:style] = style_id
2388
+ @current_row_writer&.set_column_style(idx, style_id)
2389
+ end
2390
+ else
2391
+ entry = { index: idx, width: width, hidden: hidden, custom_width: custom_width || !width.nil?, outline_level: outline_level }
2392
+ entry[:collapsed] = true if collapsed
2393
+ entry[:best_fit] = true if best_fit
2394
+ if style_id
2395
+ entry[:style] = style_id
2396
+ @current_row_writer&.set_column_style(idx, style_id)
2397
+ end
2398
+ @current_columns << entry
2399
+ end
2400
+ end
2401
+ @current_columns.sort_by! { |c| c[:index] }
2402
+ nil
2403
+ end
2404
+
2405
+ # Returns column configurations defined for the current worksheet.
2406
+ #
2407
+ # @return [Array<Elements::Column>]
2408
+ # @api public
2409
+ #: () -> Array[Elements::Column]
2410
+ def columns
2411
+ sheet if @current_sheet.nil?
2412
+ @current_columns.map do |c|
2413
+ if c.is_a?(Elements::Column)
2414
+ c
2415
+ else
2416
+ idx = c[:index]
2417
+ style_idx = c[:style] || c[:style_index]
2418
+ unmapped = c.except(:index, :width, :hidden, :custom_width, :outline_level, :style, :style_index)
2419
+ unmapped[:collapsed] = true if c[:collapsed]
2420
+ unmapped[:best_fit] = true if c[:best_fit]
2421
+ Elements::Column.new(
2422
+ index: idx,
2423
+ width: c[:width],
2424
+ hidden: c[:hidden] ? true : false,
2425
+ custom_width: c[:custom_width] ? true : false,
2426
+ outline_level: c[:outline_level],
2427
+ style_index: style_idx,
2428
+ unmapped_data: unmapped
2429
+ )
1151
2430
  end
1152
- @current_columns << entry
1153
2431
  end
1154
2432
  end
1155
2433
 
2434
+ # Groups multiple columns together with outline hierarchy.
2435
+ #
2436
+ # @example Group columns B through D
2437
+ # sheet.group_columns("B".."D", level: 1)
2438
+ #
2439
+ # @example Group columns 1 through 3 and collapse
2440
+ # sheet.group_columns(1..3, level: 1, collapsed: true)
2441
+ #
2442
+ # @param index [Integer, String, Range, Array] Column index (0-based), letter, range, or array.
2443
+ # @param level [Integer] Grouping outline level (1 to 7).
2444
+ # @param collapsed [Boolean] Whether the group is collapsed.
2445
+ # @param hidden [Boolean] Whether the columns are hidden.
2446
+ # @param width [Float, Integer, nil] Optional column width.
2447
+ # @param style [Integer, Symbol, String, nil] Optional column style.
2448
+ # @return [void]
2449
+ # @api public
2450
+ #: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?level: Integer, ?collapsed: bool, ?hidden: bool, ?width: Float | Integer | nil, ?style: untyped) -> void
2451
+ def group_columns(index, level: 1, collapsed: false, hidden: false, width: nil, style: nil)
2452
+ column(index, outline_level: level, collapsed: collapsed, hidden: hidden, width: width, style: style)
2453
+ end
2454
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
2455
+ alias group_column group_columns
2456
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
2457
+ alias group_cols group_columns
2458
+ # @deprecated Use {#group_columns} instead. Will be removed in 0.2.0.
2459
+ alias group_col group_columns
2460
+
2461
+ # Groups multiple rows with outline hierarchy with a block.
2462
+ #
2463
+ # @example Group rows with a block
2464
+ # sheet.group_rows(level: 1, collapsed: true) do
2465
+ # sheet.row(["Subtotal Item 1"])
2466
+ # sheet.row(["Subtotal Item 2"])
2467
+ # end
2468
+ #
2469
+ # @param rows [Range, Array, Integer, nil] Unused in streaming write (streaming rows are written on the fly).
2470
+ # @param level [Integer] Grouping outline level (1 to 7).
2471
+ # @param collapsed [Boolean] Whether the group is collapsed.
2472
+ # @param hidden [Boolean] Whether the rows are hidden.
2473
+ # @yield Optional block executed with active group outline settings.
2474
+ # @return [void]
2475
+ # @api public
2476
+ #: (?untyped rows, ?level: Integer, ?collapsed: bool, ?hidden: bool) ?{ (self) -> void } -> void
2477
+ def group_rows(rows = nil, level: 1, collapsed: false, hidden: false)
2478
+ _ = rows
2479
+ return unless block_given?
2480
+
2481
+ prev_level = @current_row_outline_level
2482
+ prev_collapsed = @current_row_collapsed
2483
+ prev_hidden = @current_row_hidden
2484
+ @current_row_outline_level = level
2485
+ @current_row_collapsed = collapsed
2486
+ @current_row_hidden = hidden
2487
+ begin
2488
+ yield(self)
2489
+ ensure
2490
+ @current_row_outline_level = prev_level
2491
+ @current_row_collapsed = prev_collapsed
2492
+ @current_row_hidden = prev_hidden
2493
+ end
2494
+ end
2495
+ # @deprecated Use {#group_rows} instead. Will be removed in 0.2.0.
2496
+ alias group_row group_rows
2497
+
2498
+ # Configures worksheet-level outline and grouping view properties.
2499
+ #
2500
+ # @example Show summary row below detail rows
2501
+ # sheet.outline_properties(summary_below: true, summary_right: true)
2502
+ #
2503
+ # @param summary_below [Boolean, nil] Flag indicating if summary rows appear below detail rows.
2504
+ # @param summary_right [Boolean, nil] Flag indicating if summary columns appear to the right of detail columns.
2505
+ # @param show_outline_symbols [Boolean, nil] Flag indicating whether outline symbols are visible.
2506
+ # @param show_symbols [Boolean, nil] Deprecated alias for show_outline_symbols.
2507
+ # @param apply_styles [Boolean, nil] Flag indicating whether automatic styles apply to outlines.
2508
+ # @param opts [Hash] Additional options.
2509
+ # @return [Hash<Symbol, untyped>, void]
2510
+ # @api public
2511
+ #: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?show_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> (Hash[Symbol, untyped] | void)
2512
+ def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, show_symbols: nil, apply_styles: nil, **opts)
2513
+ sheet if @current_sheet.nil?
2514
+ return @current_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?
2515
+
2516
+ warn "[Xlsxrb DEPRECATION] outline_properties keyword show_symbols: is deprecated; use show_outline_symbols: instead.", uplevel: 1 unless show_symbols.nil?
2517
+ props = (@current_sheet_properties[:outline_properties] || {}).dup
2518
+ props[:summary_below] = summary_below unless summary_below.nil?
2519
+ props[:summary_right] = summary_right unless summary_right.nil?
2520
+ symbols = show_outline_symbols.nil? ? show_symbols : show_outline_symbols
2521
+ props[:show_outline_symbols] = symbols unless symbols.nil?
2522
+ props[:apply_styles] = apply_styles unless apply_styles.nil?
2523
+ props.merge!(opts)
2524
+ @current_sheet_properties[:outline_properties] = props
2525
+ @current_sheet_properties[:summary_below] = props[:summary_below] unless props[:summary_below].nil?
2526
+ @current_sheet_properties[:summary_right] = props[:summary_right] unless props[:summary_right].nil?
2527
+ nil
2528
+ end
2529
+ # @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
2530
+ alias outline_pr outline_properties
2531
+
2532
+ # Sets worksheet outline and grouping view properties.
2533
+ #
2534
+ # @param opts [Hash] Outline properties.
2535
+ # @return [void]
2536
+ # @api public
2537
+ #: (Hash[Symbol, untyped] opts) -> void
2538
+ def outline_properties=(opts)
2539
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
2540
+ outline_properties(**h)
2541
+ nil
2542
+ end
2543
+ alias outline_pr= outline_properties=
2544
+
1156
2545
  # Adds a chart to the current worksheet.
1157
2546
  #
2547
+ # @param type [Symbol, String, nil] Optional chart type (e.g. :bar, :line).
1158
2548
  # @param options [Hash] Chart options.
1159
2549
  # @yield [builder]
1160
2550
  # @yieldparam builder [Xlsxrb::ChartBuilder]
1161
2551
  # @return [void]
1162
2552
  # @api public
1163
- #: (**untyped options) ?{ (ChartBuilder) -> void } -> void
1164
- def chart(**options)
2553
+ #: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
2554
+ def chart(type = nil, **options)
1165
2555
  sheet if @current_sheet.nil?
1166
2556
 
2557
+ options = options.merge(type: type) if type
1167
2558
  if block_given?
1168
2559
  builder = ChartBuilder.new
2560
+ builder.type(type) if type
1169
2561
  yield builder
1170
2562
  options = builder.options.merge(options)
1171
2563
  end
1172
2564
 
1173
2565
  @current_charts << options
2566
+ nil
1174
2567
  end
1175
2568
 
1176
2569
  # Adds a hyperlink on a cell.
@@ -1204,13 +2597,25 @@ module Xlsxrb
1204
2597
 
1205
2598
  # Sets the auto-filter range on the active sheet.
1206
2599
  #
1207
- # @param range [String] Cell range (e.g. "A1:E100").
2600
+ # @param range [String, nil] Cell range (e.g. "A1:E100").
1208
2601
  # @return [void]
1209
2602
  # @api public
1210
- #: (String range) -> void
2603
+ #: (String? range) -> void
1211
2604
  def auto_filter(range)
1212
2605
  sheet if @current_sheet.nil?
1213
2606
  @current_auto_filter = range
2607
+ nil
2608
+ end
2609
+
2610
+ # Sets the auto-filter range for the current worksheet.
2611
+ #
2612
+ # @param range [String, nil] Cell range (e.g. "A1:E100").
2613
+ # @return [String, nil]
2614
+ # @api public
2615
+ #: (String? range) -> String?
2616
+ def auto_filter=(range)
2617
+ auto_filter(range)
2618
+ range
1214
2619
  end
1215
2620
 
1216
2621
  # Sets filter criteria on a column in the auto-filter.
@@ -1219,10 +2624,18 @@ module Xlsxrb
1219
2624
  # @param filter [Hash] Filter criteria.
1220
2625
  # @return [void]
1221
2626
  # @api public
1222
- #: (untyped col_id, untyped filter) -> untyped
2627
+ # Sets filter criteria on an auto-filter column.
2628
+ #
2629
+ # @param col_id [Integer, String, Symbol] 0-based column index relative to auto-filter or column letter ("A", :B).
2630
+ # @param filter [Hash] Filter definition.
2631
+ # @return [void]
2632
+ # @api public
2633
+ #: (Integer | String | Symbol col_id, Hash[untyped, untyped] filter) -> void
1223
2634
  def filter_column(col_id, filter)
1224
2635
  sheet if @current_sheet.nil?
2636
+ col_id = Elements::Cell._column_index(col_id) if col_id.is_a?(String) || col_id.is_a?(Symbol)
1225
2637
  @current_filter_columns[col_id] = filter
2638
+ nil
1226
2639
  end
1227
2640
 
1228
2641
  # Configures column sort state on the active sheet.
@@ -1230,45 +2643,70 @@ module Xlsxrb
1230
2643
  # @param ref [String] The sorted range.
1231
2644
  # @param sort_conditions [Array<Hash>] Sort conditions.
1232
2645
  # @param opts [Hash] Additional options.
1233
- # @return [void]
2646
+ # @return [Elements::SortState, Hash<Symbol, untyped>, nil, void]
1234
2647
  # @api public
1235
- #: (untyped ref, untyped sort_conditions, **untyped opts) -> untyped
1236
- def sort_state(ref, sort_conditions, **opts)
2648
+ #: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, **untyped opts) -> (untyped | void)
2649
+ def sort_state(ref = nil, sort_conditions = nil, **opts)
1237
2650
  sheet if @current_sheet.nil?
2651
+ if ref.nil? && sort_conditions.nil? && opts.empty?
2652
+ return nil unless @current_sort_state
2653
+ return Elements::SortState.new(**@current_sort_state) if defined?(Elements::SortState)
2654
+
2655
+ return @current_sort_state
2656
+ end
2657
+
1238
2658
  @current_sort_state = { ref: ref, sort_conditions: sort_conditions }.merge(opts)
2659
+ nil
2660
+ end
2661
+
2662
+ # Sets column sort state for the sheet.
2663
+ #
2664
+ # @param opts [Elements::SortState, Hash, nil] Sort state options.
2665
+ # @return [void]
2666
+ # @api public
2667
+ #: (untyped opts) -> void
2668
+ def sort_state=(opts)
2669
+ sheet if @current_sheet.nil?
2670
+ @current_sort_state = opts&.respond_to?(:to_h) ? opts.to_h : opts
2671
+ nil
1239
2672
  end
1240
2673
 
1241
2674
  # Adds a data validation rule.
1242
2675
  #
1243
2676
  # @param sqref [String, nil] Cell range.
1244
- # @param opts [Hash] Validation options.
2677
+ # @param opts [Hash] Validation options (or coordinate keywords: `columns:`, `rows:`, `except_rows:`, `list:`, `in:`).
1245
2678
  # @yield [data_validation_builder] Optional configuration block.
1246
2679
  # @return [void]
1247
2680
  # @api public
1248
2681
  #: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
1249
- def validate_data(sqref = nil, **opts)
2682
+ def data_validation(sqref = nil, **opts, &)
1250
2683
  sheet if @current_sheet.nil?
1251
- if block_given?
1252
- builder = DataValidationBuilder.new(sqref, **opts)
1253
- yield builder
1254
- opts = builder.to_h
1255
- sqref = opts.delete(:sqref) || sqref
1256
- end
1257
- raise ArgumentError, "data validation sqref must be provided" unless sqref
2684
+ normalized_list = DslHelpers.normalize_data_validation(sqref, **opts, &)
2685
+ @current_data_validations.concat(normalized_list)
2686
+ end
1258
2687
 
1259
- @current_data_validations << opts.merge(sqref: sqref)
2688
+ # @deprecated Use {#data_validation} instead.
2689
+ #: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
2690
+ def validate_data(...)
2691
+ warn "[DEPRECATION] `validate_data` is deprecated; use `data_validation` instead.", uplevel: 1
2692
+ data_validation(...)
1260
2693
  end
1261
2694
 
1262
2695
  # Adds a conditional formatting rule.
2696
+ # Supports block configuration via {ConditionalFormatBuilder} and coordinate targeting (:columns, :rows).
1263
2697
  #
1264
- # @param sqref [String] Cell range.
1265
- # @param opts [Hash] Rule options.
2698
+ # @param sqref [String, nil] Cell range (e.g. "A1:A10").
2699
+ # @param opts [Hash] Rule options (e.g. `type:`, `operator:`, `formula:`, `dxf:`, `format_id:`, `font_color:`, `fill_color:`, `bold:`, `italic:`).
2700
+ # @option opts [Hash] :dxf Hierarchical differential format specification (e.g. `dxf: { font: { bold: false, color: { auto: true } }, fill: { pattern: "none", bg_color: "FFFF00" } }`).
2701
+ # @option opts [Integer] :format_id Pre-registered differential format index (dxfId).
2702
+ # @yield [conditional_format_builder] Optional block for configuration.
1266
2703
  # @return [void]
1267
2704
  # @api public
1268
- #: (untyped sqref, **untyped opts) -> void
1269
- def conditional_format(sqref, **opts)
2705
+ #: (?String? sqref, **untyped opts) ?{ (ConditionalFormatBuilder) -> void } -> void
2706
+ def conditional_format(sqref = nil, **opts, &)
1270
2707
  sheet if @current_sheet.nil?
1271
- @current_conditional_formats << opts.merge(sqref: sqref)
2708
+ normalized_list = DslHelpers.normalize_conditional_format(sqref, **opts, &)
2709
+ @current_conditional_formats.concat(normalized_list)
1272
2710
  end
1273
2711
 
1274
2712
  # Adds an Excel Table (ListObject).
@@ -1307,24 +2745,32 @@ module Xlsxrb
1307
2745
  # @param source_ref [String] Source data range.
1308
2746
  # @param row_fields [Array<Integer>] 0-based field indices for rows.
1309
2747
  # @param data_fields [Array<Hash>] Data fields.
1310
- # @param col_fields [Array<Integer>] 0-based field indices for columns.
1311
- # @param dest_ref [String] Top-left destination cell (default: "E1").
2748
+ # @param column_fields [Array<Integer>] 0-based field indices for columns.
2749
+ # @param col_fields [Array<Integer>] Deprecated alias for column_fields.
2750
+ # @param ref [String] Top-left destination cell (default: "E1").
2751
+ # @param dest_ref [String] Deprecated alias for ref.
1312
2752
  # @param name [String, nil] Pivot table name.
1313
2753
  # @param field_names [Array<String>, nil] Override field names.
1314
2754
  # @param items [Array, nil] Items configuration.
1315
2755
  # @param opts [Hash] Additional options.
1316
2756
  # @return [void]
1317
2757
  # @api public
1318
- #: (untyped source_ref, row_fields: untyped, data_fields: untyped, ?col_fields: untyped, ?dest_ref: untyped, ?name: untyped, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
1319
- def pivot_table(source_ref, row_fields:, data_fields:, col_fields: [], dest_ref: "E1", name: nil, field_names: nil, items: nil)
2758
+ #: (untyped source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?col_fields: untyped, ?ref: untyped, ?dest_ref: untyped, ?name: untyped, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
2759
+ 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)
1320
2760
  sheet if @current_sheet.nil?
2761
+ warn "[DEPRECATION] `col_fields:` is deprecated; use `column_fields:` instead.", uplevel: 1 if col_fields && column_fields.nil?
2762
+ warn "[DEPRECATION] `dest_ref:` is deprecated; use `ref:` instead.", uplevel: 1 if dest_ref && ref.nil?
2763
+ c_fields = column_fields || col_fields || []
2764
+ target_ref = ref || dest_ref || "E1"
1321
2765
  @current_pivot_tables ||= []
1322
- @current_pivot_tables << {
2766
+ entry = {
1323
2767
  source_ref: source_ref, row_fields: row_fields,
1324
- data_fields: data_fields, col_fields: col_fields,
1325
- dest_ref: dest_ref, name: name,
2768
+ data_fields: data_fields, column_fields: c_fields,
2769
+ col_fields: c_fields, ref: target_ref,
2770
+ dest_ref: target_ref, name: name,
1326
2771
  field_names: field_names, items: items
1327
- }
2772
+ }.merge(opts)
2773
+ @current_pivot_tables << entry
1328
2774
  end
1329
2775
 
1330
2776
  # Adds a comment to a cell.
@@ -1337,8 +2783,43 @@ module Xlsxrb
1337
2783
  #: (String | Integer cell, String text, ?author: ::String) -> void
1338
2784
  def comment(cell, text, author: "Author")
1339
2785
  sheet if @current_sheet.nil?
1340
- @current_comments << { cell: cell, text: text, author: author }
2786
+ ref_str = cell.to_s
2787
+ @current_comments << { ref: ref_str, text: text, author: author }
2788
+ nil
2789
+ end
2790
+
2791
+ # Adds a threaded comment to a cell.
2792
+ #
2793
+ # @param cell [String, Integer] Cell coordinate (e.g. "A1").
2794
+ # @param text [String] Comment text.
2795
+ # @param author [String] Author name.
2796
+ # @param timestamp [String, Time, nil] Optional ISO 8601 timestamp.
2797
+ # @param id [String, nil] Optional GUID for this comment.
2798
+ # @param parent_id [String, nil] Optional parent comment GUID for replies.
2799
+ # @param done [Boolean, nil] Optional resolved flag.
2800
+ # @param user_id [String, nil] Optional user ID.
2801
+ # @param provider_id [String, nil] Optional provider ID.
2802
+ # @return [void]
2803
+ # @api public
2804
+ #: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
2805
+ def threaded_comment(cell, text, author: "Author", timestamp: nil, id: nil, parent_id: nil, done: false, user_id: nil, provider_id: nil)
2806
+ sheet if @current_sheet.nil?
2807
+ ref_str = cell.to_s
2808
+ @current_threaded_comments << {
2809
+ ref: ref_str,
2810
+ text: text,
2811
+ author: author,
2812
+ timestamp: timestamp,
2813
+ id: id,
2814
+ parent_id: parent_id,
2815
+ done: done ? true : false,
2816
+ user_id: user_id,
2817
+ provider_id: provider_id
2818
+ }.compact
2819
+ nil
1341
2820
  end
2821
+ # @deprecated Use {#threaded_comment} instead. Will be removed in 0.2.0.
2822
+ alias add_threaded_comment threaded_comment
1342
2823
 
1343
2824
  # Adds a sparkline group.
1344
2825
  #
@@ -1371,10 +2852,12 @@ module Xlsxrb
1371
2852
  # @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
1372
2853
  # @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
1373
2854
  # @param opts [Hash] Additional sparkline options.
2855
+ # @deprecated Use {#sparkline_group} instead. Will be removed in 0.2.0.
1374
2856
  # @return [void]
1375
2857
  # @api public
1376
2858
  #: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
1377
2859
  def add_sparkline(location: nil, range: nil, type: nil, **opts)
2860
+ warn "[DEPRECATION] #add_sparkline is deprecated; use #sparkline_group instead.", uplevel: 1
1378
2861
  loc = location || opts.delete(:location_ref)
1379
2862
  rng = range || opts.delete(:data_ref) || opts.delete(:data)
1380
2863
  raise ArgumentError, "Missing required location: parameter for sparkline" unless loc
@@ -1390,6 +2873,10 @@ module Xlsxrb
1390
2873
 
1391
2874
  # Merges a range of cells into a single cell.
1392
2875
  #
2876
+ # @example
2877
+ # sheet.merge("A1:C1")
2878
+ #
2879
+ # @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.
1393
2880
  # @param range [String, Hash, nil] Cell range (e.g. "A1:B2") or hash of coordinates.
1394
2881
  # @param row [Integer, nil] Single row index.
1395
2882
  # @param col_start [Integer, String, nil] Starting column.
@@ -1410,47 +2897,156 @@ module Xlsxrb
1410
2897
  @current_merge_cells << canonical unless @current_merge_cells.include?(canonical)
1411
2898
  end
1412
2899
 
1413
- # Freezes window panes at the given row and column.
2900
+ # Freezes window panes at the given row and column, or queries freeze pane settings.
1414
2901
  #
1415
- # @param row [Integer] Number of rows to freeze.
1416
- # @param col [Integer, String] Number of columns to freeze.
2902
+ # @param row [Integer, nil] Number of rows to freeze.
2903
+ # @param column [Integer, String, nil] Number of columns to freeze.
2904
+ # @param col [Integer, String, nil] Deprecated alias for column.
2905
+ # @return [Elements::FreezePane, Hash<Symbol, untyped>, nil, void]
2906
+ # @api public
2907
+ #: (?row: Integer | nil, ?column: (Integer | String)?, ?col: (Integer | String)?) -> (untyped | void)
2908
+ def freeze_pane(row: nil, column: nil, col: nil)
2909
+ sheet if @current_sheet.nil?
2910
+ if row.nil? && column.nil? && col.nil?
2911
+ return nil unless @current_freeze_pane
2912
+ return Elements::FreezePane.new(**@current_freeze_pane) if defined?(Elements::FreezePane)
2913
+
2914
+ return @current_freeze_pane
2915
+ end
2916
+
2917
+ warn "[DEPRECATION] `col:` is deprecated; use `column:` instead.", uplevel: 1 if col && column.nil?
2918
+ col_val = Elements::Cell._column_index(column || col || 0)
2919
+ @current_freeze_pane = { row: row || 0, col: col_val, column: col_val }
2920
+ nil
2921
+ end
2922
+
2923
+ # Sets or clears freeze pane configuration.
2924
+ #
2925
+ # @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
1417
2926
  # @return [void]
1418
2927
  # @api public
1419
- #: (?row: Integer, ?col: (Integer | String)) -> void
1420
- def freeze_pane(row: 0, col: 0)
1421
- col = Elements::Cell.column_index(col)
2928
+ #: (untyped opts) -> void
2929
+ def freeze_pane=(opts)
1422
2930
  sheet if @current_sheet.nil?
1423
- @current_freeze_pane = { row: row, col: col }
2931
+ if opts.nil?
2932
+ @current_freeze_pane = nil
2933
+ else
2934
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
2935
+ c = h[:column] || h[:col]
2936
+ c = Elements::Cell._column_index(c) if c
2937
+ @current_freeze_pane = { row: h[:row] || 0, col: c || 0, column: c || 0 }
2938
+ end
2939
+ nil
1424
2940
  end
1425
2941
 
1426
- # Splits window panes without freezing.
2942
+ # Splits window panes without freezing or queries split pane settings.
1427
2943
  #
1428
- # @param x_split [Integer] Horizontal split in points.
1429
- # @param y_split [Integer] Vertical split in points.
2944
+ # @param x_split [Integer, nil] Horizontal split in points.
2945
+ # @param y_split [Integer, nil] Vertical split in points.
1430
2946
  # @param top_left_cell [String, nil] Top-left cell reference in bottom-right pane.
2947
+ # @param active_pane [String, Symbol, nil] Active pane identifier.
2948
+ # @param state [String, Symbol, nil] Split state.
2949
+ # @return [Elements::SplitPane, Hash<Symbol, untyped>, nil, void]
2950
+ # @api public
2951
+ #: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?, ?state: (String | Symbol)?) -> (untyped | void)
2952
+ def split_pane(x_split: nil, y_split: nil, top_left_cell: nil, active_pane: nil, state: nil)
2953
+ sheet if @current_sheet.nil?
2954
+ if x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil? && state.nil?
2955
+ return nil unless @current_split_pane
2956
+ return Elements::SplitPane.new(**@current_split_pane) if defined?(Elements::SplitPane)
2957
+
2958
+ return @current_split_pane
2959
+ end
2960
+
2961
+ entry = { x_split: x_split || 0, y_split: y_split || 0, top_left_cell: top_left_cell }
2962
+ entry[:active_pane] = active_pane.to_s if active_pane
2963
+ entry[:state] = state.to_s if state
2964
+ @current_split_pane = entry
2965
+ nil
2966
+ end
2967
+
2968
+ # Sets or clears split pane configuration.
2969
+ #
2970
+ # @param opts [Elements::SplitPane, Hash, nil] Split pane options.
1431
2971
  # @return [void]
1432
2972
  # @api public
1433
- #: (?x_split: ::Integer, ?y_split: ::Integer, ?top_left_cell: String?) -> void
1434
- def split_pane(x_split: 0, y_split: 0, top_left_cell: nil)
2973
+ #: (untyped opts) -> void
2974
+ def split_pane=(opts)
1435
2975
  sheet if @current_sheet.nil?
1436
- @current_split_pane = { x_split: x_split, y_split: y_split, top_left_cell: top_left_cell }
2976
+ if opts.nil?
2977
+ @current_split_pane = nil
2978
+ else
2979
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
2980
+ entry = { x_split: h[:x_split] || 0, y_split: h[:y_split] || 0, top_left_cell: h[:top_left_cell] }
2981
+ entry[:active_pane] = h[:active_pane].to_s if h[:active_pane]
2982
+ entry[:state] = h[:state].to_s if h[:state]
2983
+ @current_split_pane = entry
2984
+ end
2985
+ nil
1437
2986
  end
1438
2987
 
1439
- # Sets the active cell selection on the current sheet.
2988
+ # Sets or queries the active cell selection on the current sheet.
1440
2989
  #
1441
- # @param active_cell [String] Active cell reference (e.g. "A1").
2990
+ # @param active_cell [String, nil] Active cell reference (e.g. "A1") or range (e.g. "A1:D10").
1442
2991
  # @param sqref [String, nil] Selection range.
1443
2992
  # @param pane [String, Symbol, nil] Target pane.
1444
- # @return [void]
2993
+ # @return [Elements::Selection, Array<Elements::Selection>, Hash<Symbol, untyped>, nil, void]
1445
2994
  # @api public
1446
- #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
1447
- def select_cell(active_cell, sqref: nil, pane: nil)
2995
+ #: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> (untyped | void)
2996
+ def selection(active_cell = nil, sqref: nil, pane: nil)
1448
2997
  sheet if @current_sheet.nil?
1449
- @current_selection = { active_cell: active_cell, sqref: sqref || active_cell }
2998
+ if active_cell.nil? && sqref.nil? && pane.nil?
2999
+ return nil if @current_selection.nil?
3000
+
3001
+ if defined?(Elements::Selection)
3002
+ return @current_selection.map { |s| Elements::Selection.new(**s) } if @current_selection.is_a?(Array)
3003
+
3004
+ return Elements::Selection.new(**@current_selection)
3005
+ end
3006
+
3007
+ return @current_selection
3008
+ end
3009
+
3010
+ if sqref.nil? && active_cell.is_a?(String) && active_cell.include?(":")
3011
+ sqref = active_cell
3012
+ active_cell = sqref.split(":").first
3013
+ else
3014
+ sqref ||= active_cell
3015
+ end
3016
+ @current_selection = { active_cell: active_cell, sqref: sqref }
1450
3017
  @current_selection[:pane] = pane if pane
3018
+ nil
3019
+ end
3020
+
3021
+ # Sets or clears the selection configuration.
3022
+ #
3023
+ # @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
3024
+ # @return [void]
3025
+ # @api public
3026
+ #: (untyped opts) -> void
3027
+ def selection=(opts)
3028
+ sheet if @current_sheet.nil?
3029
+ @current_selection = if opts.nil?
3030
+ nil
3031
+ elsif opts.is_a?(Array)
3032
+ opts.map { |o| o.respond_to?(:to_h) ? o.to_h : o }
3033
+ else
3034
+ opts.respond_to?(:to_h) ? opts.to_h : opts
3035
+ end
3036
+ nil
3037
+ end
3038
+
3039
+ # @deprecated Use {#selection} instead.
3040
+ #: (String active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
3041
+ def select_cell(...)
3042
+ warn "[DEPRECATION] `select_cell` is deprecated; use `selection` instead.", uplevel: 1
3043
+ selection(...)
1451
3044
  end
1452
3045
 
1453
- # Sets page margins in inches for printing.
3046
+ # Configures page margins for printing (<pageMargins>).
3047
+ #
3048
+ # When called with no arguments, returns the page margins value object or hash.
3049
+ # When called with arguments, configures page margins and returns nil.
1454
3050
  #
1455
3051
  # @param left [Float, nil] Left margin.
1456
3052
  # @param right [Float, nil] Right margin.
@@ -1458,170 +3054,564 @@ module Xlsxrb
1458
3054
  # @param bottom [Float, nil] Bottom margin.
1459
3055
  # @param header [Float, nil] Header margin.
1460
3056
  # @param footer [Float, nil] Footer margin.
1461
- # @return [void]
3057
+ # @return [Elements::PageMargins, Hash<Symbol, untyped>, nil, void]
1462
3058
  # @api public
1463
- #: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> void
3059
+ #: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> (untyped | void)
1464
3060
  def page_margins(left: nil, right: nil, top: nil, bottom: nil, header: nil, footer: nil)
1465
3061
  sheet if @current_sheet.nil?
3062
+ if left.nil? && right.nil? && top.nil? && bottom.nil? && header.nil? && footer.nil?
3063
+ return nil unless @current_page_margins
3064
+ return Elements::PageMargins.new(**@current_page_margins) if defined?(Elements::PageMargins)
3065
+
3066
+ return @current_page_margins
3067
+ end
3068
+
1466
3069
  @current_page_margins = DslHelpers.normalize_page_margins(
1467
3070
  left: left, right: right, top: top, bottom: bottom, header: header, footer: footer
1468
3071
  )
3072
+ nil
3073
+ end
3074
+
3075
+ # Sets or clears page margins configuration.
3076
+ #
3077
+ # @param opts [Hash, Elements::PageMargins, nil]
3078
+ # @return [void]
3079
+ # @api public
3080
+ #: (untyped opts) -> void
3081
+ def page_margins=(opts)
3082
+ sheet if @current_sheet.nil?
3083
+ if opts.nil?
3084
+ @current_page_margins = nil
3085
+ else
3086
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
3087
+ @current_page_margins = DslHelpers.normalize_page_margins(**h)
3088
+ end
3089
+ nil
3090
+ end
3091
+
3092
+ # Configures or queries page setup configuration (<pageSetup>).
3093
+ #
3094
+ # When called with no arguments, returns the page setup value object or hash.
3095
+ # When called with keyword arguments, updates page setup and returns nil.
3096
+ #
3097
+ # @param opts [Hash] Page setup options (e.g. orientation: :landscape).
3098
+ # @return [Elements::PageSetup, Hash<Symbol, untyped>, void]
3099
+ # @api public
3100
+ #: (**untyped opts) -> (untyped | void)
3101
+ def page_setup(**opts)
3102
+ sheet if @current_sheet.nil?
3103
+ if opts.empty?
3104
+ return defined?(Elements::PageSetup) ? Elements::PageSetup.new(**@current_page_setup) : @current_page_setup
3105
+ end
3106
+
3107
+ @current_page_setup.merge!(opts)
3108
+ @current_sheet_properties[:fit_to_page] = true if (opts.key?(:fit_to_width) || opts.key?(:fit_to_height)) && !@current_sheet_properties.key?(:fit_to_page)
3109
+ nil
1469
3110
  end
1470
3111
 
1471
3112
  # Sets page setup configuration.
1472
3113
  #
1473
- # @param opts [Hash] Page setup options (e.g. orientation: :landscape).
3114
+ # @param opts [Hash, Elements::PageSetup]
1474
3115
  # @return [void]
1475
3116
  # @api public
1476
- #: (**untyped opts) -> void
1477
- def page_setup(**opts)
3117
+ #: (untyped opts) -> void
3118
+ def page_setup=(opts)
1478
3119
  sheet if @current_sheet.nil?
1479
- @current_page_setup.merge!(opts)
3120
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3121
+ @current_page_setup = h.transform_keys(&:to_sym)
3122
+ nil
1480
3123
  end
1481
3124
 
1482
- # Configures headers and footers for printing.
3125
+ # Configures or queries headers and footers for printing (<headerFooter>).
3126
+ #
3127
+ # When called with no arguments, returns the header/footer value object or hash.
3128
+ # When called with keyword arguments, updates headers and footers and returns nil.
1483
3129
  #
1484
3130
  # @param opts [Hash] Header/footer options.
1485
- # @return [void]
3131
+ # @return [Elements::HeaderFooter, Hash<Symbol, untyped>, void]
1486
3132
  # @api public
1487
- #: (**untyped opts) -> void
3133
+ #: (**untyped opts) -> (untyped | void)
1488
3134
  def header_footer(**opts)
1489
3135
  sheet if @current_sheet.nil?
3136
+ if opts.empty?
3137
+ return defined?(Elements::HeaderFooter) ? Elements::HeaderFooter.new(**@current_header_footer) : @current_header_footer
3138
+ end
3139
+
1490
3140
  @current_header_footer.merge!(opts)
3141
+ nil
3142
+ end
3143
+
3144
+ # Sets header and footer configuration.
3145
+ #
3146
+ # @param opts [Hash, Elements::HeaderFooter]
3147
+ # @return [void]
3148
+ # @api public
3149
+ #: (untyped opts) -> void
3150
+ def header_footer=(opts)
3151
+ sheet if @current_sheet.nil?
3152
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3153
+ @current_header_footer = h.transform_keys(&:to_sym)
3154
+ nil
1491
3155
  end
1492
3156
 
1493
- # Sets a print option (e.g. grid_lines: true).
3157
+ # Configures or queries print options (<printOptions>).
1494
3158
  #
1495
- # @param name [Symbol] Option name.
1496
- # @param value [Object] Option value.
3159
+ # When called with no arguments, returns the {Elements::PrintOptions} value object.
3160
+ # When called with arguments or keyword options, configures print options and returns nil.
3161
+ #
3162
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Option name or hash/record of options.
3163
+ # @param value [Object, nil] Option value.
3164
+ # @param opts [Hash] Additional print options.
3165
+ # @return [Elements::PrintOptions, void]
3166
+ # @api public
3167
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::PrintOptions | void)
3168
+ def print_options(name = nil, value = nil, **opts)
3169
+ sheet if @current_sheet.nil?
3170
+ return Elements::PrintOptions.new(**@current_print_options) if name.nil? && value.nil? && opts.empty?
3171
+
3172
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3173
+ opts = name.to_h.merge(opts)
3174
+ name = nil
3175
+ end
3176
+ @current_print_options[name.to_sym] = value if name && !value.nil?
3177
+ opts.each { |k, v| @current_print_options[k.to_sym] = v }
3178
+ nil
3179
+ end
3180
+
3181
+ # Replaces print options with the given hash or {Elements::PrintOptions} object.
3182
+ #
3183
+ # @param opts [Hash, Elements::PrintOptions]
1497
3184
  # @return [void]
1498
3185
  # @api public
1499
- #: (Symbol name, untyped value) -> void
1500
- def print_options(name, value)
3186
+ #: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
3187
+ def print_options=(opts)
1501
3188
  sheet if @current_sheet.nil?
1502
- @current_print_options[name] = value
3189
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3190
+ @current_print_options = h.transform_keys(&:to_sym)
3191
+ nil
1503
3192
  end
1504
3193
 
1505
- # Sets sheet-level protection with optional password hashing.
3194
+ # Configures or queries sheet-level protection with optional password hashing (<sheetProtection>).
3195
+ #
3196
+ # When called with no arguments, returns the sheet protection value object or hash.
3197
+ # When called with keyword arguments, sets sheet protection and returns nil.
1506
3198
  #
1507
3199
  # @param opts [Hash] Protection options.
3200
+ # @return [Elements::SheetProtection, Hash<Symbol, untyped>, nil, void]
3201
+ # @api public
3202
+ #: (**untyped opts) -> (untyped | void)
3203
+ def sheet_protection(**opts)
3204
+ sheet if @current_sheet.nil?
3205
+ if opts.empty?
3206
+ return nil unless @current_sheet_protection
3207
+ return Elements::SheetProtection.new(**@current_sheet_protection) if defined?(Elements::SheetProtection)
3208
+
3209
+ @current_sheet_protection
3210
+ else
3211
+ @current_sheet_protection = DslHelpers.normalize_protection_options(opts)
3212
+ nil
3213
+ end
3214
+ end
3215
+
3216
+ # Sets or clears sheet protection configuration.
3217
+ #
3218
+ # @param opts [Elements::SheetProtection, Hash, Boolean, nil]
1508
3219
  # @return [void]
1509
3220
  # @api public
1510
- #: (**untyped opts) -> void
1511
- def protect_sheet(**opts)
3221
+ #: (untyped opts) -> void
3222
+ def sheet_protection=(opts)
1512
3223
  sheet if @current_sheet.nil?
1513
- @current_sheet_protection = DslHelpers.normalize_protection_options(opts)
3224
+ if opts.nil? || opts == false
3225
+ @current_sheet_protection = nil
3226
+ elsif opts == true
3227
+ @current_sheet_protection = DslHelpers.normalize_protection_options(sheet: true)
3228
+ else
3229
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
3230
+ @current_sheet_protection = DslHelpers.normalize_protection_options(h)
3231
+ end
3232
+ nil
3233
+ end
3234
+
3235
+ # @deprecated Use {#sheet_protection} instead.
3236
+ #: (**untyped opts) -> void
3237
+ def protect_sheet(...)
3238
+ warn "[DEPRECATION] `protect_sheet` is deprecated; use `sheet_protection` instead.", uplevel: 1
3239
+ sheet_protection(...)
1514
3240
  end
1515
3241
 
1516
3242
  # Inserts an embedded image into the active sheet.
1517
3243
  #
1518
3244
  # @param file_data [String] Binary image data.
1519
3245
  # @param ext [String] File extension ("png", "jpeg", etc.).
1520
- # @param from_col [Integer] Top-left starting column.
3246
+ # @param from_column [Integer, nil] Top-left starting column.
3247
+ # @param from_col [Integer, nil] Deprecated alias for from_column.
1521
3248
  # @param from_row [Integer] Top-left starting row.
1522
- # @param to_col [Integer] Bottom-right ending column.
3249
+ # @param to_column [Integer, nil] Bottom-right ending column.
3250
+ # @param to_col [Integer, nil] Deprecated alias for to_column.
1523
3251
  # @param to_row [Integer] Bottom-right ending row.
1524
3252
  # @param opts [Hash] Additional options.
1525
3253
  # @return [void]
1526
3254
  # @api public
1527
- #: (String file_data, ?ext: ::String, ?from_col: ::Integer, ?from_row: ::Integer, ?to_col: ::Integer, ?to_row: ::Integer, **untyped opts) -> void
1528
- def image(file_data, ext: "png", from_col: 0, from_row: 0, to_col: 5, to_row: 10, **opts)
3255
+ #: (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
3256
+ 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)
3257
+ warn "[DEPRECATION] `from_col:` is deprecated; use `from_column:` instead.", uplevel: 1 if from_col && from_column.nil?
3258
+ warn "[DEPRECATION] `to_col:` is deprecated; use `to_column:` instead.", uplevel: 1 if to_col && to_column.nil?
3259
+ fc = from_column || from_col || 0
3260
+ tc = to_column || to_col || 5
1529
3261
  sheet if @current_sheet.nil?
1530
- img = { file_data: file_data, ext: ext, from_col: from_col, from_row: from_row, to_col: to_col, to_row: to_row }
3262
+ 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 }
1531
3263
  img.merge!(opts)
1532
3264
  @current_images << img
1533
3265
  end
1534
3266
 
3267
+ # Configures the worksheet background image (<picture>).
3268
+ #
3269
+ # @example Set background image from binary data
3270
+ # sheet.background_image(png_bytes, ext: "png")
3271
+ #
3272
+ # @example Set background image from file path
3273
+ # sheet.background_image("path/to/background.png")
3274
+ #
3275
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#background_image=} instead.
3276
+ # @param file_data [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
3277
+ # @param ext [String, nil] Image extension ("png", "jpeg", "jpg", "gif", etc.).
3278
+ # @param opts [Hash] Additional image options.
3279
+ # @return [Hash, nil]
3280
+ # @api public
3281
+ #: (?untyped file_data, ?ext: ::String?, **untyped opts) -> Hash[Symbol, untyped]?
3282
+ def background_image(file_data = nil, ext: nil, **opts)
3283
+ if file_data.nil? && ext.nil? && opts.empty?
3284
+ return nil unless @current_background_image
3285
+
3286
+ return @current_background_image.is_a?(Elements::BackgroundImage) ? @current_background_image : Elements::BackgroundImage.new(**@current_background_image)
3287
+ end
3288
+
3289
+ sheet if @current_sheet.nil?
3290
+
3291
+ data = file_data
3292
+ inferred_ext = nil
3293
+ if data.is_a?(String) && !data.include?("\x00") && File.file?(data)
3294
+ inferred_ext = File.extname(data).delete_prefix(".").downcase
3295
+ data = File.binread(data)
3296
+ elsif data.is_a?(Hash)
3297
+ inferred_ext = data[:ext] || (data[:filename] && File.extname(data[:filename]).delete_prefix("."))
3298
+ data = data[:file_data] || data[:data]
3299
+ elsif data.is_a?(Elements::Image)
3300
+ inferred_ext = File.extname(data.filename).delete_prefix(".").downcase
3301
+ data = data.data
3302
+ end
3303
+
3304
+ final_ext = (ext || inferred_ext || opts[:ext] || "png").to_s.delete_prefix(".").downcase
3305
+ mime = case final_ext
3306
+ when "png" then "image/png"
3307
+ when "jpg", "jpeg" then "image/jpeg"
3308
+ when "gif" then "image/gif"
3309
+ when "bmp" then "image/bmp"
3310
+ when "emf" then "image/x-emf"
3311
+ when "wmf" then "image/x-wmf"
3312
+ else "application/octet-stream"
3313
+ end
3314
+
3315
+ @current_background_image = {
3316
+ data: data&.b,
3317
+ file_data: data&.b,
3318
+ ext: final_ext,
3319
+ filename: "background.#{final_ext}",
3320
+ content_type: mime
3321
+ }.merge(opts).freeze
3322
+ end
3323
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
3324
+ alias background_picture background_image
3325
+ # @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
3326
+ alias picture background_image
3327
+
3328
+ #: (untyped val) -> untyped
3329
+ def background_image=(val)
3330
+ sheet if @current_sheet.nil?
3331
+ if val.nil?
3332
+ @current_background_image = nil
3333
+ else
3334
+ background_image(val)
3335
+ end
3336
+ val
3337
+ end
3338
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
3339
+ alias background_picture= background_image=
3340
+ # @deprecated Use {#background_image=} instead. Will be removed in 0.2.0.
3341
+ alias picture= background_image=
3342
+
1535
3343
  # Inserts a drawing shape.
1536
3344
  #
1537
3345
  # @param preset [String] Preset shape name.
1538
3346
  # @param text [String, nil] Label text.
1539
- # @param from_col [Integer] Top-left column.
3347
+ # @param from_column [Integer, nil] Top-left column.
3348
+ # @param from_col [Integer, nil] Deprecated alias for from_column.
1540
3349
  # @param from_row [Integer] Top-left row.
1541
- # @param to_col [Integer] Bottom-right column.
3350
+ # @param to_column [Integer, nil] Bottom-right column.
3351
+ # @param to_col [Integer, nil] Deprecated alias for to_column.
1542
3352
  # @param to_row [Integer] Bottom-right row.
1543
3353
  # @param opts [Hash] Additional options.
1544
3354
  # @return [void]
1545
3355
  # @api public
1546
3356
  #: (**untyped opts) -> void
1547
- def shape(preset: "rect", text: nil, from_col: 0, from_row: 0, to_col: 5, to_row: 5, **opts)
3357
+ 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)
3358
+ warn "[DEPRECATION] `from_col:` is deprecated; use `from_column:` instead.", uplevel: 1 if from_col && from_column.nil?
3359
+ warn "[DEPRECATION] `to_col:` is deprecated; use `to_column:` instead.", uplevel: 1 if to_col && to_column.nil?
3360
+ fc = from_column || from_col || 0
3361
+ tc = to_column || to_col || 5
1548
3362
  sheet if @current_sheet.nil?
1549
- shape = { preset: preset, text: text, from_col: from_col, from_row: from_row, to_col: to_col, to_row: to_row }
1550
- shape[:name] = opts.delete(:name) || "Shape #{@current_shapes.size + 1}"
1551
- shape.merge!(opts)
1552
- @current_shapes << shape
3363
+ 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 }
3364
+ shape_data[:name] = opts.delete(:name) || "Shape #{@current_shapes.size + 1}"
3365
+ shape_data.merge!(opts)
3366
+ @current_shapes << shape_data
1553
3367
  end
1554
3368
 
1555
- # Sets a sheet-level property (e.g. tab_color: "FF0000").
3369
+ # Gets or sets the sheet visibility state (:visible, :hidden, or :very_hidden).
1556
3370
  #
1557
- # @param name [Symbol] Property name.
3371
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#state=} instead.
3372
+ # @param new_state [Symbol, nil] The new state.
3373
+ # @return [Symbol]
3374
+ # @api public
3375
+ #: (?Symbol? new_state) -> Symbol
3376
+ def state(new_state = nil)
3377
+ sheet if @current_sheet.nil?
3378
+ if new_state
3379
+ sheet_properties(:state, new_state)
3380
+ @current_sheet_state
3381
+ else
3382
+ @current_sheet_state || :visible
3383
+ end
3384
+ end
3385
+
3386
+ # Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
3387
+ #
3388
+ # @param new_state [Symbol, String] The new state.
3389
+ # @return [Symbol]
3390
+ # @api public
3391
+ #: (Symbol | String new_state) -> Symbol
3392
+ def state=(new_state)
3393
+ sheet if @current_sheet.nil?
3394
+ sheet_properties(:state, new_state)
3395
+ @current_sheet_state
3396
+ end
3397
+
3398
+ # Gets or sets the tab color of the current worksheet.
3399
+ #
3400
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_color=} instead.
3401
+ # @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
3402
+ # @param opts [Hash] Color keyword arguments (e.g. theme: 1, tint: 0.5).
3403
+ # @return [String, Hash, nil]
3404
+ # @api public
3405
+ #: (?String | Symbol | Hash[Symbol, untyped] | nil spec, **untyped opts) -> (String | Hash[Symbol, untyped] | nil)
3406
+ def tab_color(spec = OMITTED, **opts)
3407
+ sheet if @current_sheet.nil?
3408
+ if spec.equal?(OMITTED) && opts.empty?
3409
+ @current_sheet_properties[:tab_color]
3410
+ else
3411
+ color = if opts.empty?
3412
+ spec
3413
+ else
3414
+ spec.is_a?(Hash) ? spec.merge(opts) : opts
3415
+ end
3416
+ @current_sheet_properties[:tab_color] = color
3417
+ end
3418
+ end
3419
+
3420
+ # Sets the tab color of the current worksheet.
3421
+ #
3422
+ # @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
3423
+ # @return [String, Hash, nil]
3424
+ # @api public
3425
+ #: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
3426
+ def tab_color=(spec)
3427
+ sheet if @current_sheet.nil?
3428
+ @current_sheet_properties[:tab_color] = spec
3429
+ end
3430
+
3431
+ # Sets a single sheet property.
3432
+ #
3433
+ # @param name [Symbol, String] Property name.
1558
3434
  # @param value [Object] Property value.
1559
3435
  # @return [void]
1560
3436
  # @api public
1561
- #: (Symbol name, untyped value) -> void
1562
- def sheet_properties(name, value)
3437
+ #: (Symbol | String name, untyped value) -> void
3438
+ def sheet_property(name, value)
3439
+ sheet_properties(name, value)
3440
+ end
3441
+
3442
+ # Configures or queries sheet properties (<sheetPr>).
3443
+ #
3444
+ # When called with no arguments, returns the {Elements::SheetProperties} value object.
3445
+ # When called with arguments or keyword options, configures properties and returns nil.
3446
+ #
3447
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
3448
+ # @param value [Object, nil] Property value when name is provided.
3449
+ # @param opts [Hash] Additional sheet properties.
3450
+ # @return [Elements::SheetProperties, void]
3451
+ # @api public
3452
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetProperties | void)
3453
+ def sheet_properties(name = nil, value = nil, **opts)
3454
+ sheet if @current_sheet.nil?
3455
+ return Elements::SheetProperties.new(**@current_sheet_properties) if name.nil? && value.nil? && opts.empty?
3456
+
3457
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3458
+ opts = name.to_h.merge(opts)
3459
+ name = nil
3460
+ end
3461
+ if name && !value.nil?
3462
+ sym = name.to_sym
3463
+ if sym == :state
3464
+ val = value.to_sym
3465
+ raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
3466
+
3467
+ @current_sheet_state = val
3468
+ return nil
3469
+ elsif sym == :hidden
3470
+ @current_sheet_state = value ? :hidden : :visible
3471
+ return nil
3472
+ end
3473
+ @current_sheet_properties[name.to_sym] = value
3474
+ end
3475
+ opts.each { |k, v| sheet_properties(k, v) }
3476
+ nil
3477
+ end
3478
+
3479
+ # Replaces worksheet properties with the given hash or {Elements::SheetProperties} object.
3480
+ #
3481
+ # @param opts [Hash, Elements::SheetProperties]
3482
+ # @return [void]
3483
+ # @api public
3484
+ #: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
3485
+ def sheet_properties=(opts)
3486
+ sheet if @current_sheet.nil?
3487
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3488
+ @current_sheet_properties = {}
3489
+ h.each { |k, v| sheet_properties(k, v) }
3490
+ nil
3491
+ end
3492
+
3493
+ # Configures or queries sheet view display properties (<sheetView>).
3494
+ #
3495
+ # When called with no arguments, returns the {Elements::SheetView} value object.
3496
+ # When called with arguments or keyword options, configures view properties and returns nil.
3497
+ #
3498
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] View property name or hash/record of properties.
3499
+ # @param value [Object, nil] View property value when name is provided.
3500
+ # @param opts [Hash] Additional view properties.
3501
+ # @return [Elements::SheetView, void]
3502
+ # @api public
3503
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetView | void)
3504
+ def sheet_view(name = nil, value = nil, **opts)
1563
3505
  sheet if @current_sheet.nil?
1564
- @current_sheet_properties[name] = value
3506
+ return Elements::SheetView.new(**@current_sheet_view) if name.nil? && value.nil? && opts.empty?
3507
+
3508
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3509
+ opts = name.to_h.merge(opts)
3510
+ name = nil
3511
+ end
3512
+ @current_sheet_view[name.to_sym] = value if name && !value.nil?
3513
+ opts.each { |k, v| @current_sheet_view[k.to_sym] = v }
3514
+ nil
1565
3515
  end
1566
3516
 
1567
- # Sets a sheet view property (e.g. zoom_scale: 120).
3517
+ # Replaces sheet view properties with the given hash or {Elements::SheetView} object.
1568
3518
  #
1569
- # @param name [Symbol] View property name.
1570
- # @param value [Object] View property value.
3519
+ # @param opts [Hash, Elements::SheetView]
1571
3520
  # @return [void]
1572
3521
  # @api public
1573
- #: (Symbol name, untyped value) -> void
1574
- def sheet_view(name, value)
3522
+ #: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
3523
+ def sheet_view=(opts)
1575
3524
  sheet if @current_sheet.nil?
1576
- @current_sheet_view[name] = value
3525
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3526
+ @current_sheet_view = h.transform_keys(&:to_sym)
3527
+ nil
1577
3528
  end
1578
3529
 
1579
- # Configures sheet format properties (e.g. default_row_height, default_col_width).
3530
+ # Configures or queries sheet format properties (<sheetFormatPr>).
1580
3531
  #
1581
- # @param name [Symbol, String, Hash, nil] Property name or hash of properties.
3532
+ # When called with no arguments, returns the {Elements::SheetFormat} value object.
3533
+ # When called with arguments or keyword options, configures format properties and returns nil.
3534
+ #
3535
+ # @param name [Symbol, String, Hash, Elements::MetadataRecord, nil] Property name or hash/record of properties.
1582
3536
  # @param value [Object, nil] Property value when name is provided.
1583
3537
  # @param opts [Hash] Keyword arguments for sheet format properties.
1584
- # @return [Hash[Symbol, untyped]]
3538
+ # @return [Elements::SheetFormat, void]
1585
3539
  # @api public
1586
- #: (?Symbol | String | Hash[Symbol, untyped] | nil name, ?untyped value, **untyped opts) -> Hash[Symbol, untyped]
3540
+ #: (?Symbol | String | Hash[Symbol, untyped] | Elements::MetadataRecord | nil name, ?untyped value, **untyped opts) -> (Elements::SheetFormat | void)
1587
3541
  def sheet_format(name = nil, value = nil, **opts)
1588
3542
  sheet if @current_sheet.nil?
1589
- if name.is_a?(Hash)
1590
- @current_sheet_format.merge!(name)
3543
+ return Elements::SheetFormat.new(**@current_sheet_format) if name.nil? && value.nil? && opts.empty?
3544
+
3545
+ if name.is_a?(Hash) || (name.respond_to?(:to_h) && !name.is_a?(Symbol) && !name.is_a?(String))
3546
+ @current_sheet_format.merge!(name.to_h)
1591
3547
  elsif name && value
1592
3548
  @current_sheet_format[name.to_sym] = value
1593
3549
  end
3550
+ if opts.key?(:default_col_width) && !opts.key?(:default_column_width)
3551
+ warn "[DEPRECATION] `default_col_width:` is deprecated; use `default_column_width:` instead.", uplevel: 1
3552
+ opts[:default_column_width] = opts[:default_col_width]
3553
+ end
3554
+ if opts.key?(:base_col_width) && !opts.key?(:base_column_width)
3555
+ warn "[DEPRECATION] `base_col_width:` is deprecated; use `base_column_width:` instead.", uplevel: 1
3556
+ opts[:base_column_width] = opts[:base_col_width]
3557
+ end
3558
+ if opts.key?(:outline_level_col) && !opts.key?(:outline_level_column)
3559
+ warn "[DEPRECATION] `outline_level_col:` is deprecated; use `outline_level_column:` instead.", uplevel: 1
3560
+ opts[:outline_level_column] = opts[:outline_level_col]
3561
+ end
1594
3562
  @current_sheet_format.merge!(opts) unless opts.empty?
1595
- @current_sheet_format
3563
+ nil
3564
+ end
3565
+
3566
+ # Replaces sheet format properties with the given hash or {Elements::SheetFormat} object.
3567
+ #
3568
+ # @param opts [Hash, Elements::SheetFormat]
3569
+ # @return [void]
3570
+ # @api public
3571
+ #: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
3572
+ def sheet_format=(opts)
3573
+ sheet if @current_sheet.nil?
3574
+ h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
3575
+ @current_sheet_format = {}
3576
+ sheet_format(h)
3577
+ nil
1596
3578
  end
1597
3579
 
1598
- # Inserts a horizontal page break before a row.
3580
+ # Inserts a horizontal page break after the given 0-based row.
1599
3581
  #
1600
- # @param row_num [Integer] 1-based row number.
3582
+ # @param row_index [Integer] 0-based row index.
1601
3583
  # @return [void]
1602
3584
  # @api public
3585
+ #: (Integer row_index) -> void
3586
+ def row_break(row_index)
3587
+ sheet if @current_sheet.nil?
3588
+ @current_row_breaks << { id: row_index, max: 16_383, man: 1 }
3589
+ end
3590
+
3591
+ # @deprecated Use {#row_break} instead.
1603
3592
  #: (Integer row_num) -> void
1604
3593
  def page_break_row(row_num)
1605
- # simplecov:disable
1606
- # Edge case / untested delegation block
1607
- sheet if @current_sheet.nil?
1608
- @current_row_breaks << row_num
1609
- # simplecov:enable
3594
+ warn "[DEPRECATION] `page_break_row` is deprecated; use `row_break` instead.", uplevel: 1
3595
+ row_break(row_num)
1610
3596
  end
1611
3597
 
1612
- # Inserts a vertical page break before a column.
3598
+ # Inserts a vertical page break after the given column.
1613
3599
  #
1614
- # @param col_index [Integer, String] 0-based column index or letter ("B").
3600
+ # @param col [Integer, String, Symbol] 0-based column index or letter ("B", :B).
1615
3601
  # @return [void]
1616
3602
  # @api public
1617
- #: (Integer col_index) -> void
1618
- def page_break_col(col_index)
1619
- # simplecov:disable
1620
- # Edge case / untested delegation block
1621
- col_index = Elements::Cell.column_index(col_index)
3603
+ #: (Integer | String | Symbol col) -> void
3604
+ def column_break(col)
3605
+ col_index = Elements::Cell._column_index(col)
1622
3606
  sheet if @current_sheet.nil?
1623
- @current_col_breaks << col_index
1624
- # simplecov:enable
3607
+ @current_col_breaks << { id: col_index, max: 1_048_575, man: 1 }
3608
+ end
3609
+
3610
+ # @deprecated Use {#column_break} instead.
3611
+ #: (Integer | String | Symbol col_index) -> void
3612
+ def page_break_col(col_index)
3613
+ warn "[DEPRECATION] `page_break_col` is deprecated; use `column_break` instead.", uplevel: 1
3614
+ column_break(col_index)
1625
3615
  end
1626
3616
 
1627
3617
  # Adds a protected range to the current sheet.
@@ -1640,6 +3630,7 @@ module Xlsxrb
1640
3630
  entry.merge!(opts) unless opts.empty?
1641
3631
  @current_protected_ranges << DslHelpers.normalize_protection_options(entry)
1642
3632
  end
3633
+ # @deprecated Use {#protected_range} instead. Will be removed in 0.2.0.
1643
3634
  alias add_protected_range protected_range
1644
3635
 
1645
3636
  # Adds a cell watch to the current sheet.
@@ -1652,66 +3643,408 @@ module Xlsxrb
1652
3643
  sheet if @current_sheet.nil?
1653
3644
  @current_cell_watches << ref.to_s
1654
3645
  end
3646
+ # @deprecated Use {#cell_watch} instead. Will be removed in 0.2.0.
1655
3647
  alias add_cell_watch cell_watch
1656
3648
 
3649
+ # Adds an ignored error entry to the current sheet.
3650
+ #
3651
+ # @param sqref [String] Cell range reference (e.g. "A1" or "A1:B10").
3652
+ # @param opts [Hash] Error check flags to ignore.
3653
+ # @return [void]
3654
+ # @api public
3655
+ #: (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
3656
+ def ignored_error(sqref, **opts)
3657
+ sheet if @current_sheet.nil?
3658
+ @current_ignored_errors << { sqref: sqref.to_s }.merge(opts)
3659
+ end
3660
+
3661
+ # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
3662
+ #: (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
3663
+ def ignore_error(sqref, **opts)
3664
+ warn "[DEPRECATION] #ignore_error is deprecated; use #ignored_error instead.", uplevel: 1
3665
+ ignored_error(sqref, **opts)
3666
+ end
3667
+
3668
+ # @deprecated Use {#ignored_error} instead. Will be removed in 0.2.0.
3669
+ #: (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
3670
+ def add_ignored_error(sqref, **opts)
3671
+ warn "[DEPRECATION] #add_ignored_error is deprecated; use #ignored_error instead.", uplevel: 1
3672
+ ignored_error(sqref, **opts)
3673
+ end
3674
+
3675
+ # Returns the ignored error entries configured for the current sheet.
3676
+ #
3677
+ # @return [Array<Hash[Symbol, untyped]>]
3678
+ # @api public
3679
+ #: () -> Array[Hash[Symbol, untyped]]
3680
+ def ignored_errors
3681
+ @current_ignored_errors.map { |ie| ie.is_a?(Elements::IgnoredError) ? ie : Elements::IgnoredError.new(**ie) }.freeze
3682
+ end
3683
+
3684
+ # Gets or sets phonetic (furigana) guide properties for the current sheet.
3685
+ #
3686
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#phonetic_properties=} instead.
3687
+ # @overload phonetic_properties()
3688
+ # Returns the current phonetic properties.
3689
+ # @return [Hash, nil]
3690
+ # @overload phonetic_properties(spec = nil, font_id: nil, type: nil, alignment: nil)
3691
+ # Sets phonetic properties for the current sheet.
3692
+ # @param spec [Hash, Integer, nil]
3693
+ # @param font_id [Integer, nil]
3694
+ # @param type [Symbol, String, nil]
3695
+ # @param alignment [Symbol, String, nil]
3696
+ # @return [Hash, nil]
3697
+ # @api public
3698
+ #: (?untyped spec, ?font_id: Integer?, ?type: (Symbol | String)?, ?alignment: (Symbol | String)?, **untyped opts) -> (Elements::PhoneticProperties | Hash[Symbol, untyped] | nil)
3699
+ def phonetic_properties(spec = OMITTED, font_id: nil, type: nil, alignment: nil, **opts)
3700
+ sheet if @current_sheet.nil?
3701
+ if spec.equal?(OMITTED) && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
3702
+ return nil unless @current_phonetic_properties
3703
+
3704
+ @current_phonetic_properties.is_a?(Elements::PhoneticProperties) ? @current_phonetic_properties : Elements::PhoneticProperties.new(**@current_phonetic_properties)
3705
+ elsif !spec.equal?(OMITTED) && spec.nil? && font_id.nil? && type.nil? && alignment.nil? && opts.empty?
3706
+ @current_phonetic_properties = nil
3707
+ else
3708
+ props = if spec.is_a?(Hash)
3709
+ spec.merge(opts)
3710
+ elsif spec.is_a?(Integer)
3711
+ { font_id: spec, type: type, alignment: alignment }.merge(opts)
3712
+ else
3713
+ { font_id: font_id, type: type, alignment: alignment }.merge(opts)
3714
+ end
3715
+ props.compact!
3716
+ @current_phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
3717
+ end
3718
+ end
3719
+ # @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
3720
+ alias phonetic_pr phonetic_properties
3721
+
3722
+ # Sets phonetic (furigana) guide properties for the current sheet.
3723
+ #
3724
+ # @param spec [Hash, Integer, nil]
3725
+ # @return [Hash[Symbol, untyped], Integer, nil]
3726
+ # @api public
3727
+ #: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
3728
+ def phonetic_properties=(spec)
3729
+ sheet if @current_sheet.nil?
3730
+ if spec.nil?
3731
+ @current_phonetic_properties = nil
3732
+ else
3733
+ props = if spec.is_a?(Hash)
3734
+ spec.dup
3735
+ elsif spec.is_a?(Integer)
3736
+ { font_id: spec }
3737
+ else
3738
+ {}
3739
+ end
3740
+ @current_phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
3741
+ end
3742
+ spec
3743
+ end
3744
+ # @deprecated Use {#phonetic_properties=} instead. Will be removed in 0.2.0.
3745
+ alias phonetic_pr= phonetic_properties=
3746
+
3747
+ # Sets or gets the internal code name of the current worksheet (or workbook if no sheet is open).
3748
+ #
3749
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
3750
+ # @param val [String, Symbol, nil] The code name.
3751
+ # @return [String, nil]
3752
+ # @api public
3753
+ #: (?String | Symbol | nil val) -> String?
3754
+ def code_name(val = OMITTED)
3755
+ if @current_sheet.nil?
3756
+ if val.equal?(OMITTED)
3757
+ @workbook_properties[:code_name]
3758
+ else
3759
+ @workbook_properties[:code_name] = val&.to_s
3760
+ end
3761
+ elsif val.equal?(OMITTED)
3762
+ @current_sheet_properties[:code_name]
3763
+ else
3764
+ @current_sheet_properties[:code_name] = val&.to_s
3765
+ end
3766
+ end
3767
+
3768
+ # Sets the internal code name of the current worksheet (or workbook if no sheet is open).
3769
+ #
3770
+ # @param val [String, Symbol, nil] The code name.
3771
+ # @return [String, nil]
3772
+ # @api public
3773
+ #: (String | Symbol | nil val) -> String?
3774
+ def code_name=(val)
3775
+ if @current_sheet.nil?
3776
+ @workbook_properties[:code_name] = val&.to_s
3777
+ else
3778
+ @current_sheet_properties[:code_name] = val&.to_s
3779
+ end
3780
+ end
3781
+
3782
+ # Configures whether page setup fits content to page width/height for the current sheet.
3783
+ # When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
3784
+ #
3785
+ # @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.
3786
+ # @param enabled [Boolean, nil] Whether to fit to page.
3787
+ # @param width [Integer, nil] Pages wide to fit to.
3788
+ # @param height [Integer, nil] Pages tall to fit to.
3789
+ # @return [Boolean, void]
3790
+ # @api public
3791
+ #: (?bool? enabled, ?width: Integer?, ?height: Integer?) -> (bool | void)
3792
+ def fit_to_page(enabled = OMITTED, width: nil, height: nil)
3793
+ sheet if @current_sheet.nil?
3794
+ if enabled.equal?(OMITTED) && width.nil? && height.nil?
3795
+ return @current_sheet_properties[:fit_to_page] ? true : false
3796
+ end
3797
+
3798
+ @current_sheet_properties[:fit_to_page] = if enabled.equal?(OMITTED)
3799
+ true
3800
+ else
3801
+ enabled ? true : false
3802
+ end
3803
+ page_setup(fit_to_width: width) if width
3804
+ page_setup(fit_to_height: height) if height
3805
+ end
3806
+
3807
+ # @deprecated Use {#fit_to_page} instead. Will be removed in 0.2.0.
3808
+ # @return [Boolean]
3809
+ # @api public
3810
+ #: () -> bool
3811
+ def fit_to_page?
3812
+ warn "[Xlsxrb DEPRECATION] fit_to_page? is deprecated; use fit_to_page instead.", uplevel: 1
3813
+ fit_to_page
3814
+ end
3815
+
3816
+ # Sets whether page setup fits content to page width/height for the current sheet.
3817
+ #
3818
+ # @param enabled [Boolean, nil] Whether to fit to page.
3819
+ # @return [Boolean]
3820
+ # @api public
3821
+ #: (bool? enabled) -> bool?
3822
+ def fit_to_page=(enabled)
3823
+ sheet if @current_sheet.nil?
3824
+ @current_sheet_properties[:fit_to_page] = enabled ? true : false
3825
+ end
3826
+
3827
+ # Configures worksheet calculation properties (<sheetCalcPr>) for the current sheet.
3828
+ #
3829
+ # @example Instruct Excel to recalculate formulas when loading sheet
3830
+ # w.sheet_calc_properties = { full_calc_on_load: true }
3831
+ #
3832
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#sheet_calc_properties=} instead.
3833
+ # @param spec [Hash, nil] Calculation properties hash.
3834
+ # @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
3835
+ # @return [Hash, nil]
3836
+ # @api public
3837
+ #: (?untyped spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
3838
+ def sheet_calc_properties(spec = OMITTED, full_calc_on_load: nil, **opts)
3839
+ sheet if @current_sheet.nil?
3840
+ if spec.equal?(OMITTED) && full_calc_on_load.nil? && opts.empty?
3841
+ calc = @current_sheet_calc_pr || (@current_sheet_properties[:full_calc_on_load] ? { full_calc_on_load: true } : nil)
3842
+ return nil unless calc
3843
+
3844
+ return calc.is_a?(Elements::SheetCalcProperties) ? calc : Elements::SheetCalcProperties.new(**calc)
3845
+ end
3846
+
3847
+ 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
3848
+ if !spec.equal?(OMITTED) && spec.nil? && full_calc_on_load.nil? && opts.empty?
3849
+ @current_sheet_properties.delete(:full_calc_on_load)
3850
+ return @current_sheet_calc_pr = nil
3851
+ end
3852
+
3853
+ pr = spec.is_a?(Hash) ? spec.dup : {}
3854
+ pr[:full_calc_on_load] = full_calc_on_load unless full_calc_on_load.nil?
3855
+ pr.merge!(opts) unless opts.empty?
3856
+ @current_sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
3857
+ @current_sheet_calc_pr = pr
3858
+ end
3859
+
3860
+ # Sets worksheet calculation properties (<sheetCalcPr>) for the current sheet.
3861
+ #
3862
+ # @param spec [Hash, nil] Calculation properties hash.
3863
+ # @return [Hash, nil]
3864
+ # @api public
3865
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
3866
+ def sheet_calc_properties=(spec)
3867
+ sheet if @current_sheet.nil?
3868
+ if spec.nil?
3869
+ @current_sheet_properties.delete(:full_calc_on_load)
3870
+ @current_sheet_calc_pr = nil
3871
+ else
3872
+ pr = spec.is_a?(Hash) ? spec.dup : {}
3873
+ @current_sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
3874
+ @current_sheet_calc_pr = pr
3875
+ end
3876
+ spec
3877
+ end
3878
+
3879
+ # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
3880
+ #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
3881
+ def sheet_calc_pr(spec = OMITTED, full_calc_on_load: nil, **opts)
3882
+ warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
3883
+ sheet_calc_properties(spec, full_calc_on_load: full_calc_on_load, **opts)
3884
+ end
3885
+
3886
+ # @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
3887
+ #: (?Hash[Symbol, untyped]? spec, ?full_calc_on_load: bool?, **untyped opts) -> (Elements::SheetCalcProperties | Hash[Symbol, untyped] | nil)
3888
+ def calc_pr(spec = OMITTED, full_calc_on_load: nil, **opts)
3889
+ warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
3890
+ sheet_calc_properties(spec, full_calc_on_load: full_calc_on_load, **opts)
3891
+ end
3892
+
3893
+ # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
3894
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
3895
+ def sheet_calc_pr=(spec)
3896
+ warn "[DEPRECATION] #sheet_calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
3897
+ self.sheet_calc_properties = spec
3898
+ end
3899
+
3900
+ # @deprecated Use {#sheet_calc_properties=} instead. Will be removed in 0.2.0.
3901
+ #: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
3902
+ def calc_pr=(spec)
3903
+ warn "[DEPRECATION] #calc_pr= is deprecated; use #sheet_calc_properties= instead.", uplevel: 1
3904
+ self.sheet_calc_properties = spec
3905
+ end
3906
+
1657
3907
  # --- Workbook-Level Methods ---
1658
3908
 
1659
3909
  # Adds a defined name.
1660
3910
  #
1661
3911
  # @param name [String] The defined name.
1662
- # @param value [String] The formula or value expression.
1663
- # @param sheet [String, nil] Local sheet name.
3912
+ # @param value [Object, nil] The formula or value expression.
3913
+ # @param sheet [String, nil] Reference sheet name.
3914
+ # @param scope [String, Symbol, nil] Local scope sheet name or :workbook.
1664
3915
  # @param hidden [Boolean] Whether the defined name is hidden.
3916
+ # @param column [Integer, String, nil] Deprecated alias for columns.
3917
+ # @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
3918
+ # @param col [Integer, String, nil] Deprecated alias for column.
3919
+ # @param row [Integer, Range, nil] Deprecated alias for rows.
3920
+ # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
3921
+ # @param range [String, nil] Cell range reference.
3922
+ # @param ref_sheet [String, nil] Deprecated alias for sheet.
3923
+ # @param local [Boolean] Deprecated alias for scope.
1665
3924
  # @return [void]
1666
3925
  # @api public
1667
- #: (String name, String value, ?sheet: String?, ?hidden: bool) -> void
1668
- def defined_name(name, value, sheet: nil, hidden: false)
1669
- entry = { name: name, value: value, hidden: hidden }
1670
- if sheet
3926
+ #: (String name, ?untyped value, ?sheet: String?, ?scope: (String | Symbol)?, ?hidden: bool, ?column: untyped, ?columns: untyped, ?col: untyped, ?row: untyped, ?rows: untyped, ?range: untyped, ?ref_sheet: String?, ?local: bool) -> void
3927
+ def defined_name(name, value = nil, sheet: nil, scope: nil, hidden: false, column: nil, columns: nil, col: nil, row: nil, rows: nil, range: nil, ref_sheet: nil, local: false)
3928
+ warn "[DEPRECATION] `col:` is deprecated; use `column:` (or `columns:`) instead.", uplevel: 1 if col
3929
+ warn "[DEPRECATION] `ref_sheet:` is deprecated; use `sheet:` for reference sheet and `scope:` for scope instead.", uplevel: 1 if ref_sheet
3930
+ warn "[DEPRECATION] `local:` is deprecated; use `scope:` instead.", uplevel: 1 if local
3931
+ warn "[Xlsxrb DEPRECATION] defined_name keyword column: is deprecated; use columns: instead.", uplevel: 1 unless column.nil?
3932
+ warn "[Xlsxrb DEPRECATION] defined_name keyword row: is deprecated; use rows: instead.", uplevel: 1 unless row.nil?
3933
+ target_ref_sheet = ref_sheet || sheet
3934
+ c_arg = column || columns || col
3935
+ r_arg = row || rows
3936
+ normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: target_ref_sheet, col: c_arg, rows: r_arg, range: range)
3937
+ entry = { name: name, value: normalized_val, hidden: hidden }
3938
+ local_sheet = if scope
3939
+ scope == :workbook ? nil : scope.to_s
3940
+ elsif sheet || local || ref_sheet
3941
+ sheet
3942
+ end
3943
+ if local_sheet
1671
3944
  # local_sheet_id will be resolved at close time
1672
- entry[:local_sheet_name] = sheet
3945
+ entry[:local_sheet_name] = local_sheet
1673
3946
  end
1674
3947
  @defined_names << entry
1675
3948
  end
1676
3949
 
1677
- # Sets the print area for the current or named sheet.
3950
+ # Returns workbook-level defined names.
1678
3951
  #
1679
- # @param range [String] Cell range (e.g. "A1:G50").
3952
+ # @return [Array<Elements::DefinedName>]
3953
+ # @api public
3954
+ #: () -> Array[Elements::DefinedName]
3955
+ def defined_names
3956
+ @defined_names.map { |dn| dn.is_a?(Elements::DefinedName) ? dn : Elements::DefinedName.new(**dn) }
3957
+ end
3958
+
3959
+ # Sets or gets the print area for the current or named sheet.
3960
+ #
3961
+ # @param range [String, Object, nil] Cell range (e.g. "A1:G50").
1680
3962
  # @param sheet [String, nil] Target sheet name.
1681
- # @return [void]
3963
+ # @return [String, nil, void]
1682
3964
  # @api public
1683
- #: (String range, ?sheet: String?) -> void
1684
- def print_area(range, sheet: nil)
1685
- # simplecov:disable
1686
- # Edge case / untested delegation block
3965
+ #: (?untyped range, ?sheet: String?) -> (String | nil | void)
3966
+ def print_area(range = OMITTED, sheet: nil)
3967
+ return @current_print_area if range.equal?(OMITTED)
3968
+
3969
+ @current_print_area = range
1687
3970
  sheet_name = sheet || @current_sheet || "Sheet1"
1688
- value = "'#{sheet_name}'!#{absolute_range(range)}"
1689
3971
  @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Area" && dn[:local_sheet_name] == sheet_name }
1690
- defined_name("_xlnm.Print_Area", value, sheet: sheet_name)
1691
- # simplecov:enable
3972
+ if range
3973
+ value = "'#{sheet_name}'!#{absolute_range(range)}"
3974
+ defined_name("_xlnm.Print_Area", value, sheet: sheet_name, scope: sheet_name)
3975
+ end
3976
+ nil
3977
+ end
3978
+
3979
+ # Sets the print area for the current worksheet.
3980
+ #
3981
+ # @param range [String, nil] Cell range (e.g. "A1:G50").
3982
+ # @return [String, nil]
3983
+ # @api public
3984
+ #: (String? range) -> String?
3985
+ def print_area=(range)
3986
+ print_area(range)
3987
+ range
1692
3988
  end
1693
3989
 
1694
- # Sets print titles for the current or named sheet.
3990
+ # Sets or gets print titles for the current or named sheet.
1695
3991
  #
1696
- # @param rows [String, nil] Repeating row range (e.g. "1:2").
1697
- # @param cols [String, nil] Repeating column range (e.g. "A:B").
3992
+ # @param rows [String, Integer, Range, Object, nil] Repeating row range (e.g. "1:2" or 0-based 0..1).
3993
+ # @param columns [String, Integer, Symbol, Range, Object, nil] Repeating column range (e.g. "A:B" or 0..1).
3994
+ # @param cols [String, Integer, Symbol, Range, Object, nil] Deprecated alias for columns.
1698
3995
  # @param sheet [String, nil] Target sheet name.
1699
- # @return [void]
3996
+ # @return [Elements::PrintTitles, nil, void]
1700
3997
  # @api public
1701
- #: (?rows: String?, ?cols: String?, ?sheet: String?) -> void
1702
- def print_titles(rows: nil, cols: nil, sheet: nil)
3998
+ #: (?rows: untyped, ?columns: untyped, ?cols: untyped, ?sheet: String?) -> (Elements::PrintTitles | nil | void)
3999
+ def print_titles(rows: OMITTED, columns: OMITTED, cols: OMITTED, sheet: nil)
4000
+ if rows.equal?(OMITTED) && columns.equal?(OMITTED) && cols.equal?(OMITTED)
4001
+ return nil unless @current_print_titles
4002
+
4003
+ return Elements::PrintTitles.new(rows: @current_print_titles[:rows], columns: @current_print_titles[:columns] || @current_print_titles[:cols])
4004
+ end
4005
+
4006
+ warn "[DEPRECATION] `cols:` is deprecated; use `columns:` instead.", uplevel: 1 if cols && !cols.equal?(OMITTED) && columns.equal?(OMITTED)
4007
+ r_val = rows.equal?(OMITTED) ? nil : rows
4008
+ c_val = if !columns.equal?(OMITTED)
4009
+ columns
4010
+ elsif !cols.equal?(OMITTED)
4011
+ cols
4012
+ end
4013
+ @current_print_titles = { rows: r_val, columns: c_val }.compact
4014
+
4015
+ c = DslHelpers.normalize_print_titles_columns(c_val)
4016
+ r = DslHelpers.normalize_print_titles_rows(r_val)
1703
4017
  sheet_name = sheet || @current_sheet || "Sheet1"
1704
4018
  existing = @defined_names.find { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
1705
- if existing && (rows.nil? || cols.nil?)
1706
- cols = Regexp.last_match(1).delete("$") if cols.nil? && existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
1707
- rows = Regexp.last_match(1).delete("$") if rows.nil? && existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
4019
+ if existing && (r.nil? || c.nil?)
4020
+ c = Regexp.last_match(1).delete("$") if c.nil? && existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
4021
+ r = Regexp.last_match(1).delete("$") if r.nil? && existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
1708
4022
  end
1709
4023
  parts = []
1710
- parts << "'#{sheet_name}'!$#{cols.sub(":", ":$")}" if cols
1711
- parts << "'#{sheet_name}'!$#{rows.sub(":", ":$")}" if rows
4024
+ parts << "'#{sheet_name}'!$#{c.sub(":", ":$")}" if c
4025
+ parts << "'#{sheet_name}'!$#{r.sub(":", ":$")}" if r
1712
4026
  value = parts.join(",")
1713
4027
  @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
1714
- defined_name("_xlnm.Print_Titles", value, sheet: sheet_name)
4028
+ defined_name("_xlnm.Print_Titles", value, sheet: sheet_name, scope: sheet_name) unless value.empty?
4029
+ nil
4030
+ end
4031
+
4032
+ # Sets repeating print titles for the current worksheet.
4033
+ #
4034
+ # @param opts [Elements::PrintTitles, Hash, nil] Options with :rows and/or :columns.
4035
+ # @return [Elements::PrintTitles, Hash, nil]
4036
+ # @api public
4037
+ #: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
4038
+ def print_titles=(opts)
4039
+ if opts.nil?
4040
+ @current_print_titles = nil
4041
+ sheet_name = @current_sheet || "Sheet1"
4042
+ @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
4043
+ else
4044
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
4045
+ print_titles(**h)
4046
+ end
4047
+ opts
1715
4048
  end
1716
4049
 
1717
4050
  # Sets repeating title rows for pagination on the current or named sheet.
@@ -1750,9 +4083,9 @@ module Xlsxrb
1750
4083
  cols_str = if first.is_a?(String)
1751
4084
  first.include?(":") ? first : "#{first}:#{last || first}"
1752
4085
  else
1753
- first_name = Utils.col_index_to_name(first)
4086
+ first_name = Elements::Cell._column_letter(first)
1754
4087
  last_name = if last.is_a?(Integer)
1755
- Utils.col_index_to_name(last)
4088
+ Elements::Cell._column_letter(last)
1756
4089
  elsif last
1757
4090
  last.to_s
1758
4091
  else
@@ -1760,17 +4093,39 @@ module Xlsxrb
1760
4093
  end
1761
4094
  "#{first_name}:#{last_name}"
1762
4095
  end
1763
- print_titles(cols: cols_str, sheet: sheet)
4096
+ print_titles(columns: cols_str, sheet: sheet)
1764
4097
  end
1765
4098
 
1766
- # Sets workbook protection.
4099
+ # Sets or returns workbook protection settings.
1767
4100
  #
1768
4101
  # @param opts [Hash] Protection options.
4102
+ # @return [Elements::WorkbookProtection, nil, void]
4103
+ # @api public
4104
+ #: (**String | Integer | bool | nil opts) -> (Elements::WorkbookProtection | nil)
4105
+ def workbook_protection(**opts)
4106
+ if opts.empty?
4107
+ @workbook_protection ? Elements::WorkbookProtection.new(**@workbook_protection) : nil
4108
+ else
4109
+ @workbook_protection = opts
4110
+ nil
4111
+ end
4112
+ end
4113
+
4114
+ # Sets workbook protection settings.
4115
+ #
4116
+ # @param opts [Hash, Elements::MetadataRecord, nil]
1769
4117
  # @return [void]
1770
4118
  # @api public
4119
+ #: (untyped opts) -> void
4120
+ def workbook_protection=(opts)
4121
+ @workbook_protection = opts.is_a?(Elements::MetadataRecord) ? opts.to_h : opts
4122
+ end
4123
+
4124
+ # @deprecated Use {#workbook_protection} instead.
1771
4125
  #: (**String | Integer | bool | nil opts) -> void
1772
- def protect_workbook(**opts)
1773
- @workbook_protection = opts
4126
+ def protect_workbook(...)
4127
+ warn "[DEPRECATION] `protect_workbook` is deprecated; use `workbook_protection` instead.", uplevel: 1
4128
+ workbook_protection(...)
1774
4129
  end
1775
4130
 
1776
4131
  # Sets a core document metadata property.
@@ -1784,6 +4139,15 @@ module Xlsxrb
1784
4139
  @core_properties[name] = value
1785
4140
  end
1786
4141
 
4142
+ # Returns core document properties.
4143
+ #
4144
+ # @return [Elements::CoreProperties]
4145
+ # @api public
4146
+ #: () -> Elements::CoreProperties
4147
+ def core_properties
4148
+ Elements::CoreProperties.new(**@core_properties)
4149
+ end
4150
+
1787
4151
  # Sets an app document property.
1788
4152
  #
1789
4153
  # @param name [Symbol] Property name.
@@ -1794,10 +4158,20 @@ module Xlsxrb
1794
4158
  def app_property(name, value)
1795
4159
  # simplecov:disable
1796
4160
  # Edge case / untested delegation block
1797
- @app_properties[name] = value
4161
+ norm_name = name.to_sym == :application ? :app_name : name.to_sym
4162
+ @app_properties[norm_name] = value
1798
4163
  # simplecov:enable
1799
4164
  end
1800
4165
 
4166
+ # Returns application document properties.
4167
+ #
4168
+ # @return [Elements::AppProperties]
4169
+ # @api public
4170
+ #: () -> Elements::AppProperties
4171
+ def app_properties
4172
+ Elements::AppProperties.new(**@app_properties)
4173
+ end
4174
+
1801
4175
  # Sets multiple core and/or app properties.
1802
4176
  #
1803
4177
  # @param core [Hash, nil] Core properties.
@@ -1830,6 +4204,18 @@ module Xlsxrb
1830
4204
  # simplecov:enable
1831
4205
  end
1832
4206
 
4207
+ # Returns custom document properties.
4208
+ #
4209
+ # @return [Hash<String, Elements::CustomProperty>]
4210
+ # @api public
4211
+ #: () -> Hash[String, Elements::CustomProperty]
4212
+ def custom_properties
4213
+ @custom_properties.to_h do |cp|
4214
+ prop = cp.is_a?(Elements::CustomProperty) ? cp : Elements::CustomProperty.new(name: (cp[:name] || cp["name"]).to_s, value: cp[:value] || cp["value"], type: cp[:type] || cp["type"] || :string)
4215
+ [prop.name.to_s, prop]
4216
+ end.freeze
4217
+ end
4218
+
1833
4219
  # Finalizes and writes all streaming sheet contents to the destination target.
1834
4220
  #
1835
4221
  # @return [void]
@@ -1840,6 +4226,8 @@ module Xlsxrb
1840
4226
 
1841
4227
  flush_current_sheet
1842
4228
 
4229
+ raise ArgumentError, "Workbook must contain at least one visible sheet (Excel limitation)" if @strict_excel_mode && @sheets.none? { |s| (s.is_a?(Hash) ? s[:state] : s.state) == :visible }
4230
+
1843
4231
  styles_definition = {
1844
4232
  fonts: @style_writer.fonts.dup,
1845
4233
  fills: @style_writer.fills.dup,
@@ -1851,6 +4239,12 @@ module Xlsxrb
1851
4239
 
1852
4240
  resolved_names = resolve_defined_names(@defined_names, @sheets)
1853
4241
 
4242
+ @workbook_properties[:active_sheet] = @active_sheet unless @active_sheet.nil?
4243
+ @workbook_properties[:active_tab] = @active_sheet unless @active_sheet.nil?
4244
+ @workbook_properties[:first_sheet] = @first_sheet unless @first_sheet.nil?
4245
+ @workbook_properties[:show_sheet_tabs] = @show_sheet_tabs unless @show_sheet_tabs.nil?
4246
+ @workbook_properties[:tab_ratio] = @tab_ratio unless @tab_ratio.nil?
4247
+
1854
4248
  wb_writer = Ooxml::WorkbookWriter.new(
1855
4249
  sheets: @sheets,
1856
4250
  shared_strings: @sst,
@@ -1874,7 +4268,7 @@ module Xlsxrb
1874
4268
  # Explicitly cleans up any resources if not already closed.
1875
4269
  #
1876
4270
  # @return [void]
1877
- # @api public
4271
+ # @api private
1878
4272
  #: () -> void
1879
4273
  def cleanup!
1880
4274
  if @zip && !@zip.instance_variable_get(:@closed)
@@ -1922,31 +4316,18 @@ module Xlsxrb
1922
4316
  unless @current_conditional_formats.empty?
1923
4317
  @dxfs ||= []
1924
4318
  @current_conditional_formats = @current_conditional_formats.map do |rule|
1925
- next rule if rule[:format_id]
4319
+ next rule if rule.respond_to?(:dxf_id) ? rule.dxf_id : (rule.is_a?(Hash) && (rule[:dxf_id] || rule[:format_id]))
1926
4320
 
1927
4321
  normalized = rule.dup
1928
- font = {}
1929
- font[:color] = normalized.delete(:font_color) if normalized.key?(:font_color)
1930
- font[:bold] = normalized.delete(:bold) if normalized.key?(:bold)
1931
- font[:italic] = normalized.delete(:italic) if normalized.key?(:italic)
1932
- font[:underline] = normalized.delete(:underline) if normalized.key?(:underline)
1933
-
1934
- fill = {}
1935
- if normalized.key?(:fill_color)
1936
- fill[:pattern] = "solid"
1937
- fill[:fg_color] = normalized.delete(:fill_color)
1938
- end
1939
-
1940
- dxf = {}
1941
- dxf[:font] = font unless font.empty?
1942
- dxf[:fill] = fill unless fill.empty?
1943
- next normalized if dxf.empty?
4322
+ dxf = normalized.delete(:dxf) || DslHelpers.extract_dxf_from_rule!(normalized)
4323
+ next normalized if dxf.nil? || dxf.empty?
1944
4324
 
1945
4325
  dxf_id = @dxfs.index(dxf)
1946
4326
  unless dxf_id
1947
4327
  @dxfs << dxf
1948
4328
  dxf_id = @dxfs.size - 1
1949
4329
  end
4330
+ normalized[:dxf_id] = dxf_id
1950
4331
  normalized[:format_id] = dxf_id
1951
4332
  normalized
1952
4333
  end
@@ -1956,6 +4337,7 @@ module Xlsxrb
1956
4337
 
1957
4338
  sheet_data = {
1958
4339
  name: @current_sheet,
4340
+ state: @current_sheet_state || :visible,
1959
4341
  columns: @current_columns,
1960
4342
  charts: @current_charts,
1961
4343
  hyperlinks: @current_hyperlinks,
@@ -1968,6 +4350,7 @@ module Xlsxrb
1968
4350
  pivot_tables: @current_pivot_tables,
1969
4351
  sparkline_groups: @current_sparkline_groups,
1970
4352
  comments: @current_comments,
4353
+ threaded_comments: @current_threaded_comments,
1971
4354
  merge_cells: @current_merge_cells,
1972
4355
  freeze_pane: @current_freeze_pane,
1973
4356
  split_pane: @current_split_pane,
@@ -1985,7 +4368,11 @@ module Xlsxrb
1985
4368
  row_breaks: @current_row_breaks,
1986
4369
  col_breaks: @current_col_breaks,
1987
4370
  protected_ranges: @current_protected_ranges,
1988
- cell_watches: @current_cell_watches
4371
+ cell_watches: @current_cell_watches,
4372
+ ignored_errors: @current_ignored_errors,
4373
+ phonetic_properties: @current_phonetic_properties,
4374
+ sheet_calc_pr: @current_sheet_calc_pr,
4375
+ background_image: @current_background_image
1989
4376
  }
1990
4377
  sheet_data[:cells] = @current_cells if @current_cells && !@current_cells.empty?
1991
4378
  @current_cells = nil
@@ -1995,6 +4382,7 @@ module Xlsxrb
1995
4382
 
1996
4383
  @current_row_writer.finish(
1997
4384
  drawing_rid: info[:drawing_rid],
4385
+ picture_rid: info[:picture_rid],
1998
4386
  sheet_protection: @current_sheet_protection,
1999
4387
  protected_ranges: @current_protected_ranges.empty? ? nil : @current_protected_ranges,
2000
4388
  auto_filter: @current_auto_filter,
@@ -2011,6 +4399,9 @@ module Xlsxrb
2011
4399
  row_breaks: @current_row_breaks.empty? ? nil : @current_row_breaks,
2012
4400
  col_breaks: @current_col_breaks.empty? ? nil : @current_col_breaks,
2013
4401
  cell_watches: @current_cell_watches.empty? ? nil : @current_cell_watches,
4402
+ ignored_errors: @current_ignored_errors.empty? ? nil : @current_ignored_errors,
4403
+ phonetic_pr: @current_phonetic_properties,
4404
+ sheet_calc_pr: @current_sheet_calc_pr,
2014
4405
  tables: @current_tables.empty? ? nil : @current_tables,
2015
4406
  table_start_rid: info[:table_start_rid],
2016
4407
  legacy_drawing_rid: info[:vml_rid],