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
@@ -19,17 +19,263 @@ module Xlsxrb
19
19
  # @api public
20
20
  class WorkbookBuilder
21
21
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specifications.
22
- #: (?strict_excel_mode: bool) -> void
23
- def initialize(strict_excel_mode: true)
22
+ # @param escape_formulas [Boolean] Whether to treat strings starting with formula prefixes as plain text.
23
+ # @param default_font [Hash, nil] Optional default font options (e.g. `{ name: "Arial", size: 12 }`).
24
+ #: (?strict_excel_mode: bool, ?escape_formulas: bool, ?default_font: untyped?) -> void
25
+ def initialize(strict_excel_mode: true, escape_formulas: false, default_font: nil)
24
26
  @strict_excel_mode = strict_excel_mode
27
+ @escape_formulas = escape_formulas ? true : false
28
+ @default_font = default_font
25
29
  @sheets = []
26
30
  @sheet_builders = [] # Keep track of sheet builders for style processing
27
31
  @defined_names = []
32
+ @styles = {}
28
33
  @core_properties = {}
29
34
  @app_properties = {}
30
35
  @custom_properties = []
31
36
  @workbook_protection = nil
32
37
  @workbook_properties = { update_links: "never" }
38
+ @active_sheet = nil
39
+ @first_sheet = nil
40
+ @show_sheet_tabs = nil
41
+ @tab_ratio = nil
42
+ end
43
+
44
+ # @return [Boolean] Whether to treat strings starting with formula prefixes as plain text.
45
+ #: bool
46
+ attr_accessor :escape_formulas
47
+
48
+ # Returns whether formula escaping is enabled.
49
+ #
50
+ # @return [Boolean]
51
+ # @api public
52
+ #: () -> bool
53
+ def escape_formulas?
54
+ @escape_formulas ? true : false
55
+ end
56
+
57
+ # Sets or configures the workbook-wide default font.
58
+ #
59
+ # @param name [String, Hash, nil] Font name or font options Hash.
60
+ # @param size [Float, Integer, nil] Font size in points.
61
+ # @param opts [Hash] Additional font options (e.g. `bold:`, `italic:`, `family:`, `charset:`, `color:`).
62
+ # @return [void]
63
+ # @api public
64
+ #: (?String | Hash[Symbol, untyped]? name, ?Float | Integer | nil size, **untyped opts) -> void
65
+ def default_font(name = nil, size = nil, **opts)
66
+ existing = @default_font.is_a?(Hash) ? @default_font.dup : {}
67
+ if name.is_a?(Hash)
68
+ opts = name.merge(opts)
69
+ name = opts[:name]
70
+ end
71
+ existing[:name] = name if name
72
+ existing[:size] = size if size
73
+ @default_font = existing.merge(opts)
74
+ end
75
+ # @deprecated Use {#default_font} instead. Will be removed in 0.2.0.
76
+ alias set_default_font default_font
77
+
78
+ # @return [Hash{String => StyleBuilder}]
79
+ #: Hash[String, StyleBuilder]
80
+ attr_reader :styles
81
+
82
+ # Defines or configures a named cell style at the workbook level.
83
+ #
84
+ # @example
85
+ # workbook.style(:header, bold: true, fill_color: "4F81BD", font_color: "FFFFFF")
86
+ #
87
+ # @param name [String, Symbol] The name of the style.
88
+ # @param opts [Hash] Style options (e.g. bold: true, fill_color: "FF0000").
89
+ # @yield [style_builder]
90
+ # @yieldparam style_builder [Xlsxrb::StyleBuilder]
91
+ # @return [StyleBuilder]
92
+ # @api public
93
+ #: (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
94
+ def style(name, **opts)
95
+ style_name = name.to_s
96
+ style_builder = StyleBuilder.new(style_name)
97
+ style_builder.apply_options!(**opts) unless opts.empty?
98
+ yield style_builder if block_given?
99
+ @styles[style_name] = style_builder
100
+ end
101
+
102
+ # Creates an {Elements::Formula} object.
103
+ #
104
+ # @param expression [String] The formula expression without leading '='.
105
+ # @param cached_value [Object, nil] Optional precomputed value.
106
+ # @param type [Symbol, String, nil] Formula type (:shared, :array, etc.).
107
+ # @param ref [String, nil] Target cell or range reference.
108
+ # @param shared_index [Integer, nil] Shared formula group index (0-based).
109
+ # @return [Elements::Formula]
110
+ # @api public
111
+ #: (String expression, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), ?type: (Symbol | String)?, ?ref: String?, ?shared_index: Integer?) -> Elements::Formula
112
+ def formula(...)
113
+ Xlsxrb.formula(...)
114
+ end
115
+
116
+ # Creates an array or dynamic array {Elements::Formula} object.
117
+ #
118
+ # @param expression [String] The formula expression without leading '='.
119
+ # @param ref [String, nil] Target cell or range reference (keyword).
120
+ # @param cached_value [Object, nil] Optional precomputed value.
121
+ # @return [Elements::Formula]
122
+ # @api public
123
+ #: (String expression, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), **untyped attrs) -> Elements::Formula
124
+ def array_formula(...)
125
+ Xlsxrb.array_formula(...)
126
+ end
127
+
128
+ # Creates a shared formula {Elements::Formula} object.
129
+ #
130
+ # @param expression [String, nil] The formula expression.
131
+ # @param shared_index [Integer, nil] Shared formula group index (0-based).
132
+ # @param ref [String, nil] Target range for master cell.
133
+ # @param cached_value [Object, nil] Optional precomputed value.
134
+ # @return [Elements::Formula]
135
+ # @api public
136
+ #: (?String? expression, ?shared_index: Integer?, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil)) -> Elements::Formula
137
+ def shared_formula(...)
138
+ Xlsxrb.shared_formula(...)
139
+ end
140
+
141
+ # Creates an {Elements::RichText} object.
142
+ #
143
+ # @param runs [Array] Text runs or styling options.
144
+ # @return [Elements::RichText]
145
+ # @api public
146
+ #: (*(Hash[Symbol, untyped] | Elements::RichTextRun | String | Array[untyped] | untyped) runs, ?text: String?, ?base_font: untyped, **untyped font_props) -> Elements::RichText
147
+ def rich_text(...)
148
+ Xlsxrb.rich_text(...)
149
+ end
150
+
151
+ # Creates or returns an {Elements::CellError} object.
152
+ #
153
+ # @param code [String, Symbol, Elements::CellError] Error code or symbol.
154
+ # @return [Elements::CellError]
155
+ # @api public
156
+ #: (String | Symbol | Elements::CellError code) -> Elements::CellError
157
+ def cell_error(...)
158
+ Xlsxrb.cell_error(...)
159
+ end
160
+
161
+ OMITTED = Object.new.freeze
162
+ private_constant :OMITTED
163
+
164
+ # Gets or sets the active worksheet tab in the workbook window.
165
+ #
166
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#active_sheet=} instead.
167
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
168
+ # @return [String, Symbol, Integer, nil]
169
+ # @api public
170
+ #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
171
+ def active_sheet(name_or_index = OMITTED)
172
+ if name_or_index.equal?(OMITTED)
173
+ @active_sheet
174
+ else
175
+ @active_sheet = name_or_index
176
+ end
177
+ end
178
+ # @deprecated Use {#active_sheet} instead. Will be removed in 0.2.0.
179
+ alias active_tab active_sheet
180
+
181
+ # Sets the active worksheet tab in the workbook window.
182
+ #
183
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
184
+ # @return [String, Symbol, Integer, nil]
185
+ # @api public
186
+ attr_writer :active_sheet #: (String | Symbol | Integer | nil)
187
+ # @deprecated Use {#active_sheet=} instead. Will be removed in 0.2.0.
188
+ alias active_tab= active_sheet=
189
+
190
+ # Gets or sets the first sheet tab visible in the sheet tab scroll area.
191
+ #
192
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#first_sheet=} instead.
193
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
194
+ # @return [String, Symbol, Integer, nil]
195
+ # @api public
196
+ #: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
197
+ def first_sheet(name_or_index = OMITTED)
198
+ if name_or_index.equal?(OMITTED)
199
+ @first_sheet
200
+ else
201
+ @first_sheet = name_or_index
202
+ end
203
+ end
204
+
205
+ # Sets the first sheet tab visible in the sheet tab scroll area.
206
+ #
207
+ # @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
208
+ # @return [String, Symbol, Integer, nil]
209
+ # @api public
210
+ attr_writer :first_sheet #: (String | Symbol | Integer | nil)
211
+
212
+ # Gets or sets whether sheet tabs are visible in the workbook window.
213
+ #
214
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#show_sheet_tabs=} instead.
215
+ # @param visible [Boolean, nil]
216
+ # @return [Boolean, nil]
217
+ # @api public
218
+ #: (?bool? visible) -> bool?
219
+ def show_sheet_tabs(visible = OMITTED)
220
+ if visible.equal?(OMITTED)
221
+ @show_sheet_tabs
222
+ else
223
+ @show_sheet_tabs = visible
224
+ end
225
+ end
226
+
227
+ # Sets whether sheet tabs are visible in the workbook window.
228
+ #
229
+ # @param visible [Boolean, nil]
230
+ # @return [Boolean, nil]
231
+ # @api public
232
+ attr_writer :show_sheet_tabs #: bool?
233
+
234
+ # Gets or sets the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
235
+ #
236
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#tab_ratio=} instead.
237
+ # @param ratio [Integer, nil]
238
+ # @return [Integer, nil]
239
+ # @api public
240
+ #: (?Integer? ratio) -> Integer?
241
+ def tab_ratio(ratio = OMITTED)
242
+ if ratio.equal?(OMITTED)
243
+ @tab_ratio
244
+ else
245
+ @tab_ratio = ratio
246
+ end
247
+ end
248
+
249
+ # Sets the ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
250
+ #
251
+ # @param ratio [Integer, nil]
252
+ # @return [Integer, nil]
253
+ # @api public
254
+ attr_writer :tab_ratio #: Integer?
255
+
256
+ # Gets or sets the internal code name of the workbook.
257
+ #
258
+ # @deprecated Calling with arguments is deprecated and will be removed in 0.2.0. Use {#code_name=} instead.
259
+ # @param name [String, Symbol, nil] The code name.
260
+ # @return [String, nil]
261
+ # @api public
262
+ #: (?String | Symbol | nil name) -> String?
263
+ def code_name(name = OMITTED)
264
+ if name.equal?(OMITTED)
265
+ @workbook_properties[:code_name]
266
+ else
267
+ @workbook_properties[:code_name] = name&.to_s
268
+ end
269
+ end
270
+
271
+ # Sets the internal code name of the workbook.
272
+ #
273
+ # @param name [String, Symbol, nil] The code name.
274
+ # @return [String, nil]
275
+ # @api public
276
+ #: (String | Symbol | nil name) -> String?
277
+ def code_name=(name)
278
+ @workbook_properties[:code_name] = name&.to_s
33
279
  end
34
280
 
35
281
  # Sets a workbook-level property.
@@ -42,92 +288,224 @@ module Xlsxrb
42
288
  # @param value [String, Integer, Boolean] Property value.
43
289
  # @return [void]
44
290
  # @api public
45
- #: (Symbol name, String | Integer | bool value) -> (String | Integer | bool)
291
+ #: (Symbol name, String | Integer | bool value) -> void
46
292
  def workbook_property(name, value)
47
293
  @workbook_properties[name] = value
294
+ nil
295
+ end
296
+
297
+ # Returns workbook-level properties.
298
+ #
299
+ # @return [Elements::WorkbookProperties]
300
+ # @api public
301
+ #: () -> Elements::WorkbookProperties
302
+ def workbook_properties
303
+ Elements::WorkbookProperties.new(**@workbook_properties)
304
+ end
305
+
306
+ # Sets workbook-level properties.
307
+ #
308
+ # @param props [Hash, Elements::MetadataRecord]
309
+ # @return [void]
310
+ # @api public
311
+ #: (untyped props) -> void
312
+ def workbook_properties=(props)
313
+ @workbook_properties = props.is_a?(Elements::MetadataRecord) ? props.to_h : props
314
+ end
315
+
316
+ # Returns the list of worksheet names added to this workbook so far.
317
+ #
318
+ # @return [Array<String>] Worksheet names.
319
+ # @api public
320
+ #: () -> Array[String]
321
+ def sheet_names
322
+ (@sheets.map { |s| s.respond_to?(:name) ? s.name : s.to_s } + @sheet_builders.map(&:name)).uniq
48
323
  end
49
324
 
50
325
  # Adds a new worksheet to the workbook.
51
326
  #
52
- # @param name [String, nil] Sheet name (max 31 chars, no forbidden chars `[ ] * ? / \`).
53
- # @param opts [Hash] Sheet properties.
327
+ # @param name [String, nil] Sheet name (max 31 chars, no forbidden chars `[ ] * ? / \ :`).
328
+ # @param state [Symbol, String, nil] Sheet visibility state (:visible, :hidden, :very_hidden).
329
+ # @param tab_color [String, Hash, nil] Tab color hex string or color hash.
330
+ # @param code_name [String, nil] VBA code name.
331
+ # @param hidden [Boolean, nil] Deprecated alias for state: :hidden.
332
+ # @param opts [Hash] Additional sheet properties.
54
333
  # @yield [sheet_builder]
55
334
  # @yieldparam sheet_builder [Xlsxrb::WorksheetBuilder]
56
335
  # @return [Elements::Worksheet]
57
336
  # @raise [ArgumentError] If sheet name violates Excel limits in strict mode.
58
337
  # @api public
59
- #: (?String? name, **untyped opts) ?{ (WorksheetBuilder) -> void } -> untyped
60
- def sheet(name = nil, **opts)
61
- name ||= "Sheet#{@sheets.size + 1}"
338
+ #: (?String? name, ?state: (Symbol | String)?, ?tab_color: untyped, ?code_name: String?, ?hidden: bool?, **untyped opts) ?{ (WorksheetBuilder) -> void } -> Elements::Worksheet
339
+ def sheet(name = nil, state: nil, tab_color: nil, code_name: nil, hidden: nil, **opts)
340
+ sheet_count = [@sheets.size, @sheet_builders.size].max
341
+ name ||= "Sheet#{sheet_count + 1}"
62
342
  raise ArgumentError, "Sheet name '#{name}' must be <= 31 characters (Excel limitation)" if @strict_excel_mode && name.length > 31
63
- raise ArgumentError, "Sheet name '#{name}' contains invalid characters (ECMA-376 OOXML specification)" if name.match?(%r{[\[\]*?/\\]})
64
- 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)
343
+ raise ArgumentError, "Sheet name '#{name}' contains invalid characters (Excel limitation)" if name.match?(Elements::Worksheet.forbidden_name_chars)
344
+ raise ArgumentError, "Sheet name '#{name}' cannot start or end with an apostrophe (Excel limitation)" if @strict_excel_mode && (name.start_with?("'") || name.end_with?("'"))
345
+ raise ArgumentError, "Sheet name '#{name}' is reserved by Excel (Excel limitation)" if @strict_excel_mode && name.casecmp?("History")
346
+
347
+ existing_names = @sheets.map { |s| s.respond_to?(:name) ? s.name.downcase : s.to_s.downcase } + @sheet_builders.map { |sb| sb.name.downcase }
348
+ raise ArgumentError, "Sheet name '#{name}' is already used. Excel requires unique sheet names." if @strict_excel_mode && existing_names.include?(name.downcase)
65
349
 
66
- state = opts.delete(:state)
67
- hidden = opts.delete(:hidden)
350
+ active = opts.delete(:active)
351
+ state = opts.delete(:state) if opts.key?(:state)
352
+ hidden = opts.delete(:hidden) if opts.key?(:hidden)
353
+ code_name = opts.delete(:code_name) if opts.key?(:code_name)
354
+ tab_color = opts.delete(:tab_color) if opts.key?(:tab_color)
355
+
356
+ warn "[Xlsxrb DEPRECATION] sheet keyword hidden: is deprecated; use state: :hidden instead.", uplevel: 1 unless hidden.nil?
68
357
  state ||= :hidden if hidden
69
358
  state ||= :visible
359
+ state = state.to_sym
360
+ raise ArgumentError, "Invalid sheet state ':#{state}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(state)
361
+
362
+ @active_sheet = name if active
70
363
 
71
- sheet_builder = WorksheetBuilder.new(name, strict_excel_mode: @strict_excel_mode, state: state)
364
+ sheet_builder = WorksheetBuilder.new(name, strict_excel_mode: @strict_excel_mode, state: state, escape_formulas: @escape_formulas)
365
+ sheet_builder.code_name = code_name if code_name
366
+ sheet_builder.tab_color = tab_color if tab_color
72
367
  opts.each { |k, v| sheet_builder.sheet_properties(k, v) }
73
- yield sheet_builder if block_given?
74
368
  @sheet_builders << sheet_builder
75
- @sheets << sheet_builder.build
369
+ yield sheet_builder if block_given?
370
+ @defined_names.concat(sheet_builder.defined_names)
371
+ sheet_builder.defined_names.clear
372
+ built = sheet_builder.build
373
+ @sheets << built
374
+ built
375
+ end
376
+
377
+ # Accesses or defines a worksheet by name.
378
+ #
379
+ # @param name_or_index [String, Symbol, Integer, nil]
380
+ # @yield [sheet_builder]
381
+ # @return [Elements::Worksheet]
382
+ # @api public
383
+ #: (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetBuilder) -> void } -> Elements::Worksheet
384
+ def [](name_or_index = nil, &)
385
+ sheet(name_or_index&.to_s, &)
76
386
  end
77
- alias [] sheet
78
387
 
79
388
  # --- Workbook-Level Methods ---
80
389
 
81
- # Adds a defined name (named range or formula constant) to the workbook.
390
+ # Adds a defined name (named range or formula) to the workbook.
391
+ # Bare cell references and coordinate keywords are automatically formatted with sheet quotes and absolute $ references.
82
392
  #
83
- # @param name [String] Defined name (e.g. "TaxRate").
84
- # @param value [String] Formula expression or range reference (e.g. "Sheet1!$B$2").
85
- # @param sheet [String, nil] Optional sheet name for sheet-scoped defined names.
393
+ # @param name [String] Defined name identifier.
394
+ # @param value [Object, nil] Value or formula expression.
395
+ # @param sheet [String, nil] Reference sheet name for coordinates/formula.
396
+ # @param scope [String, Symbol, nil] Optional sheet name or :workbook for scope (defaults to workbook).
86
397
  # @param hidden [Boolean] Whether the defined name is hidden from Excel's UI.
398
+ # @param column [Integer, String, nil] Deprecated alias for columns.
399
+ # @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
400
+ # @param col [Integer, String, nil] Deprecated alias for column.
401
+ # @param row [Integer, Range, nil] Deprecated alias for rows.
402
+ # @param rows [Integer, Range, nil] Row or row range (1-based) for coordinate-based reference.
403
+ # @param range [String, nil] Cell range reference.
404
+ # @param ref_sheet [String, nil] Deprecated alias for sheet.
405
+ # @param local [Boolean] Deprecated alias for scope.
87
406
  # @return [void]
88
407
  # @api public
89
- #: (String name, String value, ?sheet: String?, ?hidden: bool) -> void
90
- def defined_name(name, value, sheet: nil, hidden: false)
91
- entry = { name: name, value: value, hidden: hidden }
92
- entry[:local_sheet_name] = sheet if sheet
408
+ #: (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
409
+ 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)
410
+ warn "[DEPRECATION] `col:` is deprecated; use `column:` (or `columns:`) instead.", uplevel: 1 if col
411
+ warn "[DEPRECATION] `ref_sheet:` is deprecated; use `sheet:` for reference sheet and `scope:` for scope instead.", uplevel: 1 if ref_sheet
412
+ warn "[DEPRECATION] `local:` is deprecated; use `scope:` instead.", uplevel: 1 if local
413
+ warn "[Xlsxrb DEPRECATION] defined_name keyword column: is deprecated; use columns: instead.", uplevel: 1 unless column.nil?
414
+ warn "[Xlsxrb DEPRECATION] defined_name keyword row: is deprecated; use rows: instead.", uplevel: 1 unless row.nil?
415
+ target_ref_sheet = ref_sheet || sheet
416
+ c_arg = column || columns || col
417
+ r_arg = row || rows
418
+ normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: target_ref_sheet, col: c_arg, rows: r_arg, range: range)
419
+ entry = { name: name, value: normalized_val, hidden: hidden }
420
+ local_sheet = if scope
421
+ scope == :workbook ? nil : scope.to_s
422
+ elsif sheet || local || ref_sheet
423
+ sheet
424
+ end
425
+ entry[:local_sheet_name] = local_sheet if local_sheet
93
426
  @defined_names << entry
94
427
  end
95
428
 
96
- # Sets the print area for a sheet.
429
+ # Returns workbook-level defined names.
97
430
  #
98
- # @param range [String] Cell range (e.g. "A1:G50").
431
+ # @return [Array<Elements::DefinedName>]
432
+ # @api public
433
+ #: () -> Array[Elements::DefinedName]
434
+ def defined_names
435
+ @defined_names.map { |dn| dn.is_a?(Elements::DefinedName) ? dn : Elements::DefinedName.new(**dn) }
436
+ end
437
+
438
+ # Sets or gets the print area for a sheet.
439
+ #
440
+ # @param range [String, Object, nil] Cell range (e.g. "A1:G50").
99
441
  # @param sheet [String, nil] Target sheet name (defaults to latest or "Sheet1").
100
- # @return [void]
442
+ # @return [String, nil, void]
101
443
  # @api public
102
- #: (String range, ?sheet: String?) -> void
103
- def print_area(range, sheet: nil)
444
+ #: (?untyped range, ?sheet: String?) -> (String | nil | void)
445
+ def print_area(range = OMITTED, sheet: nil)
104
446
  sheet_name = sheet || @sheets.last&.name || "Sheet1"
105
- value = "'#{sheet_name}'!#{absolute_range(range)}"
447
+ if range.equal?(OMITTED)
448
+ dn = @defined_names.find { |d| d[:name] == "_xlnm.Print_Area" && d[:local_sheet_name] == sheet_name }
449
+ return dn ? dn[:value].split("!", 2).last.tr("$", "") : nil
450
+ end
451
+
106
452
  @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Area" && dn[:local_sheet_name] == sheet_name }
107
- defined_name("_xlnm.Print_Area", value, sheet: sheet_name)
453
+ if range
454
+ value = "'#{sheet_name}'!#{absolute_range(range)}"
455
+ defined_name("_xlnm.Print_Area", value, sheet: sheet_name)
456
+ end
457
+ nil
458
+ end
459
+
460
+ # Sets the print area for the worksheet.
461
+ #
462
+ # @param range [String, nil] Cell range (e.g. "A1:G50").
463
+ # @return [String, nil]
464
+ # @api public
465
+ #: (String? range) -> String?
466
+ def print_area=(range)
467
+ print_area(range)
468
+ range
108
469
  end
109
470
 
110
471
  # Sets repeating print titles (rows and/or columns) for pagination.
111
472
  #
112
473
  # @param rows [String, nil] Repeating row range (e.g. "1:2").
113
- # @param cols [String, nil] Repeating column range (e.g. "A:B").
474
+ # @param columns [String, nil] Repeating column range (e.g. "A:B").
475
+ # @param cols [String, nil] Deprecated alias for columns.
114
476
  # @param sheet [String, nil] Target sheet name.
115
477
  # @return [void]
116
478
  # @api public
117
- #: (?rows: String?, ?cols: String?, ?sheet: String?) -> void
118
- def print_titles(rows: nil, cols: nil, sheet: nil)
479
+ #: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?, ?cols: (String | Integer | Symbol | Range[untyped])?, ?sheet: String?) -> void
480
+ def print_titles(rows: nil, columns: nil, cols: nil, sheet: nil)
481
+ warn "[DEPRECATION] `cols:` is deprecated; use `columns:` instead.", uplevel: 1 if cols && columns.nil?
482
+ c = DslHelpers.normalize_print_titles_columns(columns || cols)
483
+ r = DslHelpers.normalize_print_titles_rows(rows)
119
484
  sheet_name = sheet || @sheets.last&.name || "Sheet1"
120
485
  existing = @defined_names.find { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
121
- if existing && (rows.nil? || cols.nil?)
122
- cols = Regexp.last_match(1).delete("$") if cols.nil? && existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
123
- rows = Regexp.last_match(1).delete("$") if rows.nil? && existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
486
+ if existing && (r.nil? || c.nil?)
487
+ c = Regexp.last_match(1).delete("$") if c.nil? && existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
488
+ r = Regexp.last_match(1).delete("$") if r.nil? && existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
124
489
  end
125
490
  parts = []
126
- parts << "'#{sheet_name}'!$#{cols.sub(":", ":$")}" if cols
127
- parts << "'#{sheet_name}'!$#{rows.sub(":", ":$")}" if rows
491
+ parts << "'#{sheet_name}'!$#{c.sub(":", ":$")}" if c
492
+ parts << "'#{sheet_name}'!$#{r.sub(":", ":$")}" if r
128
493
  value = parts.join(",")
129
494
  @defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
130
495
  defined_name("_xlnm.Print_Titles", value, sheet: sheet_name)
496
+ nil
497
+ end
498
+
499
+ # Sets repeating print titles.
500
+ #
501
+ # @param opts [Elements::PrintTitles, Hash] Options with :rows and/or :columns.
502
+ # @return [Elements::PrintTitles, Hash]
503
+ # @api public
504
+ #: (Elements::PrintTitles | Hash[Symbol, untyped] opts) -> (Elements::PrintTitles | Hash[Symbol, untyped])
505
+ def print_titles=(opts)
506
+ h = opts.respond_to?(:to_h) ? opts.to_h : opts
507
+ print_titles(**h)
508
+ opts
131
509
  end
132
510
 
133
511
  # Sets repeating title rows for pagination on the target or active sheet.
@@ -166,9 +544,9 @@ module Xlsxrb
166
544
  cols_str = if first.is_a?(String)
167
545
  first.include?(":") ? first : "#{first}:#{last || first}"
168
546
  else
169
- first_name = Utils.col_index_to_name(first)
547
+ first_name = Elements::Cell._column_letter(first)
170
548
  last_name = if last.is_a?(Integer)
171
- Utils.col_index_to_name(last)
549
+ Elements::Cell._column_letter(last)
172
550
  elsif last
173
551
  last.to_s
174
552
  else
@@ -176,17 +554,39 @@ module Xlsxrb
176
554
  end
177
555
  "#{first_name}:#{last_name}"
178
556
  end
179
- print_titles(cols: cols_str, sheet: sheet)
557
+ print_titles(columns: cols_str, sheet: sheet)
180
558
  end
181
559
 
182
- # Sets workbook structure and window protection.
560
+ # Sets or returns workbook structure and window protection.
183
561
  #
184
562
  # @param opts [Hash] Protection options (e.g. lock_structure: true, password: "secret").
563
+ # @return [Elements::WorkbookProtection, nil, void]
564
+ # @api public
565
+ #: (**String | Integer | bool | nil opts) -> (Elements::WorkbookProtection | nil)
566
+ def workbook_protection(**opts)
567
+ if opts.empty?
568
+ @workbook_protection ? Elements::WorkbookProtection.new(**@workbook_protection) : nil
569
+ else
570
+ @workbook_protection = opts
571
+ nil
572
+ end
573
+ end
574
+
575
+ # Sets workbook protection settings.
576
+ #
577
+ # @param opts [Hash, Elements::MetadataRecord, nil]
185
578
  # @return [void]
186
579
  # @api public
580
+ #: (untyped opts) -> void
581
+ def workbook_protection=(opts)
582
+ @workbook_protection = opts.is_a?(Elements::MetadataRecord) ? opts.to_h : opts
583
+ end
584
+
585
+ # @deprecated Use {#workbook_protection} instead.
187
586
  #: (**String | Integer | bool | nil opts) -> void
188
- def protect_workbook(**opts)
189
- @workbook_protection = opts
587
+ def protect_workbook(...)
588
+ warn "[DEPRECATION] `protect_workbook` is deprecated; use `workbook_protection` instead.", uplevel: 1
589
+ workbook_protection(...)
190
590
  end
191
591
 
192
592
  # Sets a Dublin Core document metadata property.
@@ -200,6 +600,15 @@ module Xlsxrb
200
600
  @core_properties[name] = value
201
601
  end
202
602
 
603
+ # Returns core document properties.
604
+ #
605
+ # @return [Elements::CoreProperties]
606
+ # @api public
607
+ #: () -> Elements::CoreProperties
608
+ def core_properties
609
+ Elements::CoreProperties.new(**@core_properties)
610
+ end
611
+
203
612
  # Sets an extended application metadata property.
204
613
  #
205
614
  # @param name [Symbol] Application property name (:company, :manager, :app_version, etc.).
@@ -211,6 +620,15 @@ module Xlsxrb
211
620
  @app_properties[name] = value
212
621
  end
213
622
 
623
+ # Returns application document properties.
624
+ #
625
+ # @return [Elements::AppProperties]
626
+ # @api public
627
+ #: () -> Elements::AppProperties
628
+ def app_properties
629
+ Elements::AppProperties.new(**@app_properties)
630
+ end
631
+
214
632
  # Sets multiple core, app, and/or custom properties simultaneously.
215
633
  #
216
634
  # @param core [Hash{Symbol => Object}, nil] Core properties map.
@@ -237,6 +655,18 @@ module Xlsxrb
237
655
  @custom_properties << { name: name, value: value, type: type }
238
656
  end
239
657
 
658
+ # Returns custom document properties.
659
+ #
660
+ # @return [Hash<String, Elements::CustomProperty>]
661
+ # @api public
662
+ #: () -> Hash[String, Elements::CustomProperty]
663
+ def custom_properties
664
+ @custom_properties.to_h do |cp|
665
+ 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)
666
+ [prop.name.to_s, prop]
667
+ end.freeze
668
+ end
669
+
240
670
  # Builds and returns the compiled {Elements::Workbook}.
241
671
  #
242
672
  # @return [Elements::Workbook]
@@ -244,7 +674,10 @@ module Xlsxrb
244
674
  # @api public
245
675
  #: () -> Elements::Workbook
246
676
  def build
247
- raise ArgumentError, "Workbook must contain at least one sheet (Excel limitation)" if @strict_excel_mode && @sheets.empty?
677
+ if @strict_excel_mode
678
+ raise ArgumentError, "Workbook must contain at least one sheet (Excel limitation)" if @sheets.empty?
679
+ raise ArgumentError, "Workbook must contain at least one visible sheet (Excel limitation)" if @sheets.none? { |s| s.state == :visible }
680
+ end
248
681
 
249
682
  # Process styles from all sheets and collect style definitions
250
683
  processed_sheets, styles_definition = process_styles(@sheets)
@@ -252,9 +685,47 @@ module Xlsxrb
252
685
  # Auto-register print_area and print_titles defined names from sheet builders if not explicitly defined
253
686
  @sheet_builders.each do |sb|
254
687
  print_area(sb.print_area, sheet: sb.name) if sb.print_area && @defined_names.none? { |dn| dn[:name] == "_xlnm.Print_Area" && dn[:local_sheet_name] == sb.name }
255
- print_titles(rows: sb.print_titles[:rows], cols: sb.print_titles[:cols], sheet: sb.name) if sb.print_titles && @defined_names.none? { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sb.name }
688
+ print_titles(rows: sb.print_titles[:rows], columns: sb.print_titles[:columns] || sb.print_titles[:cols], sheet: sb.name) if sb.print_titles && @defined_names.none? { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sb.name }
689
+ sb.defined_names&.each do |dn|
690
+ @defined_names << dn
691
+ end
692
+ end
693
+
694
+ active_tab_idx = if @active_sheet.is_a?(Integer)
695
+ @active_sheet
696
+ elsif @active_sheet
697
+ idx = processed_sheets.find_index { |s| s.name == @active_sheet.to_s }
698
+ raise ArgumentError, "Active sheet '#{@active_sheet}' not found" if idx.nil? && @strict_excel_mode
699
+
700
+ idx || @active_sheet
701
+ end
702
+
703
+ if active_tab_idx.nil?
704
+ first_vis_idx = processed_sheets.find_index { |s| s.state == :visible }
705
+ active_tab_idx = first_vis_idx if first_vis_idx&.positive?
256
706
  end
257
707
 
708
+ if active_tab_idx.is_a?(Integer) && @strict_excel_mode
709
+ target = processed_sheets[active_tab_idx]
710
+ raise ArgumentError, "Active sheet index #{active_tab_idx} out of bounds" if target.nil?
711
+ raise ArgumentError, "Cannot set hidden sheet '#{target.name}' as active sheet" if target.state != :visible
712
+ end
713
+
714
+ first_sheet_idx = if @first_sheet.is_a?(Integer)
715
+ @first_sheet
716
+ elsif @first_sheet
717
+ idx = processed_sheets.find_index { |s| s.name == @first_sheet.to_s }
718
+ raise ArgumentError, "First sheet '#{@first_sheet}' not found" if idx.nil? && @strict_excel_mode
719
+
720
+ idx || @first_sheet
721
+ end
722
+
723
+ @workbook_properties[:active_sheet] = active_tab_idx unless active_tab_idx.nil?
724
+ @workbook_properties[:active_tab] = active_tab_idx unless active_tab_idx.nil?
725
+ @workbook_properties[:first_sheet] = first_sheet_idx unless first_sheet_idx.nil?
726
+ @workbook_properties[:show_sheet_tabs] = @show_sheet_tabs unless @show_sheet_tabs.nil?
727
+ @workbook_properties[:tab_ratio] = @tab_ratio unless @tab_ratio.nil?
728
+
258
729
  # Store workbook-level metadata in unmapped_data
259
730
  wb_meta = {}
260
731
  dns = resolve_defined_names(@defined_names, processed_sheets)
@@ -296,8 +767,8 @@ module Xlsxrb
296
767
 
297
768
  #: (untyped sheets) -> (::Array[untyped | ::Hash[untyped, untyped]] | ::Array[untyped])
298
769
  def process_styles(sheets)
299
- # Collect all unique StyleBuilders from all sheets
300
- all_style_builders = {}
770
+ # Collect all unique StyleBuilders from workbook and sheets
771
+ all_style_builders = @styles.dup
301
772
  @sheet_builders.each do |sheet_builder|
302
773
  sheet_builder.styles.each do |style_name, style_builder|
303
774
  all_style_builders[style_name.to_s] = style_builder
@@ -331,10 +802,16 @@ module Xlsxrb
331
802
  end
332
803
  end
333
804
 
334
- return [sheets, {}] if all_style_builders.empty?
805
+ if all_style_builders.empty?
806
+ if @default_font
807
+ temp_writer = Ooxml::Writer.new(default_font: @default_font)
808
+ return [sheets, extract_styles_from_writer(temp_writer)]
809
+ end
810
+ return [sheets, {}]
811
+ end
335
812
 
336
813
  # Create a temporary writer to register styles and get numeric IDs
337
- temp_writer = Ooxml::Writer.new
814
+ temp_writer = Ooxml::Writer.new(default_font: @default_font)
338
815
  style_name_to_id = {}
339
816
  all_style_builders.each do |name, builder|
340
817
  style_id = builder.register_with(temp_writer)
@@ -354,14 +831,14 @@ module Xlsxrb
354
831
  resolved_col_style = if raw_col_style.is_a?(Hash)
355
832
  inline_name = "__inline_col_#{raw_col_style.hash}"
356
833
  sb = all_style_builders[inline_name]
357
- if sb&.num_fmt_id
358
- col_fmt_map[col.index] = sb.num_fmt_id.is_a?(String) ? sb.num_fmt_id : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.num_fmt_id]
834
+ if sb&.number_format
835
+ col_fmt_map[col.index] = sb.number_format.is_a?(String) ? sb.number_format : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.number_format]
359
836
  end
360
837
  style_name_to_id[inline_name]
361
838
  elsif (raw_col_style.is_a?(String) || raw_col_style.is_a?(Symbol)) && style_name_to_id.key?(raw_col_style.to_s)
362
839
  sb = all_style_builders[raw_col_style.to_s]
363
- if sb&.num_fmt_id
364
- col_fmt_map[col.index] = sb.num_fmt_id.is_a?(String) ? sb.num_fmt_id : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.num_fmt_id]
840
+ if sb&.number_format
841
+ col_fmt_map[col.index] = sb.number_format.is_a?(String) ? sb.number_format : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.number_format]
365
842
  end
366
843
  style_name_to_id[raw_col_style.to_s]
367
844
  else
@@ -405,7 +882,7 @@ module Xlsxrb
405
882
  end
406
883
 
407
884
  new_cells = row.cells.map do |cell|
408
- raw_cell_style = cell.style_index
885
+ raw_cell_style = cell.style || cell.style_index
409
886
  resolved_cell_style = if (raw_cell_style.is_a?(String) || raw_cell_style.is_a?(Symbol)) && style_name_to_id.key?(raw_cell_style.to_s)
410
887
  style_name_to_id[raw_cell_style.to_s]
411
888
  elsif raw_cell_style.nil?
@@ -416,7 +893,7 @@ module Xlsxrb
416
893
 
417
894
  target_fmt = cell.format_code || col_fmt_map[cell.column_index]
418
895
 
419
- if resolved_cell_style == cell.style_index && target_fmt == cell.format_code
896
+ if resolved_cell_style == (cell.style || cell.style_index) && target_fmt == cell.format_code
420
897
  cell
421
898
  else
422
899
  Elements::Cell.new(
@@ -424,7 +901,8 @@ module Xlsxrb
424
901
  column_index: cell.column_index,
425
902
  value: cell.value,
426
903
  formula: cell.formula,
427
- style_index: resolved_cell_style,
904
+ style: (resolved_cell_style unless resolved_cell_style.is_a?(Integer)),
905
+ style_index: (resolved_cell_style if resolved_cell_style.is_a?(Integer)),
428
906
  hyperlink: cell.hyperlink,
429
907
  comment: cell.comment,
430
908
  raw_value: cell.raw_value,
@@ -439,10 +917,11 @@ module Xlsxrb
439
917
  index: row.index,
440
918
  cells: new_cells,
441
919
  height: row.height,
442
- hidden: row.hidden,
443
- custom_height: row.custom_height,
444
- collapsed: row.collapsed,
920
+ hidden: row.hidden?,
921
+ custom_height: row.custom_height?,
922
+ collapsed: row.collapsed?,
445
923
  outline_level: row.outline_level,
924
+ style_index: resolved_row_style,
446
925
  unmapped_data: row_unmapped,
447
926
  errors: row.errors
448
927
  )
@@ -454,7 +933,7 @@ module Xlsxrb
454
933
  [updated_sheets, styles_definition]
455
934
  end
456
935
 
457
- #: (untyped writer) -> { fonts: untyped, fills: untyped, borders: untyped, xf_entries: untyped, num_fmts: untyped }
936
+ #: (untyped writer) -> Hash[Symbol, untyped]
458
937
  def extract_styles_from_writer(writer)
459
938
  # Extract style definitions from the writer that can be reused
460
939
  # This captures the fonts, fills, borders, and xf entries that were created
@@ -462,6 +941,7 @@ module Xlsxrb
462
941
  fonts: writer.fonts.dup,
463
942
  fills: writer.fills.dup,
464
943
  borders: writer.borders.dup,
944
+ cell_xfs: writer.xf_entries.dup,
465
945
  xf_entries: writer.xf_entries.dup,
466
946
  num_fmts: writer.num_fmts.dup
467
947
  }