xlsxrb 0.1.17 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +256 -1
- data/README.md +111 -28
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +439 -139
- data/lib/xlsxrb/chart_builder.rb +540 -193
- data/lib/xlsxrb/dsl_helpers.rb +178 -73
- data/lib/xlsxrb/elements/cell.rb +197 -130
- data/lib/xlsxrb/elements/column.rb +88 -7
- data/lib/xlsxrb/elements/coordinate_access.rb +86 -59
- data/lib/xlsxrb/elements/image.rb +18 -19
- data/lib/xlsxrb/elements/metadata.rb +2379 -0
- data/lib/xlsxrb/elements/row.rb +84 -118
- data/lib/xlsxrb/elements/styles.rb +140 -90
- data/lib/xlsxrb/elements/types.rb +164 -22
- data/lib/xlsxrb/elements/workbook.rb +122 -140
- data/lib/xlsxrb/elements/worksheet.rb +451 -226
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +16 -5
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +14 -9
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +296 -34
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
- data/lib/xlsxrb/ooxml/reader.rb +52 -50
- data/lib/xlsxrb/ooxml/styles_parser.rb +36 -5
- data/lib/xlsxrb/ooxml/utils.rb +2 -2
- data/lib/xlsxrb/ooxml/workbook_parser.rb +0 -1
- data/lib/xlsxrb/ooxml/workbook_writer.rb +242 -109
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +63 -31
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +119 -56
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +33 -13
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +75 -15
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +18 -8
- data/lib/xlsxrb/ooxml/writer.rb +124 -44
- data/lib/xlsxrb/ooxml/xml_parser.rb +78 -5
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +112 -25
- data/lib/xlsxrb/ooxml/zip_writer.rb +119 -30
- data/lib/xlsxrb/stream_row.rb +56 -81
- data/lib/xlsxrb/stream_sheet.rb +542 -273
- data/lib/xlsxrb/stream_writer.rb +1536 -870
- data/lib/xlsxrb/style_builder.rb +667 -221
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +406 -143
- data/lib/xlsxrb/worksheet_builder.rb +1009 -900
- data/lib/xlsxrb.rb +1179 -1056
- data/sig/generated/xlsxrb/chart_builder.rbs +385 -159
- data/sig/generated/xlsxrb/dsl_helpers.rbs +81 -15
- data/sig/generated/xlsxrb/elements/cell.rbs +78 -70
- data/sig/generated/xlsxrb/elements/column.rbs +55 -3
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +35 -29
- data/sig/generated/xlsxrb/elements/image.rbs +7 -11
- data/sig/generated/xlsxrb/elements/metadata.rbs +1574 -0
- data/sig/generated/xlsxrb/elements/row.rbs +39 -42
- data/sig/generated/xlsxrb/elements/styles.rbs +66 -66
- data/sig/generated/xlsxrb/elements/types.rbs +27 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +46 -99
- data/sig/generated/xlsxrb/elements/worksheet.rbs +121 -96
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -4
- data/sig/generated/xlsxrb/ooxml/reader.rbs +2 -2
- data/sig/generated/xlsxrb/ooxml/styles_parser.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/utils.rbs +3 -3
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +13 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +16 -0
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +6 -4
- data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +7 -0
- data/sig/generated/xlsxrb/ooxml/writer.rbs +22 -13
- data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +70 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +24 -9
- data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +26 -1
- data/sig/generated/xlsxrb/stream_row.rbs +32 -33
- data/sig/generated/xlsxrb/stream_sheet.rbs +233 -181
- data/sig/generated/xlsxrb/stream_writer.rbs +961 -667
- data/sig/generated/xlsxrb/style_builder.rbs +402 -128
- data/sig/generated/xlsxrb/workbook_builder.rbs +223 -71
- data/sig/generated/xlsxrb/worksheet_builder.rbs +579 -453
- data/sig/generated/xlsxrb.rbs +205 -144
- data/sig/rexml.rbs +8 -0
- metadata +5 -5
- data/lib/xlsxrb/utils.rb +0 -291
- data/sig/generated/xlsxrb/utils.rbs +0 -184
data/lib/xlsxrb/stream_writer.rb
CHANGED
|
@@ -24,40 +24,49 @@ 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
|
-
#
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# @
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# Returns whether the shared strings table is enabled.
|
|
36
|
+
#
|
|
37
|
+
# @return [Boolean]
|
|
38
|
+
# @api public
|
|
39
|
+
#: () -> bool
|
|
40
|
+
def shared_strings?
|
|
41
|
+
@shared_strings ? true : false
|
|
42
|
+
end
|
|
37
43
|
|
|
38
44
|
# @return [Integer] The ZIP deflate compression level (0..9).
|
|
45
|
+
#: Integer
|
|
39
46
|
attr_reader :compression_level
|
|
40
47
|
|
|
48
|
+
# @return [Hash{String => StyleBuilder}]
|
|
49
|
+
#: Hash[String, StyleBuilder]
|
|
50
|
+
attr_reader :styles
|
|
51
|
+
|
|
41
52
|
# Initializes a streaming writer context.
|
|
42
53
|
#
|
|
43
54
|
# @param target [String, IO, StringIO] Destination file path or writable IO stream.
|
|
44
55
|
# @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel specification limits.
|
|
45
|
-
# @param escape_formulas [Boolean] Whether to treat strings starting with formula prefixes as plain text.
|
|
46
56
|
# @param default_font [Hash, nil] Optional default font options (e.g. `{ name: "Arial", size: 12 }`).
|
|
47
57
|
# @param shared_strings [Boolean] Whether to intern strings into a shared strings table (`xl/sharedStrings.xml`).
|
|
48
58
|
# When set to `false`, strings are written directly as inline strings (`<c t="inlineStr">`), maintaining flat
|
|
49
59
|
# $O(1)$ constant memory regardless of row count or unique string cardinality. Note that disabling shared strings
|
|
50
60
|
# may slightly increase archive size (typically 3-5%) on datasets with high repetition.
|
|
51
|
-
# @param compression_level [Integer, nil] ZIP deflate compression level (0..9, or Zlib::DEFAULT_COMPRESSION
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#: (untyped target, ?strict_excel_mode: bool, ?
|
|
55
|
-
def initialize(target, strict_excel_mode: true,
|
|
61
|
+
# @param compression_level [Integer, nil] ZIP deflate compression level (0..9, or Zlib::DEFAULT_COMPRESSION
|
|
62
|
+
# for zlib's level 6). Defaults to {Xlsxrb::DEFAULT_COMPRESSION_LEVEL}. Higher levels write smaller files more slowly;
|
|
63
|
+
# level 0 stores entries without compression. See docs/adr/0009-default-zip-compression-level.md.
|
|
64
|
+
#: (untyped target, ?strict_excel_mode: bool, ?default_font: untyped?, ?shared_strings: bool, ?compression_level: Integer | nil) -> void
|
|
65
|
+
def initialize(target, strict_excel_mode: true, default_font: nil, shared_strings: true, compression_level: DEFAULT_COMPRESSION_LEVEL)
|
|
56
66
|
@target = target
|
|
57
67
|
@strict_excel_mode = strict_excel_mode
|
|
58
|
-
@escape_formulas = escape_formulas ? true : false
|
|
59
68
|
@shared_strings = shared_strings ? true : false
|
|
60
|
-
@compression_level = compression_level ||
|
|
69
|
+
@compression_level = compression_level || DEFAULT_COMPRESSION_LEVEL
|
|
61
70
|
@io = target.is_a?(String) ? File.open(target, "wb") : target
|
|
62
71
|
@owns_io = target.is_a?(String)
|
|
63
72
|
@zip = Ooxml::ZipWriter.new(@io, compression_level: @compression_level)
|
|
@@ -109,6 +118,8 @@ module Xlsxrb
|
|
|
109
118
|
@current_phonetic_properties = nil
|
|
110
119
|
@current_sheet_calc_pr = nil
|
|
111
120
|
@current_background_image = nil
|
|
121
|
+
@current_print_area = nil
|
|
122
|
+
@current_print_titles = nil
|
|
112
123
|
@current_row_outline_level = nil
|
|
113
124
|
@current_row_collapsed = false
|
|
114
125
|
@current_row_hidden = false
|
|
@@ -116,8 +127,8 @@ module Xlsxrb
|
|
|
116
127
|
@styles = {} # { style_name => StyleBuilder }
|
|
117
128
|
@style_writer = Ooxml::Writer.new(default_font: default_font)
|
|
118
129
|
@style_name_to_id = {}
|
|
119
|
-
style("__xlsxrb_date", number_format:
|
|
120
|
-
style("__xlsxrb_time", number_format:
|
|
130
|
+
style("__xlsxrb_date", number_format: DslHelpers::DATE_NUMBER_FORMAT)
|
|
131
|
+
style("__xlsxrb_time", number_format: DslHelpers::TIME_NUMBER_FORMAT)
|
|
121
132
|
# Workbook-level settings
|
|
122
133
|
@defined_names = []
|
|
123
134
|
@core_properties = {}
|
|
@@ -136,75 +147,62 @@ module Xlsxrb
|
|
|
136
147
|
# @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
|
|
137
148
|
# @return [String, Symbol, Integer, nil]
|
|
138
149
|
# @api public
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
else
|
|
144
|
-
@active_sheet
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
alias active_sheet= active_sheet
|
|
148
|
-
alias active_tab active_sheet
|
|
149
|
-
alias active_tab= active_sheet
|
|
150
|
+
# Active worksheet tab in the workbook window.
|
|
151
|
+
# @return [String, Symbol, Integer, nil]
|
|
152
|
+
# @api public
|
|
153
|
+
attr_accessor :active_sheet #: (String | Symbol | Integer | nil)
|
|
150
154
|
|
|
151
|
-
#
|
|
152
|
-
#
|
|
153
|
-
# @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
|
|
155
|
+
# First sheet tab visible in the sheet tab scroll area.
|
|
154
156
|
# @return [String, Symbol, Integer, nil]
|
|
155
157
|
# @api public
|
|
156
|
-
|
|
157
|
-
def first_sheet(name_or_index = nil)
|
|
158
|
-
if name_or_index
|
|
159
|
-
@first_sheet = name_or_index
|
|
160
|
-
else
|
|
161
|
-
@first_sheet
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
alias first_sheet= first_sheet
|
|
158
|
+
attr_accessor :first_sheet #: (String | Symbol | Integer | nil)
|
|
165
159
|
|
|
166
|
-
#
|
|
167
|
-
#
|
|
160
|
+
# Sets whether sheet tabs are visible in the workbook window.
|
|
168
161
|
# @param visible [Boolean, nil]
|
|
169
162
|
# @return [Boolean, nil]
|
|
170
163
|
# @api public
|
|
171
|
-
#: (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
164
|
+
attr_writer :show_sheet_tabs #: (bool?) -> bool?
|
|
165
|
+
|
|
166
|
+
# Returns whether sheet tabs are visible in the workbook window.
|
|
167
|
+
# @return [Boolean]
|
|
168
|
+
# @api public
|
|
169
|
+
#: () -> bool
|
|
170
|
+
def show_sheet_tabs?
|
|
171
|
+
@show_sheet_tabs != false
|
|
178
172
|
end
|
|
179
|
-
alias show_sheet_tabs= show_sheet_tabs
|
|
180
173
|
|
|
181
|
-
#
|
|
182
|
-
#
|
|
183
|
-
# @param ratio [Integer, nil]
|
|
174
|
+
# Ratio between the sheet tabs bar and the horizontal scroll bar (0-1000).
|
|
184
175
|
# @return [Integer, nil]
|
|
185
176
|
# @api public
|
|
186
|
-
|
|
187
|
-
def tab_ratio(ratio = nil)
|
|
188
|
-
if ratio
|
|
189
|
-
@tab_ratio = ratio
|
|
190
|
-
else
|
|
191
|
-
@tab_ratio
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
alias tab_ratio= tab_ratio
|
|
177
|
+
attr_accessor :tab_ratio #: Integer?
|
|
195
178
|
|
|
196
|
-
#
|
|
179
|
+
# Configures or queries workbook-level properties.
|
|
180
|
+
#
|
|
181
|
+
# When called with no arguments, returns the {Elements::WorkbookProperties} value object.
|
|
182
|
+
# When called with keyword options, configures properties and returns nil.
|
|
197
183
|
#
|
|
198
|
-
# @
|
|
199
|
-
#
|
|
200
|
-
#
|
|
184
|
+
# @param opts [Hash] Workbook properties map.
|
|
185
|
+
# @return [Elements::WorkbookProperties, void]
|
|
186
|
+
# @api public
|
|
187
|
+
#: () -> Elements::WorkbookProperties
|
|
188
|
+
#: (**untyped opts) -> void
|
|
189
|
+
def workbook_properties(**opts)
|
|
190
|
+
return Elements::WorkbookProperties.new(**@workbook_properties) if opts.empty?
|
|
191
|
+
|
|
192
|
+
@workbook_properties.merge!(opts)
|
|
193
|
+
nil
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Sets workbook-level properties.
|
|
201
197
|
#
|
|
202
|
-
# @param
|
|
203
|
-
# @param value [String, Integer, Boolean] Property value.
|
|
198
|
+
# @param props [Hash, Elements::MetadataRecord]
|
|
204
199
|
# @return [void]
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
200
|
+
# @api public
|
|
201
|
+
#: (untyped props) -> void
|
|
202
|
+
def workbook_properties=(props)
|
|
203
|
+
h = props.respond_to?(:to_h) ? props.to_h : (props || {})
|
|
204
|
+
@workbook_properties = h.transform_keys(&:to_sym)
|
|
205
|
+
nil
|
|
208
206
|
end
|
|
209
207
|
|
|
210
208
|
# Defines or configures a named cell style.
|
|
@@ -239,7 +237,41 @@ module Xlsxrb
|
|
|
239
237
|
def default_font(name = nil, size = nil, **opts)
|
|
240
238
|
@style_writer.default_font(name, size, **opts)
|
|
241
239
|
end
|
|
242
|
-
|
|
240
|
+
|
|
241
|
+
# Creates an {Elements::Formula} object.
|
|
242
|
+
# @api public
|
|
243
|
+
#: (String expression, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), ?type: (Symbol | String)?, ?ref: String?, ?shared_index: Integer?) -> Elements::Formula
|
|
244
|
+
def formula(...)
|
|
245
|
+
Xlsxrb.formula(...)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Creates an array or dynamic array {Elements::Formula} object.
|
|
249
|
+
# @api public
|
|
250
|
+
#: (String expression, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), **untyped attrs) -> Elements::Formula
|
|
251
|
+
def array_formula(...)
|
|
252
|
+
Xlsxrb.array_formula(...)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# Creates a shared formula {Elements::Formula} object.
|
|
256
|
+
# @api public
|
|
257
|
+
#: (?String? expression, ?shared_index: Integer?, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil)) -> Elements::Formula
|
|
258
|
+
def shared_formula(...)
|
|
259
|
+
Xlsxrb.shared_formula(...)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
# Creates an {Elements::RichText} object.
|
|
263
|
+
# @api public
|
|
264
|
+
#: (*(Hash[Symbol, untyped] | Elements::RichTextRun | String | Array[untyped] | untyped) runs, ?text: String?, ?base_font: untyped, **untyped font_props) -> Elements::RichText
|
|
265
|
+
def rich_text(...)
|
|
266
|
+
Xlsxrb.rich_text(...)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# Creates or returns an {Elements::CellError} object.
|
|
270
|
+
# @api public
|
|
271
|
+
#: (String | Symbol | Elements::CellError code) -> Elements::CellError
|
|
272
|
+
def cell_error(...)
|
|
273
|
+
Xlsxrb.cell_error(...)
|
|
274
|
+
end
|
|
243
275
|
|
|
244
276
|
# Proxy object yielded by the `sheet` method to prevent writing to inactive sheets in streaming mode.
|
|
245
277
|
#
|
|
@@ -252,26 +284,48 @@ module Xlsxrb
|
|
|
252
284
|
@sheet_name = sheet_name
|
|
253
285
|
end
|
|
254
286
|
|
|
255
|
-
#
|
|
287
|
+
# Returns the worksheet name.
|
|
256
288
|
#
|
|
257
|
-
# @
|
|
258
|
-
# @param size [Float, Integer, nil] Font size in points.
|
|
259
|
-
# @param opts [Hash] Additional font options.
|
|
260
|
-
# @return [void]
|
|
289
|
+
# @return [String]
|
|
261
290
|
# @api public
|
|
262
|
-
#: (
|
|
263
|
-
def
|
|
264
|
-
@
|
|
291
|
+
#: () -> String
|
|
292
|
+
def name
|
|
293
|
+
@sheet_name
|
|
265
294
|
end
|
|
266
|
-
alias set_default_font default_font
|
|
267
295
|
|
|
268
|
-
#
|
|
269
|
-
#
|
|
270
|
-
|
|
296
|
+
# Creates an {Elements::Formula} object.
|
|
297
|
+
# @api public
|
|
298
|
+
#: (String expression, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), ?type: (Symbol | String)?, ?ref: String?, ?shared_index: Integer?) -> Elements::Formula
|
|
299
|
+
def formula(...)
|
|
300
|
+
Xlsxrb.formula(...)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
# Creates an array or dynamic array {Elements::Formula} object.
|
|
304
|
+
# @api public
|
|
305
|
+
#: (String expression, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil), **untyped attrs) -> Elements::Formula
|
|
306
|
+
def array_formula(...)
|
|
307
|
+
Xlsxrb.array_formula(...)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# Creates a shared formula {Elements::Formula} object.
|
|
311
|
+
# @api public
|
|
312
|
+
#: (?String? expression, ?shared_index: Integer?, ?ref: String?, ?cached_value: (String | Numeric | bool | Elements::CellError | nil)) -> Elements::Formula
|
|
313
|
+
def shared_formula(...)
|
|
314
|
+
Xlsxrb.shared_formula(...)
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
# Creates an {Elements::RichText} object.
|
|
318
|
+
# @api public
|
|
319
|
+
#: (*(Hash[Symbol, untyped] | Elements::RichTextRun | String | Array[untyped] | untyped) runs, ?text: String?, ?base_font: untyped, **untyped font_props) -> Elements::RichText
|
|
320
|
+
def rich_text(...)
|
|
321
|
+
Xlsxrb.rich_text(...)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
# Creates or returns an {Elements::CellError} object.
|
|
271
325
|
# @api public
|
|
272
|
-
#: () ->
|
|
273
|
-
def
|
|
274
|
-
|
|
326
|
+
#: (String | Symbol | Elements::CellError code) -> Elements::CellError
|
|
327
|
+
def cell_error(...)
|
|
328
|
+
Xlsxrb.cell_error(...)
|
|
275
329
|
end
|
|
276
330
|
|
|
277
331
|
# Defines or configures a named cell style on the active sheet.
|
|
@@ -297,18 +351,10 @@ module Xlsxrb
|
|
|
297
351
|
# @example Merge with cell reference string
|
|
298
352
|
# s.merge("A1:C1")
|
|
299
353
|
#
|
|
300
|
-
# @
|
|
301
|
-
# s.merge(row: 0, col_start: 0, col_end: 2)
|
|
302
|
-
#
|
|
303
|
-
# @param range [String, nil] The cell range (e.g. "A1:B2").
|
|
304
|
-
# @param row [Integer, nil] 0-based row index.
|
|
305
|
-
# @param col_start [Integer, String, nil] 0-based start column index or letter.
|
|
306
|
-
# @param col_end [Integer, String, nil] 0-based end column index or letter.
|
|
307
|
-
# @param row_start [Integer, nil] 0-based start row index.
|
|
308
|
-
# @param row_end [Integer, nil] 0-based end row index.
|
|
354
|
+
# @param range [String] The cell range (e.g. "A1:B2").
|
|
309
355
|
# @return [void]
|
|
310
356
|
# @api public
|
|
311
|
-
#: (
|
|
357
|
+
#: (String range) -> void
|
|
312
358
|
def merge(...)
|
|
313
359
|
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
|
|
314
360
|
|
|
@@ -318,59 +364,48 @@ module Xlsxrb
|
|
|
318
364
|
# Adds a drawing shape to the sheet.
|
|
319
365
|
#
|
|
320
366
|
# @example
|
|
321
|
-
# s.shape(preset: "ellipse", text: "Circle",
|
|
367
|
+
# s.shape(preset: "ellipse", text: "Circle", from_column: 1, from_row: 1, to_column: 4, to_row: 5)
|
|
322
368
|
#
|
|
323
369
|
# @param preset [String] Preset shape type (e.g. "rect", "ellipse").
|
|
324
370
|
# @param text [String, nil] Shape label text.
|
|
325
|
-
# @param
|
|
371
|
+
# @param from_column [Integer, nil] Starting column index (0-based).
|
|
326
372
|
# @param from_row [Integer] Starting row index (0-based).
|
|
327
|
-
# @param
|
|
373
|
+
# @param to_column [Integer, nil] Ending column index (0-based).
|
|
328
374
|
# @param to_row [Integer] Ending row index (0-based).
|
|
329
375
|
# @param opts [Hash] Additional shape formatting options.
|
|
330
376
|
# @return [void]
|
|
331
377
|
# @api public
|
|
332
|
-
#: (?preset: String, ?text: String?, ?
|
|
378
|
+
#: (?preset: String, ?text: String?, ?from_column: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_row: Integer, **untyped opts) -> void
|
|
333
379
|
def shape(...)
|
|
334
380
|
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
|
|
335
381
|
|
|
336
382
|
@writer.shape(...)
|
|
337
383
|
end
|
|
338
384
|
|
|
339
|
-
# simplecov:disable
|
|
340
|
-
# Edge case / untested delegation block
|
|
341
|
-
#: (*untyped args, **untyped kwargs) ?{ (*untyped) -> untyped } -> untyped
|
|
342
|
-
def internal_sheet_setup(...)
|
|
343
|
-
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
|
|
344
|
-
|
|
345
|
-
@writer.internal_sheet_setup(...)
|
|
346
|
-
end
|
|
347
|
-
# simplecov:enable
|
|
348
|
-
|
|
349
385
|
# Appends a row of cells to the active sheet.
|
|
350
386
|
#
|
|
351
387
|
# @example Write an array of values
|
|
352
388
|
# s.row(["Name", "Age", "City"])
|
|
353
389
|
#
|
|
354
390
|
# @example Write with explicit column keys and styles
|
|
355
|
-
# s.row({ A: "Header", C: 100 },
|
|
391
|
+
# s.row({ A: "Header", C: 100 }, cell_styles: { A: :bold })
|
|
356
392
|
#
|
|
357
393
|
# @param values [Array, Hash] The cell values (e.g. `[1, 2, 3]` or `{ A: 1, C: 3 }`).
|
|
358
|
-
# @param
|
|
394
|
+
# @param cell_styles [String, Symbol, Array, Hash, nil] Style names or hashes to apply to cells.
|
|
395
|
+
# @param row_style [Integer, Symbol, String, Hash, nil] Row style format or index.
|
|
359
396
|
# @param height [Float, Integer, nil] The row height in points (0 - 409).
|
|
360
397
|
# @param hidden [Boolean] Whether the row is hidden.
|
|
361
398
|
# @param custom_height [Boolean] Whether to flag as custom height.
|
|
362
399
|
# @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
|
|
363
400
|
# @param collapsed [Boolean] Whether the row is collapsed.
|
|
364
|
-
# @param style [Integer, Symbol, String, Hash, nil] Row style format or index.
|
|
365
401
|
# @return [void]
|
|
366
402
|
# @api public
|
|
367
|
-
#: (Array[untyped] | Hash[untyped, untyped] values, ?
|
|
368
|
-
def row(values,
|
|
403
|
+
#: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
|
|
404
|
+
def row(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
|
|
369
405
|
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
|
|
370
406
|
|
|
371
|
-
@writer.row(values,
|
|
407
|
+
@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)
|
|
372
408
|
end
|
|
373
|
-
alias add_row row
|
|
374
409
|
|
|
375
410
|
# Appends a row to the worksheet and returns self for chaining.
|
|
376
411
|
#
|
|
@@ -388,9 +423,6 @@ module Xlsxrb
|
|
|
388
423
|
|
|
389
424
|
# Advances the row cursor by count without writing empty row elements.
|
|
390
425
|
#
|
|
391
|
-
# @example Skip one row
|
|
392
|
-
# s.skip_row
|
|
393
|
-
#
|
|
394
426
|
# @example Skip multiple rows
|
|
395
427
|
# s.skip_rows(3)
|
|
396
428
|
#
|
|
@@ -403,24 +435,23 @@ module Xlsxrb
|
|
|
403
435
|
|
|
404
436
|
@writer.skip_rows(count)
|
|
405
437
|
end
|
|
406
|
-
alias skip_row skip_rows
|
|
407
438
|
|
|
408
439
|
# Configures column width and properties.
|
|
409
440
|
#
|
|
410
441
|
# @example Set column A width
|
|
411
442
|
# s.column(0, width: 25.0)
|
|
412
443
|
#
|
|
413
|
-
# @param
|
|
444
|
+
# @param index [Integer, String, Symbol, Range, Array] 0-based column index, letter ("A", :A), range, or array.
|
|
414
445
|
# @param width [Float, Integer, nil] Column width in characters.
|
|
415
446
|
# @param hidden [Boolean] Whether the column is hidden.
|
|
416
|
-
# @param best_fit [Boolean] Whether the column automatically fits content.
|
|
417
447
|
# @param custom_width [Boolean] Whether to flag as custom width.
|
|
418
448
|
# @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
|
|
419
449
|
# @param collapsed [Boolean] Whether the outline group is collapsed.
|
|
420
450
|
# @param style [Integer, Symbol, String, Hash, nil] Column style format or index.
|
|
451
|
+
# @param best_fit [Boolean] Whether the column automatically fits content.
|
|
421
452
|
# @return [void]
|
|
422
453
|
# @api public
|
|
423
|
-
#: (Integer | String | Symbol | Range[Integer | String] | Array[Integer | String]
|
|
454
|
+
#: (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
|
|
424
455
|
def column(...)
|
|
425
456
|
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
|
|
426
457
|
|
|
@@ -443,9 +474,6 @@ module Xlsxrb
|
|
|
443
474
|
|
|
444
475
|
@writer.group_columns(...)
|
|
445
476
|
end
|
|
446
|
-
alias group_column group_columns
|
|
447
|
-
alias group_cols group_columns
|
|
448
|
-
alias group_col group_columns
|
|
449
477
|
|
|
450
478
|
# Groups multiple rows with outline hierarchy with a block.
|
|
451
479
|
#
|
|
@@ -468,41 +496,51 @@ module Xlsxrb
|
|
|
468
496
|
@writer.group_rows(rows, level: level, collapsed: collapsed, hidden: hidden)
|
|
469
497
|
end
|
|
470
498
|
end
|
|
471
|
-
alias group_row group_rows
|
|
472
499
|
|
|
473
|
-
# Configures worksheet-level outline and grouping view properties.
|
|
500
|
+
# Configures or queries worksheet-level outline and grouping view properties.
|
|
474
501
|
#
|
|
475
502
|
# @param summary_below [Boolean, nil] Summary rows below detail rows.
|
|
476
503
|
# @param summary_right [Boolean, nil] Summary columns to the right of detail columns.
|
|
477
504
|
# @param show_outline_symbols [Boolean, nil] Outline symbols visible.
|
|
478
|
-
# @param show_symbols [Boolean, nil] Alias for show_outline_symbols.
|
|
479
505
|
# @param apply_styles [Boolean, nil] Automatic styles applied.
|
|
480
506
|
# @param opts [Hash] Additional options.
|
|
481
|
-
# @return [Hash]
|
|
507
|
+
# @return [Hash<Symbol, untyped>, void]
|
|
482
508
|
# @api public
|
|
483
|
-
#: (
|
|
509
|
+
#: () -> Hash[Symbol, untyped]
|
|
510
|
+
#: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
|
|
484
511
|
def outline_properties(...)
|
|
485
512
|
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
|
|
486
513
|
|
|
487
514
|
@writer.outline_properties(...)
|
|
488
515
|
end
|
|
489
|
-
|
|
516
|
+
|
|
517
|
+
# Sets worksheet-level outline and grouping view properties.
|
|
518
|
+
#
|
|
519
|
+
# @param opts [Hash] Outline properties.
|
|
520
|
+
# @return [void]
|
|
521
|
+
# @api public
|
|
522
|
+
#: (Hash[Symbol, untyped] opts) -> void
|
|
523
|
+
def outline_properties=(opts)
|
|
524
|
+
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
|
+
|
|
526
|
+
@writer.outline_properties = opts
|
|
527
|
+
end
|
|
490
528
|
|
|
491
529
|
# Adds a chart to the active sheet.
|
|
492
530
|
#
|
|
493
531
|
# @example
|
|
494
532
|
# s.chart(:bar) do |chart_builder|
|
|
495
|
-
# chart_builder.title
|
|
533
|
+
# chart_builder.title = "Quarterly Sales"
|
|
496
534
|
# chart_builder.series(values: "Sheet1!$B$2:$B$5", categories: "Sheet1!$A$2:$A$5", name: "Revenue")
|
|
497
535
|
# end
|
|
498
536
|
#
|
|
499
537
|
# @param type [Symbol, String, nil] The chart type (:bar, :col, :line, :pie, :scatter, :area, :doughnut, :radar).
|
|
500
|
-
# @param
|
|
538
|
+
# @param options [Hash] Additional chart options.
|
|
501
539
|
# @yield [chart_builder]
|
|
502
540
|
# @yieldparam chart_builder [Xlsxrb::ChartBuilder]
|
|
503
541
|
# @return [void]
|
|
504
542
|
# @api public
|
|
505
|
-
#: (?Symbol | String? type, **untyped
|
|
543
|
+
#: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
|
|
506
544
|
def chart(...)
|
|
507
545
|
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
|
|
508
546
|
|
|
@@ -531,19 +569,27 @@ module Xlsxrb
|
|
|
531
569
|
@writer.hyperlink(...)
|
|
532
570
|
end
|
|
533
571
|
|
|
534
|
-
#
|
|
572
|
+
# Returns the auto-filter range on the active sheet, or nil if none.
|
|
535
573
|
#
|
|
536
|
-
# @
|
|
537
|
-
#
|
|
574
|
+
# @return [String, nil]
|
|
575
|
+
# @api public
|
|
576
|
+
#: () -> String?
|
|
577
|
+
def auto_filter
|
|
578
|
+
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
|
|
579
|
+
|
|
580
|
+
@writer.auto_filter
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
# Sets the auto-filter range on the active sheet.
|
|
538
584
|
#
|
|
539
|
-
# @param
|
|
540
|
-
# @return [
|
|
585
|
+
# @param range [String, nil] The cell range (e.g. "A1:D10").
|
|
586
|
+
# @return [String, nil]
|
|
541
587
|
# @api public
|
|
542
|
-
#: (String
|
|
543
|
-
def auto_filter(
|
|
588
|
+
#: (String? range) -> String?
|
|
589
|
+
def auto_filter=(range)
|
|
544
590
|
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
|
|
545
591
|
|
|
546
|
-
@writer.auto_filter
|
|
592
|
+
@writer.auto_filter = range
|
|
547
593
|
end
|
|
548
594
|
|
|
549
595
|
# Sets filter criteria for a column in the auto-filter.
|
|
@@ -551,45 +597,56 @@ module Xlsxrb
|
|
|
551
597
|
# @example Simple values filter
|
|
552
598
|
# s.filter_column(0, ["Active", "Pending"])
|
|
553
599
|
#
|
|
554
|
-
# @param col_id [Integer] 0-based column index relative to auto-filter range.
|
|
555
|
-
# @param
|
|
600
|
+
# @param col_id [Integer, String, Symbol] 0-based column index relative to auto-filter range or column letter.
|
|
601
|
+
# @param filter [Hash] Values or filter specification hash.
|
|
556
602
|
# @return [void]
|
|
557
603
|
# @api public
|
|
558
|
-
#: (Integer
|
|
604
|
+
#: (Integer | String | Symbol col_id, (Hash[untyped, untyped] | Array[untyped]) filter) -> void
|
|
559
605
|
def filter_column(...)
|
|
560
606
|
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
|
|
561
607
|
|
|
562
608
|
@writer.filter_column(...)
|
|
563
609
|
end
|
|
564
610
|
|
|
565
|
-
# Configures sort state on a range.
|
|
611
|
+
# Configures or queries sort state on a range.
|
|
566
612
|
#
|
|
567
|
-
#
|
|
568
|
-
#
|
|
613
|
+
# When called with no arguments, returns the {Elements::SortState} value object.
|
|
614
|
+
# When called with arguments, updates sort state and returns nil.
|
|
569
615
|
#
|
|
570
|
-
# @param ref [String] The range to sort.
|
|
571
|
-
# @param sort_conditions [Array<Hash>,
|
|
616
|
+
# @param ref [String, nil] The range to sort.
|
|
617
|
+
# @param sort_conditions [Array<Hash>, nil] Sort conditions array.
|
|
572
618
|
# @param opts [Hash] Additional sort options.
|
|
573
|
-
# @return [void]
|
|
619
|
+
# @return [Elements::SortState, nil, void]
|
|
574
620
|
# @api public
|
|
575
|
-
#: (
|
|
621
|
+
#: () -> Elements::SortState?
|
|
622
|
+
#: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, **untyped opts) -> void
|
|
576
623
|
def sort_state(...)
|
|
577
624
|
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
|
|
578
625
|
|
|
579
626
|
@writer.sort_state(...)
|
|
580
627
|
end
|
|
581
628
|
|
|
582
|
-
#
|
|
629
|
+
# Sets sort state configuration for the active sheet.
|
|
583
630
|
#
|
|
584
|
-
#
|
|
631
|
+
# @param opts [Elements::SortState, Hash, nil] Sort state options.
|
|
632
|
+
# @return [void]
|
|
633
|
+
# @api public
|
|
634
|
+
#: (Elements::SortState | Hash[Symbol, untyped] | nil opts) -> void
|
|
635
|
+
def sort_state=(opts)
|
|
636
|
+
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
|
|
637
|
+
|
|
638
|
+
@writer.sort_state = opts
|
|
639
|
+
end
|
|
640
|
+
|
|
641
|
+
# Adds data validation rules to a range.
|
|
585
642
|
#
|
|
586
643
|
# @example Dropdown list validation
|
|
587
|
-
# s.
|
|
644
|
+
# s.data_validation("B2:B100", type: "list", formula1: '"High,Medium,Low"')
|
|
588
645
|
#
|
|
589
646
|
# @example Block syntax
|
|
590
|
-
# s.
|
|
591
|
-
# dv.type :list
|
|
592
|
-
# dv.formula1 '"High,Medium,Low"'
|
|
647
|
+
# s.data_validation("B2:B100") do |dv|
|
|
648
|
+
# dv.type = :list
|
|
649
|
+
# dv.formula1 = '"High,Medium,Low"'
|
|
593
650
|
# end
|
|
594
651
|
#
|
|
595
652
|
# @param range [String, nil] The cell range (e.g. "B2:B10").
|
|
@@ -599,10 +656,10 @@ module Xlsxrb
|
|
|
599
656
|
# @return [void]
|
|
600
657
|
# @api public
|
|
601
658
|
#: (?String? range, ?type: (String | Symbol)?, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
|
|
602
|
-
def
|
|
659
|
+
def data_validation(...)
|
|
603
660
|
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
661
|
|
|
605
|
-
@writer.
|
|
662
|
+
@writer.data_validation(...)
|
|
606
663
|
end
|
|
607
664
|
|
|
608
665
|
# Adds conditional formatting to a range.
|
|
@@ -636,8 +693,8 @@ module Xlsxrb
|
|
|
636
693
|
#
|
|
637
694
|
# @example Block syntax
|
|
638
695
|
# s.table("A1:C10") do |t|
|
|
639
|
-
# t.columns ["ID", "Name", "Total"]
|
|
640
|
-
# t.style "TableStyleMedium9"
|
|
696
|
+
# t.columns = ["ID", "Name", "Total"]
|
|
697
|
+
# t.style = "TableStyleMedium9"
|
|
641
698
|
# end
|
|
642
699
|
#
|
|
643
700
|
# @param ref [String, nil] The cell range for the table (e.g. "A1:D10").
|
|
@@ -656,16 +713,6 @@ module Xlsxrb
|
|
|
656
713
|
@writer.table(...)
|
|
657
714
|
end
|
|
658
715
|
|
|
659
|
-
# simplecov:disable
|
|
660
|
-
# Edge case / untested delegation block
|
|
661
|
-
#: () -> void
|
|
662
|
-
def cleanup!(...)
|
|
663
|
-
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
|
|
664
|
-
|
|
665
|
-
@writer.cleanup!(...)
|
|
666
|
-
end
|
|
667
|
-
# simplecov:enable
|
|
668
|
-
|
|
669
716
|
# Adds a comment to a cell.
|
|
670
717
|
#
|
|
671
718
|
# @example
|
|
@@ -674,9 +721,10 @@ module Xlsxrb
|
|
|
674
721
|
# @param cell [String, Integer] The cell reference (e.g. "A1").
|
|
675
722
|
# @param text [String] The comment text.
|
|
676
723
|
# @param author [String] The author name.
|
|
724
|
+
# @param visible [Boolean] Whether the comment is always shown instead of on hover.
|
|
677
725
|
# @return [void]
|
|
678
726
|
# @api public
|
|
679
|
-
#: (String | Integer cell, String text, ?author: String) -> void
|
|
727
|
+
#: (String | Integer cell, String text, ?author: String, ?visible: bool) -> void
|
|
680
728
|
def comment(...)
|
|
681
729
|
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
|
|
682
730
|
|
|
@@ -688,7 +736,7 @@ module Xlsxrb
|
|
|
688
736
|
# @param cell [String, Integer] The cell reference (e.g. "A1").
|
|
689
737
|
# @param text [String] The comment text.
|
|
690
738
|
# @param author [String] The author name.
|
|
691
|
-
# @param opts [Hash] Options: timestamp, id, parent_id, done, user_id, provider_id.
|
|
739
|
+
# @param visible [Boolean] Whether the comment is always shown instead of on hover. # @param opts [Hash] Options: timestamp, id, parent_id, done, user_id, provider_id.
|
|
692
740
|
# @return [void]
|
|
693
741
|
# @api public
|
|
694
742
|
#: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
|
|
@@ -697,22 +745,21 @@ module Xlsxrb
|
|
|
697
745
|
|
|
698
746
|
@writer.threaded_comment(...)
|
|
699
747
|
end
|
|
700
|
-
alias add_threaded_comment threaded_comment
|
|
701
748
|
|
|
702
749
|
# Adds a Pivot Table to the sheet.
|
|
703
750
|
#
|
|
704
751
|
# @param source_ref [String] Source data range reference (e.g. "Sheet1!A1:D100").
|
|
705
752
|
# @param row_fields [Array<String>] Field names for rows.
|
|
706
753
|
# @param data_fields [Array<String>] Field names for data values.
|
|
707
|
-
# @param
|
|
708
|
-
# @param
|
|
754
|
+
# @param column_fields [Array<String>, nil] Field names for columns.
|
|
755
|
+
# @param ref [String, nil] Target top-left cell reference (default: "E1").
|
|
709
756
|
# @param name [String, nil] Pivot table name.
|
|
710
757
|
# @param field_names [Array<String>, nil] Override field names.
|
|
711
|
-
# @param items [Array, nil] Items
|
|
758
|
+
# @param items [Hash{Integer => Array}, nil] Items of each field, by 0-based field index.
|
|
712
759
|
# @param opts [Hash] Additional options.
|
|
713
760
|
# @return [void]
|
|
714
761
|
# @api public
|
|
715
|
-
#: (String source_ref, row_fields: untyped, data_fields: untyped, ?
|
|
762
|
+
#: (String source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?ref: String?, ?name: String?, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
|
|
716
763
|
def pivot_table(...)
|
|
717
764
|
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
|
|
718
765
|
|
|
@@ -736,208 +783,192 @@ module Xlsxrb
|
|
|
736
783
|
@writer.sparkline_group(...)
|
|
737
784
|
end
|
|
738
785
|
|
|
739
|
-
# Adds a single sparkline to the sheet.
|
|
740
|
-
#
|
|
741
|
-
# @example Add a line sparkline
|
|
742
|
-
# s.add_sparkline(location: "F1", range: "A1:E1")
|
|
743
|
-
#
|
|
744
|
-
# @example Add a column sparkline with high/low markers
|
|
745
|
-
# s.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
|
|
746
|
-
#
|
|
747
|
-
# @example Add a win/loss sparkline
|
|
748
|
-
# s.add_sparkline(location: "F3", range: "A3:E3", type: :win_loss)
|
|
749
|
-
#
|
|
750
|
-
# @param location [String, nil] Target cell for the sparkline (e.g. "F1").
|
|
751
|
-
# @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
|
|
752
|
-
# @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
|
|
753
|
-
# @param opts [Hash] Additional sparkline options.
|
|
754
|
-
# @return [void]
|
|
755
|
-
# @api public
|
|
756
|
-
#: (?location: String?, ?range: String?, ?type: (String | Symbol)?, **untyped opts) -> void
|
|
757
|
-
def add_sparkline(...)
|
|
758
|
-
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
|
|
759
|
-
|
|
760
|
-
@writer.add_sparkline(...)
|
|
761
|
-
end
|
|
762
|
-
|
|
763
786
|
# Sets workbook-level properties.
|
|
764
787
|
#
|
|
765
|
-
#
|
|
766
|
-
# @return [void]
|
|
767
|
-
# @api public
|
|
768
|
-
#: (**untyped opts) -> void
|
|
769
|
-
def workbook_property(...)
|
|
770
|
-
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
|
|
771
|
-
|
|
772
|
-
@writer.workbook_property(...)
|
|
773
|
-
end
|
|
774
|
-
|
|
775
|
-
# Sets or gets the active sheet in the workbook window.
|
|
776
|
-
# If called without arguments on the proxy, marks this sheet as the active sheet.
|
|
777
|
-
#
|
|
778
|
-
# @param name_or_index [String, Symbol, Integer, nil]
|
|
779
|
-
# @return [String, Symbol, Integer, nil]
|
|
780
|
-
# @api public
|
|
781
|
-
#: (?String | Symbol | Integer | nil name_or_index) -> (String | Symbol | Integer | nil)
|
|
782
|
-
def active_sheet(name_or_index = @sheet_name)
|
|
783
|
-
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
|
|
784
|
-
|
|
785
|
-
@writer.active_sheet(name_or_index)
|
|
786
|
-
end
|
|
787
|
-
alias active_tab active_sheet
|
|
788
|
-
|
|
789
|
-
# Sets or gets the first visible sheet in the tab bar.
|
|
788
|
+
# Gets the sheet visibility state (:visible, :hidden, or :very_hidden).
|
|
790
789
|
#
|
|
791
|
-
# @
|
|
792
|
-
# @return [String, Symbol, Integer, nil]
|
|
790
|
+
# @return [Symbol]
|
|
793
791
|
# @api public
|
|
794
|
-
#: (
|
|
795
|
-
def
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
@writer.first_sheet(name_or_index)
|
|
792
|
+
#: () -> Symbol
|
|
793
|
+
def state
|
|
794
|
+
@writer.state
|
|
799
795
|
end
|
|
800
796
|
|
|
801
|
-
# Sets
|
|
797
|
+
# Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
|
|
802
798
|
#
|
|
803
|
-
# @param
|
|
804
|
-
# @return [
|
|
799
|
+
# @param new_state [Symbol, String] The new state.
|
|
800
|
+
# @return [Symbol]
|
|
805
801
|
# @api public
|
|
806
|
-
#: (
|
|
807
|
-
def
|
|
802
|
+
#: (Symbol | String new_state) -> Symbol
|
|
803
|
+
def state=(new_state)
|
|
808
804
|
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
805
|
|
|
810
|
-
@writer.
|
|
806
|
+
@writer.state = new_state
|
|
807
|
+
@writer.state
|
|
811
808
|
end
|
|
812
809
|
|
|
813
|
-
#
|
|
810
|
+
# Gets the tab color of this worksheet.
|
|
814
811
|
#
|
|
815
|
-
# @
|
|
816
|
-
# @return [Integer, nil]
|
|
812
|
+
# @return [String, Hash, nil]
|
|
817
813
|
# @api public
|
|
818
|
-
#: (
|
|
819
|
-
def
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
@writer.tab_ratio(ratio)
|
|
814
|
+
#: () -> (String | Hash[Symbol, untyped] | nil)
|
|
815
|
+
def tab_color
|
|
816
|
+
@writer.tab_color
|
|
823
817
|
end
|
|
824
818
|
|
|
825
|
-
#
|
|
819
|
+
# Sets the tab color of this worksheet.
|
|
826
820
|
#
|
|
827
|
-
# @param
|
|
828
|
-
# @return [
|
|
821
|
+
# @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
|
|
822
|
+
# @return [String, Hash, nil]
|
|
829
823
|
# @api public
|
|
830
|
-
#: (
|
|
831
|
-
def
|
|
824
|
+
#: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
|
|
825
|
+
def tab_color=(spec)
|
|
832
826
|
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
|
|
833
827
|
|
|
834
|
-
@writer.
|
|
828
|
+
@writer.tab_color = spec
|
|
835
829
|
end
|
|
836
830
|
|
|
837
|
-
#
|
|
831
|
+
# Configures or queries sheet properties.
|
|
838
832
|
#
|
|
839
|
-
# @param
|
|
840
|
-
# @
|
|
841
|
-
# @return [String, Hash, nil]
|
|
833
|
+
# @param opts [Hash] Keyword options for sheet properties.
|
|
834
|
+
# @return [Elements::SheetProperties, void]
|
|
842
835
|
# @api public
|
|
843
|
-
#: (
|
|
844
|
-
|
|
836
|
+
#: () -> Elements::SheetProperties
|
|
837
|
+
#: (**untyped opts) -> void
|
|
838
|
+
def sheet_properties(**opts)
|
|
845
839
|
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
|
|
846
840
|
|
|
847
|
-
@writer.
|
|
841
|
+
@writer.sheet_properties(**opts)
|
|
848
842
|
end
|
|
849
|
-
alias tab_color= tab_color
|
|
850
843
|
|
|
851
|
-
#
|
|
852
|
-
#
|
|
853
|
-
# @example
|
|
854
|
-
# s.sheet_properties(:tab_color, "FF0000")
|
|
855
|
-
#
|
|
856
|
-
# @param name [Symbol, String] Property name.
|
|
857
|
-
# @param value [Object] Property value.
|
|
844
|
+
# Replaces worksheet properties.
|
|
845
|
+
# @param opts [Hash, Elements::SheetProperties]
|
|
858
846
|
# @return [void]
|
|
859
847
|
# @api public
|
|
860
|
-
#: (Symbol |
|
|
861
|
-
def sheet_properties(
|
|
848
|
+
#: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
|
|
849
|
+
def sheet_properties=(opts)
|
|
862
850
|
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
|
|
863
851
|
|
|
864
|
-
@writer.sheet_properties
|
|
852
|
+
@writer.sheet_properties = opts
|
|
865
853
|
end
|
|
866
854
|
|
|
867
|
-
# Adds a defined named range or formula.
|
|
868
|
-
#
|
|
869
|
-
# @example
|
|
870
|
-
# s.defined_name("TaxRate", "0.10")
|
|
871
|
-
#
|
|
872
|
-
# @param name [String] The name.
|
|
873
855
|
# Adds a defined name (named range or formula) scoped to this sheet or workbook.
|
|
874
856
|
# Bare cell references and coordinate keywords are automatically formatted with sheet quotes and absolute $ references.
|
|
875
857
|
#
|
|
876
858
|
# @param name [String] Defined name identifier.
|
|
877
859
|
# @param value [Object, nil] Value or formula expression.
|
|
878
860
|
# @param hidden [Boolean] Whether the defined name is hidden.
|
|
879
|
-
# @param
|
|
880
|
-
# @param rows [Integer, Range, nil] Row or row range (
|
|
861
|
+
# @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
|
|
862
|
+
# @param rows [Integer, Range, nil] Row or row range (0-based) for coordinate-based reference.
|
|
881
863
|
# @param range [String, nil] Cell range reference.
|
|
882
|
-
# @param sheet [String, nil]
|
|
864
|
+
# @param sheet [String, nil] Reference sheet name (defaults to current sheet).
|
|
865
|
+
# @param scope [String, Symbol, nil] Scope identifier (:workbook or sheet name).
|
|
883
866
|
# @return [void]
|
|
884
867
|
# @api public
|
|
885
|
-
#: (String name, ?untyped value, ?hidden: bool, ?
|
|
886
|
-
def defined_name(name, value = nil, hidden: false,
|
|
868
|
+
#: (String name, ?untyped value, ?hidden: bool, ?columns: untyped, ?rows: untyped, ?range: untyped, ?sheet: String?, ?scope: (String | Symbol)?) -> void
|
|
869
|
+
def defined_name(name, value = nil, hidden: false, columns: nil, rows: nil, range: nil, sheet: nil, scope: nil)
|
|
887
870
|
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
|
|
888
871
|
|
|
889
872
|
ref_sheet = sheet || @sheet_name
|
|
890
|
-
local_sheet =
|
|
891
|
-
|
|
873
|
+
local_sheet = if scope
|
|
874
|
+
scope == :workbook ? nil : scope.to_s
|
|
875
|
+
end
|
|
876
|
+
@writer.defined_name(name, value, sheet: ref_sheet, scope: local_sheet, hidden: hidden, columns: columns, rows: rows, range: range)
|
|
892
877
|
end
|
|
893
878
|
|
|
894
|
-
#
|
|
879
|
+
# Configures or queries freeze panes (<pane state="frozen">).
|
|
880
|
+
#
|
|
881
|
+
# When called with no arguments, returns the {Elements::FreezePane} value object or nil.
|
|
882
|
+
# When called with arguments, configures the freeze pane and returns nil.
|
|
895
883
|
#
|
|
896
884
|
# @example Freeze top row
|
|
897
885
|
# s.freeze_pane(row: 1)
|
|
898
886
|
#
|
|
899
887
|
# @example Freeze first column and top 2 rows
|
|
900
|
-
# s.freeze_pane(row: 2,
|
|
888
|
+
# s.freeze_pane(row: 2, column: 1)
|
|
901
889
|
#
|
|
902
890
|
# @param row [Integer, nil] Number of rows to freeze.
|
|
903
|
-
# @param
|
|
904
|
-
# @return [void]
|
|
891
|
+
# @param column [Integer, String, nil] Number of columns to freeze.
|
|
892
|
+
# @return [Elements::FreezePane, nil, void]
|
|
905
893
|
# @api public
|
|
906
|
-
#: (
|
|
894
|
+
#: () -> Elements::FreezePane?
|
|
895
|
+
#: (?row: Integer | nil, ?column: (Integer | String)?, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
907
896
|
def freeze_pane(...)
|
|
908
897
|
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
|
|
909
898
|
|
|
910
899
|
@writer.freeze_pane(...)
|
|
911
900
|
end
|
|
912
901
|
|
|
913
|
-
#
|
|
914
|
-
# Edge case / untested delegation block
|
|
915
|
-
# Sets the print area range for the sheet.
|
|
902
|
+
# Sets or clears freeze pane configuration.
|
|
916
903
|
#
|
|
917
|
-
# @param
|
|
904
|
+
# @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
|
|
918
905
|
# @return [void]
|
|
919
906
|
# @api public
|
|
920
|
-
#: (
|
|
921
|
-
def
|
|
907
|
+
#: (Elements::FreezePane | Hash[Symbol, untyped] | nil opts) -> void
|
|
908
|
+
def freeze_pane=(opts)
|
|
922
909
|
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
|
|
923
910
|
|
|
924
|
-
@writer.
|
|
911
|
+
@writer.freeze_pane = opts
|
|
925
912
|
end
|
|
926
|
-
# simplecov:enable
|
|
927
913
|
|
|
928
|
-
#
|
|
929
|
-
# Edge case / untested delegation block
|
|
930
|
-
# Configures repeating title rows and columns for printing.
|
|
914
|
+
# Returns the print area range for this worksheet, or nil if none.
|
|
931
915
|
#
|
|
932
|
-
# @
|
|
933
|
-
# @
|
|
934
|
-
|
|
916
|
+
# @return [String, nil]
|
|
917
|
+
# @api public
|
|
918
|
+
#: () -> String?
|
|
919
|
+
def print_area
|
|
920
|
+
@writer.print_area(sheet: @sheet_name)
|
|
921
|
+
end
|
|
922
|
+
|
|
923
|
+
# Sets the print area for this worksheet.
|
|
924
|
+
#
|
|
925
|
+
# @param range [String, nil] Cell range (e.g. "A1:G50").
|
|
926
|
+
# @return [String, nil]
|
|
927
|
+
# @api public
|
|
928
|
+
#: (String? range) -> String?
|
|
929
|
+
def print_area=(range)
|
|
930
|
+
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
|
|
931
|
+
|
|
932
|
+
@writer.send(:set_print_area, range, sheet: @sheet_name)
|
|
933
|
+
end
|
|
934
|
+
|
|
935
|
+
# Sets or gets repeating print titles (rows and/or columns) for pagination.
|
|
936
|
+
#
|
|
937
|
+
# When called with no arguments, returns the {Elements::PrintTitles} value object or nil.
|
|
938
|
+
# When called with arguments, updates print titles and returns nil.
|
|
939
|
+
#
|
|
940
|
+
# @param rows [String, Integer, Range, nil] Repeating row range (e.g. "1:2").
|
|
941
|
+
# @param columns [String, Integer, Symbol, Range, nil] Repeating column range (e.g. "A:B").
|
|
942
|
+
# @return [Elements::PrintTitles, nil, void]
|
|
943
|
+
# @api public
|
|
944
|
+
#: () -> Elements::PrintTitles?
|
|
945
|
+
#: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?) -> void
|
|
946
|
+
def print_titles(rows: nil, columns: nil)
|
|
947
|
+
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
|
|
948
|
+
|
|
949
|
+
if rows.nil? && columns.nil?
|
|
950
|
+
@writer.print_titles(sheet: @sheet_name)
|
|
951
|
+
else
|
|
952
|
+
@writer.print_titles(rows: rows, columns: columns, sheet: @sheet_name)
|
|
953
|
+
end
|
|
954
|
+
end
|
|
955
|
+
|
|
956
|
+
# Sets repeating print titles for this worksheet.
|
|
957
|
+
#
|
|
958
|
+
# @param opts [Elements::PrintTitles, Hash, nil] Options with :rows and/or :columns.
|
|
959
|
+
# @return [Elements::PrintTitles, Hash, nil]
|
|
935
960
|
# @api public
|
|
936
|
-
#: (
|
|
937
|
-
def print_titles(
|
|
961
|
+
#: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
|
|
962
|
+
def print_titles=(opts)
|
|
938
963
|
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
|
|
939
964
|
|
|
940
|
-
|
|
965
|
+
if opts.nil?
|
|
966
|
+
@writer.print_titles = nil
|
|
967
|
+
else
|
|
968
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
969
|
+
@writer.print_titles(**h, sheet: @sheet_name)
|
|
970
|
+
end
|
|
971
|
+
opts
|
|
941
972
|
end
|
|
942
973
|
|
|
943
974
|
# Sets repeating title rows to appear at the top of each printed page.
|
|
@@ -967,68 +998,72 @@ module Xlsxrb
|
|
|
967
998
|
end
|
|
968
999
|
# simplecov:enable
|
|
969
1000
|
|
|
970
|
-
# Splits sheet view into panes.
|
|
1001
|
+
# Splits sheet view into panes or queries split pane settings (<pane>).
|
|
1002
|
+
#
|
|
1003
|
+
# When called with no arguments, returns the {Elements::SplitPane} value object or nil.
|
|
1004
|
+
# When called with arguments, configures the split pane and returns nil.
|
|
971
1005
|
#
|
|
972
|
-
# @param x_split [
|
|
973
|
-
# @param y_split [
|
|
1006
|
+
# @param x_split [Integer, nil] Horizontal split position.
|
|
1007
|
+
# @param y_split [Integer, nil] Vertical split position.
|
|
974
1008
|
# @param top_left_cell [String, nil] Top-left visible cell in bottom-right pane.
|
|
975
|
-
# @param active_pane [String, nil] Active pane identifier.
|
|
976
|
-
# @param state [String, nil] Split state.
|
|
977
|
-
# @return [void]
|
|
1009
|
+
# @param active_pane [String, Symbol, nil] Active pane identifier.
|
|
1010
|
+
# @param state [String, Symbol, nil] Split state.
|
|
1011
|
+
# @return [Elements::SplitPane, nil, void]
|
|
978
1012
|
# @api public
|
|
979
|
-
#: (
|
|
1013
|
+
#: () -> Elements::SplitPane?
|
|
1014
|
+
#: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
980
1015
|
def split_pane(...)
|
|
981
1016
|
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
|
|
982
1017
|
|
|
983
1018
|
@writer.split_pane(...)
|
|
984
1019
|
end
|
|
985
1020
|
|
|
986
|
-
#
|
|
987
|
-
# Edge case / untested delegation block
|
|
988
|
-
# Protects the workbook structure.
|
|
1021
|
+
# Sets or clears split pane configuration.
|
|
989
1022
|
#
|
|
990
|
-
# @param opts [Hash]
|
|
1023
|
+
# @param opts [Elements::SplitPane, Hash, nil] Split pane options.
|
|
991
1024
|
# @return [void]
|
|
992
1025
|
# @api public
|
|
993
|
-
#: (
|
|
994
|
-
def
|
|
1026
|
+
#: (Elements::SplitPane | Hash[Symbol, untyped] | nil opts) -> void
|
|
1027
|
+
def split_pane=(opts)
|
|
995
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
|
|
996
1029
|
|
|
997
|
-
@writer.
|
|
1030
|
+
@writer.split_pane = opts
|
|
998
1031
|
end
|
|
999
|
-
# simplecov:enable
|
|
1000
1032
|
|
|
1001
|
-
#
|
|
1002
|
-
# Edge case / untested delegation block
|
|
1003
|
-
# Sets core metadata property.
|
|
1033
|
+
# Sets or queries the active/selected cell on the sheet (<selection>).
|
|
1004
1034
|
#
|
|
1005
|
-
#
|
|
1006
|
-
#
|
|
1007
|
-
#
|
|
1035
|
+
# When called with no arguments, returns the selection ({Elements::Selection}, Array, or nil).
|
|
1036
|
+
# When called with arguments, updates the selection and returns nil.
|
|
1037
|
+
#
|
|
1038
|
+
# @param active_cell [String, nil] Cell reference (e.g. "A1") or range (e.g. "A1:D10").
|
|
1039
|
+
# @param sqref [String, nil] Selection range.
|
|
1040
|
+
# @param pane [String, Symbol, nil] Pane identifier.
|
|
1041
|
+
# @return [Elements::Selection, Array<Elements::Selection>, nil, void]
|
|
1008
1042
|
# @api public
|
|
1009
|
-
#: (
|
|
1010
|
-
|
|
1043
|
+
#: () -> (Elements::Selection | Array[Elements::Selection])?
|
|
1044
|
+
#: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
|
|
1045
|
+
def selection(...)
|
|
1011
1046
|
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
|
|
1012
1047
|
|
|
1013
|
-
@writer.
|
|
1048
|
+
@writer.selection(...)
|
|
1014
1049
|
end
|
|
1015
|
-
# simplecov:enable
|
|
1016
1050
|
|
|
1017
|
-
# Sets
|
|
1051
|
+
# Sets or clears the selection configuration.
|
|
1018
1052
|
#
|
|
1019
|
-
# @param
|
|
1020
|
-
# @param sqref [String, nil] Selection range.
|
|
1021
|
-
# @param pane [String, Symbol, nil] Pane identifier.
|
|
1053
|
+
# @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
|
|
1022
1054
|
# @return [void]
|
|
1023
1055
|
# @api public
|
|
1024
|
-
#: (
|
|
1025
|
-
def
|
|
1056
|
+
#: (Elements::Selection | Array[Elements::Selection | Hash[Symbol, untyped]] | Hash[Symbol, untyped] | nil opts) -> void
|
|
1057
|
+
def selection=(opts)
|
|
1026
1058
|
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
|
|
1027
1059
|
|
|
1028
|
-
@writer.
|
|
1060
|
+
@writer.selection = opts
|
|
1029
1061
|
end
|
|
1030
1062
|
|
|
1031
|
-
# Configures page margins for printing.
|
|
1063
|
+
# Configures or queries page margins for printing (<pageMargins>).
|
|
1064
|
+
#
|
|
1065
|
+
# When called with no arguments, returns the {Elements::PageMargins} value object or nil.
|
|
1066
|
+
# When called with arguments, configures page margins and returns nil.
|
|
1032
1067
|
#
|
|
1033
1068
|
# @param left [Float, nil] Left margin in inches.
|
|
1034
1069
|
# @param right [Float, nil] Right margin in inches.
|
|
@@ -1036,8 +1071,9 @@ module Xlsxrb
|
|
|
1036
1071
|
# @param bottom [Float, nil] Bottom margin in inches.
|
|
1037
1072
|
# @param header [Float, nil] Header margin in inches.
|
|
1038
1073
|
# @param footer [Float, nil] Footer margin in inches.
|
|
1039
|
-
# @return [void]
|
|
1074
|
+
# @return [Elements::PageMargins, nil, void]
|
|
1040
1075
|
# @api public
|
|
1076
|
+
#: () -> Elements::PageMargins?
|
|
1041
1077
|
#: (?left: Float | nil, ?right: Float | nil, ?top: Float | nil, ?bottom: Float | nil, ?header: Float | nil, ?footer: Float | nil) -> void
|
|
1042
1078
|
def page_margins(...)
|
|
1043
1079
|
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
|
|
@@ -1045,25 +1081,57 @@ module Xlsxrb
|
|
|
1045
1081
|
@writer.page_margins(...)
|
|
1046
1082
|
end
|
|
1047
1083
|
|
|
1048
|
-
#
|
|
1084
|
+
# Sets or clears page margins configuration.
|
|
1085
|
+
#
|
|
1086
|
+
# @param opts [Hash, Elements::PageMargins, nil]
|
|
1087
|
+
# @return [void]
|
|
1088
|
+
# @api public
|
|
1089
|
+
#: (Hash[Symbol, untyped] | Elements::PageMargins | nil opts) -> void
|
|
1090
|
+
def page_margins=(opts)
|
|
1091
|
+
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
|
|
1092
|
+
|
|
1093
|
+
@writer.page_margins = opts
|
|
1094
|
+
end
|
|
1095
|
+
|
|
1096
|
+
# Configures or queries page orientation, paper size, and print setup (<pageSetup>).
|
|
1097
|
+
#
|
|
1098
|
+
# When called with no arguments, returns the {Elements::PageSetup} value object.
|
|
1099
|
+
# When called with keyword arguments, updates page setup and returns nil.
|
|
1049
1100
|
#
|
|
1050
1101
|
# @param orientation [String, Symbol, nil] "portrait" or "landscape" (or :portrait, :landscape).
|
|
1051
1102
|
# @param paper_size [Integer, nil] Paper size index (e.g. 9 for A4, 1 for Letter).
|
|
1052
1103
|
# @param opts [Hash] Additional options (scale, fit_to_width, fit_to_height).
|
|
1053
|
-
# @return [void]
|
|
1104
|
+
# @return [Elements::PageSetup, void]
|
|
1054
1105
|
# @api public
|
|
1055
|
-
#: (
|
|
1106
|
+
#: () -> Elements::PageSetup
|
|
1107
|
+
#: (**untyped opts) -> void
|
|
1056
1108
|
def page_setup(...)
|
|
1057
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
|
|
1058
1110
|
|
|
1059
1111
|
@writer.page_setup(...)
|
|
1060
1112
|
end
|
|
1061
1113
|
|
|
1062
|
-
#
|
|
1114
|
+
# Sets page setup configuration.
|
|
1063
1115
|
#
|
|
1064
|
-
# @param opts [Hash]
|
|
1116
|
+
# @param opts [Hash, Elements::PageSetup]
|
|
1065
1117
|
# @return [void]
|
|
1066
1118
|
# @api public
|
|
1119
|
+
#: (Hash[Symbol, untyped] | Elements::PageSetup opts) -> void
|
|
1120
|
+
def page_setup=(opts)
|
|
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
|
|
1122
|
+
|
|
1123
|
+
@writer.page_setup = opts
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
|
+
# Configures or queries header and footer text for printing (<headerFooter>).
|
|
1127
|
+
#
|
|
1128
|
+
# When called with no arguments, returns the {Elements::HeaderFooter} value object.
|
|
1129
|
+
# When called with keyword arguments, updates headers and footers and returns nil.
|
|
1130
|
+
#
|
|
1131
|
+
# @param opts [Hash] Header and footer specifications.
|
|
1132
|
+
# @return [Elements::HeaderFooter, void]
|
|
1133
|
+
# @api public
|
|
1134
|
+
#: () -> Elements::HeaderFooter
|
|
1067
1135
|
#: (**untyped opts) -> void
|
|
1068
1136
|
def header_footer(...)
|
|
1069
1137
|
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
|
|
@@ -1071,150 +1139,167 @@ module Xlsxrb
|
|
|
1071
1139
|
@writer.header_footer(...)
|
|
1072
1140
|
end
|
|
1073
1141
|
|
|
1074
|
-
#
|
|
1142
|
+
# Sets header and footer configuration.
|
|
1075
1143
|
#
|
|
1076
|
-
# @param
|
|
1077
|
-
# @param value [Object] Print option value.
|
|
1144
|
+
# @param opts [Hash, Elements::HeaderFooter]
|
|
1078
1145
|
# @return [void]
|
|
1079
1146
|
# @api public
|
|
1080
|
-
#: (Symbol |
|
|
1081
|
-
def
|
|
1147
|
+
#: (Hash[Symbol, untyped] | Elements::HeaderFooter opts) -> void
|
|
1148
|
+
def header_footer=(opts)
|
|
1082
1149
|
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
|
|
1083
1150
|
|
|
1084
|
-
@writer.
|
|
1151
|
+
@writer.header_footer = opts
|
|
1085
1152
|
end
|
|
1086
1153
|
|
|
1087
|
-
#
|
|
1088
|
-
#
|
|
1089
|
-
# Sets document metadata properties (core, app, custom).
|
|
1154
|
+
# Configures or gets print options (e.g. gridlines, headings).
|
|
1155
|
+
# Configures or queries print options.
|
|
1090
1156
|
#
|
|
1091
|
-
# @param
|
|
1092
|
-
# @
|
|
1093
|
-
# @param custom [Hash, nil] Custom properties.
|
|
1094
|
-
# @return [void]
|
|
1157
|
+
# @param opts [Hash] Additional options.
|
|
1158
|
+
# @return [Elements::PrintOptions, void]
|
|
1095
1159
|
# @api public
|
|
1096
|
-
#: (
|
|
1097
|
-
|
|
1160
|
+
#: () -> Elements::PrintOptions
|
|
1161
|
+
#: (**untyped opts) -> void
|
|
1162
|
+
def print_options(**opts)
|
|
1098
1163
|
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
|
|
1099
1164
|
|
|
1100
|
-
@writer.
|
|
1165
|
+
@writer.print_options(**opts)
|
|
1101
1166
|
end
|
|
1102
|
-
# simplecov:enable
|
|
1103
1167
|
|
|
1104
|
-
#
|
|
1105
|
-
#
|
|
1106
|
-
# Sets app metadata property.
|
|
1107
|
-
#
|
|
1108
|
-
# @param name [String, Symbol] Property name.
|
|
1109
|
-
# @param value [Object] Property value.
|
|
1168
|
+
# Replaces print options.
|
|
1169
|
+
# @param opts [Hash, Elements::PrintOptions]
|
|
1110
1170
|
# @return [void]
|
|
1111
1171
|
# @api public
|
|
1112
|
-
#: (
|
|
1113
|
-
def
|
|
1172
|
+
#: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
|
|
1173
|
+
def print_options=(opts)
|
|
1114
1174
|
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
|
|
1115
1175
|
|
|
1116
|
-
@writer.
|
|
1176
|
+
@writer.print_options = opts
|
|
1117
1177
|
end
|
|
1118
|
-
# simplecov:enable
|
|
1119
1178
|
|
|
1120
|
-
#
|
|
1179
|
+
# Sets or queries sheet-level protection with optional password hashing (<sheetProtection>).
|
|
1180
|
+
#
|
|
1181
|
+
# When called with no arguments, returns the {Elements::SheetProtection} value object or nil.
|
|
1182
|
+
# When called with keyword arguments, sets sheet protection and returns nil.
|
|
1121
1183
|
#
|
|
1122
1184
|
# @param opts [Hash] Protection options.
|
|
1123
|
-
# @return [void]
|
|
1185
|
+
# @return [Elements::SheetProtection, nil, void]
|
|
1124
1186
|
# @api public
|
|
1187
|
+
#: () -> Elements::SheetProtection?
|
|
1125
1188
|
#: (**untyped opts) -> void
|
|
1126
|
-
def
|
|
1189
|
+
def sheet_protection(...)
|
|
1127
1190
|
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
|
|
1128
1191
|
|
|
1129
|
-
@writer.
|
|
1192
|
+
@writer.sheet_protection(...)
|
|
1130
1193
|
end
|
|
1131
1194
|
|
|
1132
|
-
#
|
|
1133
|
-
# Edge case / untested delegation block
|
|
1134
|
-
# Sets custom metadata property.
|
|
1195
|
+
# Sets or clears sheet protection configuration.
|
|
1135
1196
|
#
|
|
1136
|
-
# @param
|
|
1137
|
-
# @param value [Object] Property value.
|
|
1197
|
+
# @param opts [Elements::SheetProtection, Hash, Boolean, nil]
|
|
1138
1198
|
# @return [void]
|
|
1139
1199
|
# @api public
|
|
1140
|
-
#: (
|
|
1141
|
-
def
|
|
1200
|
+
#: (Elements::SheetProtection | Hash[Symbol, untyped] | bool | nil opts) -> void
|
|
1201
|
+
def sheet_protection=(opts)
|
|
1142
1202
|
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
|
|
1143
1203
|
|
|
1144
|
-
@writer.
|
|
1204
|
+
@writer.sheet_protection = opts
|
|
1205
|
+
end
|
|
1206
|
+
|
|
1207
|
+
# Returns column configurations defined for this worksheet.
|
|
1208
|
+
#
|
|
1209
|
+
# @return [Array<Elements::Column>]
|
|
1210
|
+
# @api public
|
|
1211
|
+
#: () -> Array[Elements::Column]
|
|
1212
|
+
def columns
|
|
1213
|
+
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
|
|
1214
|
+
|
|
1215
|
+
@writer.columns
|
|
1145
1216
|
end
|
|
1146
|
-
# simplecov:enable
|
|
1147
1217
|
|
|
1148
1218
|
# Inserts an image into the sheet.
|
|
1149
1219
|
#
|
|
1150
1220
|
# @param file_data [String] Binary image data or file content.
|
|
1151
1221
|
# @param ext [String] Image extension ("png", "jpeg", etc.).
|
|
1152
|
-
# @param
|
|
1222
|
+
# @param from_column [Integer, nil] Starting column index (0-based).
|
|
1153
1223
|
# @param from_row [Integer] Starting row index (0-based).
|
|
1154
|
-
# @param
|
|
1224
|
+
# @param to_column [Integer, nil] Ending column index (0-based).
|
|
1155
1225
|
# @param to_row [Integer] Ending row index (0-based).
|
|
1156
1226
|
# @param opts [Hash] Additional anchor and sizing options.
|
|
1157
1227
|
# @return [void]
|
|
1158
1228
|
# @api public
|
|
1159
|
-
#: (String file_data, ?ext: String, ?
|
|
1229
|
+
#: (String file_data, ?ext: String, ?from_column: Integer?, ?from_row: Integer, ?to_column: Integer?, ?to_row: Integer, **untyped opts) -> void
|
|
1160
1230
|
def image(...)
|
|
1161
1231
|
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
|
|
1162
1232
|
|
|
1163
1233
|
@writer.image(...)
|
|
1164
1234
|
end
|
|
1165
1235
|
|
|
1166
|
-
#
|
|
1167
|
-
#
|
|
1168
|
-
# @example Set background image from binary data
|
|
1169
|
-
# sheet.background_image(png_bytes, ext: "png")
|
|
1236
|
+
# Gets the worksheet background image (<picture>).
|
|
1170
1237
|
#
|
|
1171
|
-
# @
|
|
1172
|
-
# @param ext [String, nil] Image extension.
|
|
1173
|
-
# @param opts [Hash] Additional options.
|
|
1174
|
-
# @return [Hash, nil]
|
|
1238
|
+
# @return [Elements::BackgroundImage, nil]
|
|
1175
1239
|
# @api public
|
|
1176
|
-
#: (
|
|
1177
|
-
def background_image
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
@writer.background_image(...)
|
|
1240
|
+
#: () -> Elements::BackgroundImage?
|
|
1241
|
+
def background_image
|
|
1242
|
+
@writer.background_image
|
|
1181
1243
|
end
|
|
1182
|
-
alias background_picture background_image
|
|
1183
|
-
alias picture background_image
|
|
1184
1244
|
|
|
1245
|
+
# Sets the worksheet background image (<picture>).
|
|
1246
|
+
#
|
|
1247
|
+
# @param val [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
|
|
1248
|
+
# @return [untyped]
|
|
1249
|
+
# @api public
|
|
1250
|
+
#: (untyped val) -> untyped
|
|
1185
1251
|
def background_image=(val)
|
|
1186
1252
|
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
1253
|
|
|
1188
1254
|
@writer.background_image = val
|
|
1189
1255
|
end
|
|
1190
|
-
alias background_picture= background_image=
|
|
1191
|
-
alias picture= background_image=
|
|
1192
1256
|
|
|
1193
|
-
# Configures sheet view settings (zoom scale, grid lines visibility).
|
|
1257
|
+
# Configures or gets sheet view settings (zoom scale, grid lines visibility).
|
|
1194
1258
|
#
|
|
1195
|
-
# @param
|
|
1196
|
-
# @
|
|
1259
|
+
# @param opts [Hash] Additional options.
|
|
1260
|
+
# @return [Elements::SheetView, void]
|
|
1261
|
+
# @api public
|
|
1262
|
+
#: () -> Elements::SheetView
|
|
1263
|
+
#: (**untyped opts) -> void
|
|
1264
|
+
def sheet_view(**opts)
|
|
1265
|
+
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
|
|
1266
|
+
|
|
1267
|
+
@writer.sheet_view(**opts)
|
|
1268
|
+
end
|
|
1269
|
+
|
|
1270
|
+
# Replaces sheet view properties.
|
|
1271
|
+
# @param opts [Hash, Elements::SheetView]
|
|
1197
1272
|
# @return [void]
|
|
1198
1273
|
# @api public
|
|
1199
|
-
#: (Symbol |
|
|
1200
|
-
def sheet_view(
|
|
1274
|
+
#: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
|
|
1275
|
+
def sheet_view=(opts)
|
|
1201
1276
|
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
|
|
1202
1277
|
|
|
1203
|
-
@writer.sheet_view
|
|
1278
|
+
@writer.sheet_view = opts
|
|
1204
1279
|
end
|
|
1205
1280
|
|
|
1206
|
-
# Configures sheet format properties (e.g. default_row_height,
|
|
1281
|
+
# Configures or gets sheet format properties (e.g. default_row_height, default_column_width).
|
|
1207
1282
|
#
|
|
1208
|
-
# @param name [Symbol, String, Hash, nil] Property name or hash of properties.
|
|
1209
|
-
# @param value [Object, nil] Property value when name is provided.
|
|
1210
1283
|
# @param opts [Hash] Keyword arguments for sheet format properties.
|
|
1211
|
-
# @return [
|
|
1284
|
+
# @return [Elements::SheetFormat, void]
|
|
1212
1285
|
# @api public
|
|
1213
|
-
#: (
|
|
1214
|
-
|
|
1286
|
+
#: () -> Elements::SheetFormat
|
|
1287
|
+
#: (**untyped opts) -> void
|
|
1288
|
+
def sheet_format(**opts)
|
|
1215
1289
|
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
|
|
1216
1290
|
|
|
1217
|
-
@writer.sheet_format(
|
|
1291
|
+
@writer.sheet_format(**opts)
|
|
1292
|
+
end
|
|
1293
|
+
|
|
1294
|
+
# Replaces sheet format properties.
|
|
1295
|
+
# @param opts [Hash, Elements::SheetFormat]
|
|
1296
|
+
# @return [void]
|
|
1297
|
+
# @api public
|
|
1298
|
+
#: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
|
|
1299
|
+
def sheet_format=(opts)
|
|
1300
|
+
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
|
|
1301
|
+
|
|
1302
|
+
@writer.sheet_format = opts
|
|
1218
1303
|
end
|
|
1219
1304
|
|
|
1220
1305
|
# simplecov:disable
|
|
@@ -1225,25 +1310,25 @@ module Xlsxrb
|
|
|
1225
1310
|
# @return [void]
|
|
1226
1311
|
# @api public
|
|
1227
1312
|
#: (Integer row_index) -> void
|
|
1228
|
-
def
|
|
1313
|
+
def row_break(...)
|
|
1229
1314
|
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
|
|
1230
1315
|
|
|
1231
|
-
@writer.
|
|
1316
|
+
@writer.row_break(...)
|
|
1232
1317
|
end
|
|
1233
1318
|
# simplecov:enable
|
|
1234
1319
|
|
|
1235
1320
|
# simplecov:disable
|
|
1236
1321
|
# Edge case / untested delegation block
|
|
1237
|
-
# Adds a vertical page break after the given column
|
|
1322
|
+
# Adds a vertical page break after the given column.
|
|
1238
1323
|
#
|
|
1239
|
-
# @param
|
|
1324
|
+
# @param col [Integer, String, Symbol] 0-based column index or column letter.
|
|
1240
1325
|
# @return [void]
|
|
1241
1326
|
# @api public
|
|
1242
|
-
#: (Integer
|
|
1243
|
-
def
|
|
1327
|
+
#: (Integer | String | Symbol col) -> void
|
|
1328
|
+
def column_break(...)
|
|
1244
1329
|
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
|
|
1245
1330
|
|
|
1246
|
-
@writer.
|
|
1331
|
+
@writer.column_break(...)
|
|
1247
1332
|
end
|
|
1248
1333
|
# simplecov:enable
|
|
1249
1334
|
|
|
@@ -1261,7 +1346,6 @@ module Xlsxrb
|
|
|
1261
1346
|
|
|
1262
1347
|
@writer.protected_range(...)
|
|
1263
1348
|
end
|
|
1264
|
-
alias add_protected_range protected_range
|
|
1265
1349
|
|
|
1266
1350
|
# Adds a cell watch to the sheet.
|
|
1267
1351
|
#
|
|
@@ -1274,7 +1358,6 @@ module Xlsxrb
|
|
|
1274
1358
|
|
|
1275
1359
|
@writer.cell_watch(...)
|
|
1276
1360
|
end
|
|
1277
|
-
alias add_cell_watch cell_watch
|
|
1278
1361
|
|
|
1279
1362
|
# Adds an ignored error entry to the sheet.
|
|
1280
1363
|
#
|
|
@@ -1283,80 +1366,104 @@ module Xlsxrb
|
|
|
1283
1366
|
# @return [void]
|
|
1284
1367
|
# @api public
|
|
1285
1368
|
#: (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
|
|
1286
|
-
def
|
|
1369
|
+
def ignored_error(...)
|
|
1287
1370
|
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
|
|
1288
1371
|
|
|
1289
|
-
@writer.
|
|
1372
|
+
@writer.ignored_error(...)
|
|
1290
1373
|
end
|
|
1291
|
-
alias add_ignored_error ignore_error
|
|
1292
1374
|
|
|
1293
1375
|
# Returns the ignored error entries configured for this sheet.
|
|
1294
1376
|
#
|
|
1295
|
-
# @return [Array<
|
|
1377
|
+
# @return [Array<Elements::IgnoredError>]
|
|
1296
1378
|
# @api public
|
|
1297
|
-
#: () -> Array[
|
|
1379
|
+
#: () -> Array[Elements::IgnoredError]
|
|
1298
1380
|
def ignored_errors
|
|
1299
1381
|
@writer.ignored_errors
|
|
1300
1382
|
end
|
|
1301
1383
|
|
|
1302
|
-
# Gets
|
|
1384
|
+
# Gets phonetic (furigana) guide properties for the sheet.
|
|
1303
1385
|
#
|
|
1386
|
+
# @return [Elements::PhoneticProperties, nil]
|
|
1304
1387
|
# @api public
|
|
1305
|
-
#: (
|
|
1306
|
-
def phonetic_properties
|
|
1388
|
+
#: () -> Elements::PhoneticProperties?
|
|
1389
|
+
def phonetic_properties
|
|
1390
|
+
@writer.phonetic_properties
|
|
1391
|
+
end
|
|
1392
|
+
|
|
1393
|
+
# Sets phonetic (furigana) guide properties for the sheet.
|
|
1394
|
+
#
|
|
1395
|
+
# @param spec [Hash, Integer, nil] Options hash or font ID integer.
|
|
1396
|
+
# @return [Hash[Symbol, untyped], Integer, nil]
|
|
1397
|
+
# @api public
|
|
1398
|
+
#: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
|
|
1399
|
+
def phonetic_properties=(spec)
|
|
1307
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
|
|
1308
1401
|
|
|
1309
|
-
@writer.phonetic_properties
|
|
1402
|
+
@writer.phonetic_properties = spec
|
|
1403
|
+
end
|
|
1404
|
+
|
|
1405
|
+
# Gets the internal code name of the worksheet.
|
|
1406
|
+
#
|
|
1407
|
+
# @return [String, nil]
|
|
1408
|
+
# @api public
|
|
1409
|
+
#: () -> String?
|
|
1410
|
+
def code_name
|
|
1411
|
+
@writer.code_name
|
|
1310
1412
|
end
|
|
1311
|
-
alias phonetic_properties= phonetic_properties
|
|
1312
|
-
alias phonetic_pr phonetic_properties
|
|
1313
|
-
alias phonetic_pr= phonetic_properties
|
|
1314
1413
|
|
|
1315
|
-
# Sets
|
|
1414
|
+
# Sets the internal code name of the worksheet.
|
|
1316
1415
|
#
|
|
1317
1416
|
# @param val [String, Symbol, nil] The code name.
|
|
1318
1417
|
# @return [String, nil]
|
|
1319
1418
|
# @api public
|
|
1320
|
-
#: (
|
|
1321
|
-
def code_name(val
|
|
1419
|
+
#: (String | Symbol | nil val) -> String?
|
|
1420
|
+
def code_name=(val)
|
|
1322
1421
|
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
|
|
1323
1422
|
|
|
1324
|
-
@writer.code_name
|
|
1423
|
+
@writer.code_name = val
|
|
1325
1424
|
end
|
|
1326
|
-
alias code_name= code_name
|
|
1327
1425
|
|
|
1328
|
-
#
|
|
1329
|
-
#
|
|
1426
|
+
# Returns whether page setup fits content to page width/height.
|
|
1427
|
+
#
|
|
1428
|
+
# @return [Boolean]
|
|
1429
|
+
# @api public
|
|
1430
|
+
#: () -> bool
|
|
1431
|
+
def fit_to_page?
|
|
1432
|
+
@writer.fit_to_page?
|
|
1433
|
+
end
|
|
1434
|
+
|
|
1435
|
+
# Sets whether page setup fits content to page width/height.
|
|
1330
1436
|
#
|
|
1331
1437
|
# @param enabled [Boolean, nil] Whether to fit to page.
|
|
1332
|
-
# @
|
|
1333
|
-
# @param height [Integer, nil] Pages tall to fit to.
|
|
1334
|
-
# @return [Boolean, void]
|
|
1438
|
+
# @return [Boolean]
|
|
1335
1439
|
# @api public
|
|
1336
|
-
#: (
|
|
1337
|
-
def fit_to_page(enabled
|
|
1440
|
+
#: (bool? enabled) -> bool??
|
|
1441
|
+
def fit_to_page=(enabled)
|
|
1338
1442
|
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
|
|
1339
1443
|
|
|
1340
|
-
@writer.fit_to_page
|
|
1444
|
+
@writer.fit_to_page = enabled
|
|
1341
1445
|
end
|
|
1342
|
-
alias fit_to_page= fit_to_page
|
|
1343
|
-
alias fit_to_page? fit_to_page
|
|
1344
1446
|
|
|
1345
|
-
#
|
|
1447
|
+
# Gets worksheet calculation properties (<sheetCalcPr>).
|
|
1448
|
+
#
|
|
1449
|
+
# @return [Elements::SheetCalcProperties, nil]
|
|
1450
|
+
# @api public
|
|
1451
|
+
#: () -> Elements::SheetCalcProperties?
|
|
1452
|
+
def sheet_calc_properties
|
|
1453
|
+
@writer.sheet_calc_properties
|
|
1454
|
+
end
|
|
1455
|
+
|
|
1456
|
+
# Sets worksheet calculation properties (<sheetCalcPr>).
|
|
1346
1457
|
#
|
|
1347
1458
|
# @param spec [Hash, nil] Calculation properties hash.
|
|
1348
|
-
# @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
|
|
1349
1459
|
# @return [Hash, nil]
|
|
1350
1460
|
# @api public
|
|
1351
|
-
#: (
|
|
1352
|
-
def
|
|
1461
|
+
#: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
|
|
1462
|
+
def sheet_calc_properties=(spec)
|
|
1353
1463
|
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
|
|
1354
1464
|
|
|
1355
|
-
@writer.
|
|
1465
|
+
@writer.sheet_calc_properties = spec
|
|
1356
1466
|
end
|
|
1357
|
-
alias sheet_calc_pr= sheet_calc_pr
|
|
1358
|
-
alias calc_pr sheet_calc_pr
|
|
1359
|
-
alias calc_pr= sheet_calc_pr
|
|
1360
1467
|
end
|
|
1361
1468
|
|
|
1362
1469
|
# Returns the list of worksheet names created in this workbook so far.
|
|
@@ -1373,17 +1480,20 @@ module Xlsxrb
|
|
|
1373
1480
|
# Adds a new sheet to the workbook and starts streaming rows into it.
|
|
1374
1481
|
#
|
|
1375
1482
|
# @param name [String, nil] Sheet name (max 31 characters).
|
|
1483
|
+
# @param state [Symbol, String, nil] Sheet visibility state (:visible, :hidden, :very_hidden).
|
|
1484
|
+
# @param tab_color [String, Hash, Symbol, nil] Tab color hex string (e.g. "FF0000") or hash options.
|
|
1485
|
+
# @param code_name [String, Symbol, nil] Internal VBA code name of the sheet.
|
|
1376
1486
|
# @param opts [Hash] Sheet-level configuration.
|
|
1377
1487
|
# @yield [sheet_proxy]
|
|
1378
1488
|
# @yieldparam sheet_proxy [WorksheetProxy] The streaming sheet proxy.
|
|
1379
1489
|
# @return [String] The sheet name.
|
|
1380
1490
|
# @api public
|
|
1381
|
-
#: (?String? name, **untyped opts) ?{ (WorksheetProxy) -> void } ->
|
|
1382
|
-
def sheet(name = nil, **opts)
|
|
1491
|
+
#: (?String? name, ?state: Symbol | String | nil, ?tab_color: String | Hash[Symbol, untyped] | Symbol | nil, ?code_name: String | Symbol | nil, **untyped opts) ?{ (WorksheetProxy) -> void } -> String
|
|
1492
|
+
def sheet(name = nil, state: nil, tab_color: nil, code_name: nil, **opts)
|
|
1383
1493
|
sheet_count = @sheets.size + (@current_sheet ? 1 : 0)
|
|
1384
1494
|
name ||= "Sheet#{sheet_count + 1}"
|
|
1385
1495
|
raise ArgumentError, "Sheet name '#{name}' must be <= 31 characters (Excel limitation)" if @strict_excel_mode && name.length > 31
|
|
1386
|
-
raise ArgumentError, "Sheet name '#{name}' contains invalid characters (Excel limitation)" if name.match?(Elements::Worksheet
|
|
1496
|
+
raise ArgumentError, "Sheet name '#{name}' contains invalid characters (Excel limitation)" if name.match?(Elements::Worksheet.forbidden_name_chars)
|
|
1387
1497
|
raise ArgumentError, "Sheet name '#{name}' cannot start or end with an apostrophe (Excel limitation)" if @strict_excel_mode && (name.start_with?("'") || name.end_with?("'"))
|
|
1388
1498
|
raise ArgumentError, "Sheet name '#{name}' is reserved by Excel (Excel limitation)" if @strict_excel_mode && name.casecmp?("History")
|
|
1389
1499
|
|
|
@@ -1392,8 +1502,10 @@ module Xlsxrb
|
|
|
1392
1502
|
raise ArgumentError, "Sheet name '#{name}' is already used. Excel requires unique sheet names." if @strict_excel_mode && existing_names.include?(name.downcase)
|
|
1393
1503
|
|
|
1394
1504
|
active = opts.delete(:active)
|
|
1395
|
-
state = opts.delete(:state)
|
|
1505
|
+
state = opts.delete(:state) if opts.key?(:state)
|
|
1396
1506
|
hidden = opts.delete(:hidden)
|
|
1507
|
+
code_name = opts.delete(:code_name) if opts.key?(:code_name)
|
|
1508
|
+
tab_color = opts.delete(:tab_color) if opts.key?(:tab_color)
|
|
1397
1509
|
state ||= :hidden if hidden
|
|
1398
1510
|
state ||= :visible
|
|
1399
1511
|
state = state.to_sym
|
|
@@ -1404,13 +1516,38 @@ module Xlsxrb
|
|
|
1404
1516
|
@active_sheet = name
|
|
1405
1517
|
@current_sheet_view[:tab_selected] = true
|
|
1406
1518
|
end
|
|
1407
|
-
|
|
1519
|
+
self.tab_color = tab_color if tab_color
|
|
1520
|
+
self.code_name = code_name if code_name
|
|
1521
|
+
sheet_properties(**opts) unless opts.empty?
|
|
1408
1522
|
|
|
1409
1523
|
yield WorksheetProxy.new(self, @current_sheet) if block_given?
|
|
1410
1524
|
@current_sheet
|
|
1411
1525
|
end
|
|
1412
1526
|
|
|
1527
|
+
# Returns a WorksheetProxy for the current or named sheet.
|
|
1528
|
+
#
|
|
1529
|
+
# @param name_or_index [String, Symbol, Integer, nil] Sheet name or 0-based sheet index.
|
|
1530
|
+
# @yield [proxy]
|
|
1531
|
+
# @yieldparam proxy [WorksheetProxy]
|
|
1532
|
+
# @return [WorksheetProxy]
|
|
1533
|
+
# @api public
|
|
1534
|
+
#: (?String | Symbol | Integer | nil name_or_index) ?{ (WorksheetProxy) -> void } -> WorksheetProxy
|
|
1535
|
+
def [](name_or_index = nil)
|
|
1536
|
+
target_name = if name_or_index.nil?
|
|
1537
|
+
@current_sheet || sheet
|
|
1538
|
+
elsif name_or_index.is_a?(Integer)
|
|
1539
|
+
all_names = sheet_names
|
|
1540
|
+
all_names[name_or_index] || raise(ArgumentError, "Sheet index #{name_or_index} out of bounds")
|
|
1541
|
+
else
|
|
1542
|
+
name_or_index.to_s
|
|
1543
|
+
end
|
|
1544
|
+
proxy = WorksheetProxy.new(self, target_name)
|
|
1545
|
+
yield proxy if block_given?
|
|
1546
|
+
proxy
|
|
1547
|
+
end
|
|
1548
|
+
|
|
1413
1549
|
# Internal: Start or switch to a named sheet (internal helper).
|
|
1550
|
+
# @api private
|
|
1414
1551
|
#: (?String? name, ?state: Symbol) ?{ (WorksheetProxy) -> void } -> (WorksheetProxy | nil)
|
|
1415
1552
|
def internal_sheet_setup(name = nil, state: :visible)
|
|
1416
1553
|
flush_current_sheet
|
|
@@ -1423,7 +1560,7 @@ module Xlsxrb
|
|
|
1423
1560
|
@current_row_buffer = String.new(capacity: 65_536)
|
|
1424
1561
|
@current_sheet_io = StringIO.new(@current_row_buffer)
|
|
1425
1562
|
date1904 = @workbook_properties&.[](:date1904) ? true : false
|
|
1426
|
-
@current_row_writer = Ooxml::WorksheetWriter.new(@current_sheet_io, date1904: date1904
|
|
1563
|
+
@current_row_writer = Ooxml::WorksheetWriter.new(@current_sheet_io, date1904: date1904)
|
|
1427
1564
|
@current_row_writer.instance_variable_set(:@started, true)
|
|
1428
1565
|
|
|
1429
1566
|
@current_columns = []
|
|
@@ -1461,6 +1598,8 @@ module Xlsxrb
|
|
|
1461
1598
|
@current_phonetic_properties = nil
|
|
1462
1599
|
@current_sheet_calc_pr = nil
|
|
1463
1600
|
@current_background_image = nil
|
|
1601
|
+
@current_print_area = nil
|
|
1602
|
+
@current_print_titles = nil
|
|
1464
1603
|
@current_row_outline_level = nil
|
|
1465
1604
|
@current_row_collapsed = false
|
|
1466
1605
|
@current_row_hidden = false
|
|
@@ -1475,6 +1614,8 @@ module Xlsxrb
|
|
|
1475
1614
|
# simplecov:enable
|
|
1476
1615
|
end
|
|
1477
1616
|
|
|
1617
|
+
# @api private
|
|
1618
|
+
#: () -> void
|
|
1478
1619
|
def start_sheet_entry
|
|
1479
1620
|
return if @sheet_entry_started
|
|
1480
1621
|
|
|
@@ -1499,7 +1640,7 @@ module Xlsxrb
|
|
|
1499
1640
|
end
|
|
1500
1641
|
|
|
1501
1642
|
date1904 = @workbook_properties&.[](:date1904) ? true : false
|
|
1502
|
-
@current_row_writer = Ooxml::WorksheetWriter.new(zip_io, date1904: date1904
|
|
1643
|
+
@current_row_writer = Ooxml::WorksheetWriter.new(zip_io, date1904: date1904)
|
|
1503
1644
|
@current_row_writer.start(
|
|
1504
1645
|
columns: @current_columns,
|
|
1505
1646
|
sheet_properties: @current_sheet_properties.empty? ? nil : @current_sheet_properties,
|
|
@@ -1516,16 +1657,17 @@ module Xlsxrb
|
|
|
1516
1657
|
# Appends a row of values to the active sheet.
|
|
1517
1658
|
#
|
|
1518
1659
|
# @param values [Array<Object>, Hash] The cell values.
|
|
1519
|
-
# @param
|
|
1660
|
+
# @param cell_styles [String, Symbol, Array, Hash, nil] Style names or inline style definitions to apply to cells.
|
|
1661
|
+
# @param row_style [Integer, Symbol, String, Hash, nil] Row style format or index.
|
|
1520
1662
|
# @param height [Float, Integer, nil] The row height in points (0 - 409).
|
|
1521
1663
|
# @param hidden [Boolean] Whether the row is hidden.
|
|
1522
1664
|
# @param custom_height [Boolean] Whether custom row height is set.
|
|
1523
1665
|
# @param outline_level [Integer, nil] Grouping/outline level (0 - 7).
|
|
1524
|
-
# @param
|
|
1666
|
+
# @param collapsed [Boolean] Whether the row is collapsed.
|
|
1525
1667
|
# @return [void]
|
|
1526
1668
|
# @api public
|
|
1527
|
-
#: (Array[untyped] | Hash[untyped, untyped] values, ?
|
|
1528
|
-
def row(values,
|
|
1669
|
+
#: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: untyped, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
|
|
1670
|
+
def row(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
|
|
1529
1671
|
sheet if @current_sheet.nil?
|
|
1530
1672
|
|
|
1531
1673
|
row_index = @current_row_index
|
|
@@ -1533,7 +1675,12 @@ module Xlsxrb
|
|
|
1533
1675
|
@current_row_index += 1
|
|
1534
1676
|
|
|
1535
1677
|
values = DslHelpers.normalize_row_values(values)
|
|
1536
|
-
|
|
1678
|
+
cell_styles = DslHelpers.normalize_row_styles(cell_styles)
|
|
1679
|
+
if cell_styles
|
|
1680
|
+
check_style_names!(cell_styles)
|
|
1681
|
+
cell_styles = with_date_style_variants(values, cell_styles)
|
|
1682
|
+
end
|
|
1683
|
+
DslHelpers.check_style_name!(row_style, @style_name_to_id)
|
|
1537
1684
|
|
|
1538
1685
|
if @current_charts && !@current_charts.empty?
|
|
1539
1686
|
@current_cells ||= {}
|
|
@@ -1541,19 +1688,19 @@ module Xlsxrb
|
|
|
1541
1688
|
values.each_with_index do |val, col_idx|
|
|
1542
1689
|
next if val.nil?
|
|
1543
1690
|
|
|
1544
|
-
addr = "#{Elements::Cell.
|
|
1691
|
+
addr = "#{Elements::Cell._column_letter(col_idx)}#{row_num}"
|
|
1545
1692
|
@current_cells[addr] = val
|
|
1546
1693
|
end
|
|
1547
1694
|
end
|
|
1548
1695
|
|
|
1549
1696
|
raise ArgumentError, "Row contains #{values.length} columns, exceeding Excel limit of 16_384 columns" if @strict_excel_mode && values.length > 16_384
|
|
1550
1697
|
|
|
1551
|
-
row_style_id = if
|
|
1552
|
-
inline_name = "__inline_row_#{
|
|
1553
|
-
style(inline_name, **
|
|
1698
|
+
row_style_id = if row_style.is_a?(Hash)
|
|
1699
|
+
inline_name = "__inline_row_#{row_style.hash}"
|
|
1700
|
+
style(inline_name, **row_style) unless @style_name_to_id.key?(inline_name)
|
|
1554
1701
|
@style_name_to_id[inline_name]
|
|
1555
1702
|
else
|
|
1556
|
-
|
|
1703
|
+
row_style
|
|
1557
1704
|
end
|
|
1558
1705
|
|
|
1559
1706
|
effective_outline = outline_level || @current_row_outline_level
|
|
@@ -1571,10 +1718,9 @@ module Xlsxrb
|
|
|
1571
1718
|
attrs[:style_index] = row_style_id if row_style_id
|
|
1572
1719
|
end
|
|
1573
1720
|
|
|
1574
|
-
@current_row_writer.write_row_values(row_index, values, styles:
|
|
1721
|
+
@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)
|
|
1575
1722
|
start_sheet_entry if !@sheet_entry_started && @current_row_buffer.bytesize >= 65_536
|
|
1576
1723
|
end
|
|
1577
|
-
alias add_row row
|
|
1578
1724
|
|
|
1579
1725
|
# Appends a row to the worksheet and returns self for chaining.
|
|
1580
1726
|
#
|
|
@@ -1592,9 +1738,6 @@ module Xlsxrb
|
|
|
1592
1738
|
|
|
1593
1739
|
# Advances the row cursor by count without writing empty row elements.
|
|
1594
1740
|
#
|
|
1595
|
-
# @example Skip one row
|
|
1596
|
-
# w.skip_row
|
|
1597
|
-
#
|
|
1598
1741
|
# @example Skip multiple rows
|
|
1599
1742
|
# w.skip_rows(3)
|
|
1600
1743
|
#
|
|
@@ -1608,23 +1751,26 @@ module Xlsxrb
|
|
|
1608
1751
|
sheet if @current_sheet.nil?
|
|
1609
1752
|
@current_row_index += count
|
|
1610
1753
|
end
|
|
1611
|
-
alias skip_row skip_rows
|
|
1612
1754
|
|
|
1613
1755
|
# Sets column formatting and properties for one or multiple columns.
|
|
1614
1756
|
#
|
|
1615
|
-
# @param index [Integer, String, Range, Array] Column index (0-based)
|
|
1757
|
+
# @param index [Integer, String, Symbol, Range, Array] Column index (0-based), letter ("A", :A), range, or array.
|
|
1616
1758
|
# @param width [Float, Integer, nil] Column width in character units (0 - 255).
|
|
1617
1759
|
# @param hidden [Boolean] Whether the column is hidden.
|
|
1760
|
+
# @param custom_width [Boolean] Whether custom width flag is set.
|
|
1761
|
+
# @param outline_level [Integer, nil] Grouping/outline level.
|
|
1618
1762
|
# @param collapsed [Boolean] Whether the column is collapsed.
|
|
1619
1763
|
# @param style [Integer, Symbol, String, Hash, nil] Column style format or index.
|
|
1764
|
+
# @param best_fit [Boolean] Whether the column automatically fits content.
|
|
1620
1765
|
# @return [void]
|
|
1621
1766
|
# @api public
|
|
1622
|
-
#: (Integer | String | Range[Integer | String] | Array[Integer | String] index, ?width: Float | Integer | nil, ?hidden: bool, ?custom_width: bool, ?outline_level: Integer | nil, ?collapsed: bool, ?style: (Integer | Symbol | String | Hash[Symbol, untyped])?) -> void
|
|
1623
|
-
def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, collapsed: false, style: nil)
|
|
1767
|
+
#: (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
|
|
1768
|
+
def column(index, width: nil, hidden: false, custom_width: false, outline_level: nil, collapsed: false, style: nil, best_fit: false)
|
|
1624
1769
|
raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
|
|
1625
1770
|
|
|
1626
1771
|
sheet if @current_sheet.nil?
|
|
1627
1772
|
|
|
1773
|
+
DslHelpers.check_style_name!(style, @style_name_to_id)
|
|
1628
1774
|
style_id = if style.is_a?(Hash)
|
|
1629
1775
|
inline_name = "__inline_col_#{style.hash}"
|
|
1630
1776
|
style(inline_name, **style) unless @style_name_to_id.key?(inline_name)
|
|
@@ -1642,6 +1788,7 @@ module Xlsxrb
|
|
|
1642
1788
|
existing[:hidden] = hidden if hidden
|
|
1643
1789
|
existing[:outline_level] = outline_level unless outline_level.nil?
|
|
1644
1790
|
existing[:collapsed] = true if collapsed
|
|
1791
|
+
existing[:best_fit] = true if best_fit
|
|
1645
1792
|
if style_id
|
|
1646
1793
|
existing[:style] = style_id
|
|
1647
1794
|
@current_row_writer&.set_column_style(idx, style_id)
|
|
@@ -1649,6 +1796,7 @@ module Xlsxrb
|
|
|
1649
1796
|
else
|
|
1650
1797
|
entry = { index: idx, width: width, hidden: hidden, custom_width: custom_width || !width.nil?, outline_level: outline_level }
|
|
1651
1798
|
entry[:collapsed] = true if collapsed
|
|
1799
|
+
entry[:best_fit] = true if best_fit
|
|
1652
1800
|
if style_id
|
|
1653
1801
|
entry[:style] = style_id
|
|
1654
1802
|
@current_row_writer&.set_column_style(idx, style_id)
|
|
@@ -1657,6 +1805,36 @@ module Xlsxrb
|
|
|
1657
1805
|
end
|
|
1658
1806
|
end
|
|
1659
1807
|
@current_columns.sort_by! { |c| c[:index] }
|
|
1808
|
+
nil
|
|
1809
|
+
end
|
|
1810
|
+
|
|
1811
|
+
# Returns column configurations defined for the active worksheet.
|
|
1812
|
+
#
|
|
1813
|
+
# @return [Array<Elements::Column>]
|
|
1814
|
+
# @api public
|
|
1815
|
+
#: () -> Array[Elements::Column]
|
|
1816
|
+
def columns
|
|
1817
|
+
ensure_sheet_started!
|
|
1818
|
+
@current_columns.map do |c|
|
|
1819
|
+
if c.is_a?(Elements::Column)
|
|
1820
|
+
c
|
|
1821
|
+
else
|
|
1822
|
+
idx = c[:index]
|
|
1823
|
+
style_idx = c[:style] || c[:style_index]
|
|
1824
|
+
unmapped = c.except(:index, :width, :hidden, :custom_width, :outline_level, :style, :style_index, :collapsed, :best_fit)
|
|
1825
|
+
Elements::Column.new(
|
|
1826
|
+
index: idx,
|
|
1827
|
+
width: c[:width],
|
|
1828
|
+
hidden: c[:hidden] ? true : false,
|
|
1829
|
+
custom_width: c[:custom_width] ? true : false,
|
|
1830
|
+
outline_level: c[:outline_level],
|
|
1831
|
+
style_index: style_idx,
|
|
1832
|
+
collapsed: c[:collapsed] ? true : false,
|
|
1833
|
+
best_fit: c[:best_fit] ? true : false,
|
|
1834
|
+
unmapped_data: unmapped
|
|
1835
|
+
)
|
|
1836
|
+
end
|
|
1837
|
+
end
|
|
1660
1838
|
end
|
|
1661
1839
|
|
|
1662
1840
|
# Groups multiple columns together with outline hierarchy.
|
|
@@ -1679,9 +1857,6 @@ module Xlsxrb
|
|
|
1679
1857
|
def group_columns(index, level: 1, collapsed: false, hidden: false, width: nil, style: nil)
|
|
1680
1858
|
column(index, outline_level: level, collapsed: collapsed, hidden: hidden, width: width, style: style)
|
|
1681
1859
|
end
|
|
1682
|
-
alias group_column group_columns
|
|
1683
|
-
alias group_cols group_columns
|
|
1684
|
-
alias group_col group_columns
|
|
1685
1860
|
|
|
1686
1861
|
# Groups multiple rows with outline hierarchy with a block.
|
|
1687
1862
|
#
|
|
@@ -1717,9 +1892,11 @@ module Xlsxrb
|
|
|
1717
1892
|
@current_row_hidden = prev_hidden
|
|
1718
1893
|
end
|
|
1719
1894
|
end
|
|
1720
|
-
alias group_row group_rows
|
|
1721
1895
|
|
|
1722
|
-
# Configures worksheet-level outline and grouping view properties.
|
|
1896
|
+
# Configures or queries worksheet-level outline and grouping view properties.
|
|
1897
|
+
#
|
|
1898
|
+
# When called with no arguments, returns the outline properties Hash.
|
|
1899
|
+
# When called with arguments, updates outline properties and returns nil.
|
|
1723
1900
|
#
|
|
1724
1901
|
# @example Show summary row below detail rows
|
|
1725
1902
|
# sheet.outline_properties(summary_below: true, summary_right: true)
|
|
@@ -1727,47 +1904,64 @@ module Xlsxrb
|
|
|
1727
1904
|
# @param summary_below [Boolean, nil] Flag indicating if summary rows appear below detail rows.
|
|
1728
1905
|
# @param summary_right [Boolean, nil] Flag indicating if summary columns appear to the right of detail columns.
|
|
1729
1906
|
# @param show_outline_symbols [Boolean, nil] Flag indicating whether outline symbols are visible.
|
|
1730
|
-
# @param show_symbols [Boolean, nil] Alias for show_outline_symbols.
|
|
1731
1907
|
# @param apply_styles [Boolean, nil] Flag indicating whether automatic styles apply to outlines.
|
|
1732
1908
|
# @param opts [Hash] Additional options.
|
|
1733
|
-
# @return [Hash]
|
|
1909
|
+
# @return [Hash<Symbol, untyped>, void]
|
|
1734
1910
|
# @api public
|
|
1735
|
-
#: (
|
|
1736
|
-
|
|
1911
|
+
#: () -> Hash[Symbol, untyped]
|
|
1912
|
+
#: (?summary_below: bool?, ?summary_right: bool?, ?show_outline_symbols: bool?, ?apply_styles: bool?, **untyped opts) -> void
|
|
1913
|
+
def outline_properties(summary_below: nil, summary_right: nil, show_outline_symbols: nil, apply_styles: nil, **opts)
|
|
1737
1914
|
sheet if @current_sheet.nil?
|
|
1738
1915
|
|
|
1916
|
+
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? && apply_styles.nil? && opts.empty?
|
|
1917
|
+
|
|
1739
1918
|
props = (@current_sheet_properties[:outline_properties] || {}).dup
|
|
1740
1919
|
props[:summary_below] = summary_below unless summary_below.nil?
|
|
1741
1920
|
props[:summary_right] = summary_right unless summary_right.nil?
|
|
1742
|
-
|
|
1743
|
-
props[:show_outline_symbols] = symbols unless symbols.nil?
|
|
1921
|
+
props[:show_outline_symbols] = show_outline_symbols unless show_outline_symbols.nil?
|
|
1744
1922
|
props[:apply_styles] = apply_styles unless apply_styles.nil?
|
|
1745
1923
|
props.merge!(opts)
|
|
1746
1924
|
@current_sheet_properties[:outline_properties] = props
|
|
1747
1925
|
@current_sheet_properties[:summary_below] = props[:summary_below] unless props[:summary_below].nil?
|
|
1748
1926
|
@current_sheet_properties[:summary_right] = props[:summary_right] unless props[:summary_right].nil?
|
|
1749
|
-
|
|
1927
|
+
nil
|
|
1928
|
+
end
|
|
1929
|
+
|
|
1930
|
+
# Sets worksheet outline and grouping view properties.
|
|
1931
|
+
#
|
|
1932
|
+
# @param opts [Hash] Outline properties.
|
|
1933
|
+
# @return [void]
|
|
1934
|
+
# @api public
|
|
1935
|
+
#: (Hash[Symbol, untyped] opts) -> void
|
|
1936
|
+
def outline_properties=(opts)
|
|
1937
|
+
sheet if @current_sheet.nil?
|
|
1938
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
1939
|
+
outline_properties(**h)
|
|
1940
|
+
nil
|
|
1750
1941
|
end
|
|
1751
|
-
alias outline_pr outline_properties
|
|
1752
1942
|
|
|
1753
1943
|
# Adds a chart to the current worksheet.
|
|
1754
1944
|
#
|
|
1945
|
+
# @param type [Symbol, String, nil] Optional chart type (e.g. :bar, :line).
|
|
1755
1946
|
# @param options [Hash] Chart options.
|
|
1756
1947
|
# @yield [builder]
|
|
1757
1948
|
# @yieldparam builder [Xlsxrb::ChartBuilder]
|
|
1758
1949
|
# @return [void]
|
|
1759
1950
|
# @api public
|
|
1760
|
-
#: (**untyped options) ?{ (ChartBuilder) -> void } -> void
|
|
1761
|
-
def chart(**options)
|
|
1951
|
+
#: (?Symbol | String? type, **untyped options) ?{ (ChartBuilder) -> void } -> void
|
|
1952
|
+
def chart(type = nil, **options)
|
|
1762
1953
|
sheet if @current_sheet.nil?
|
|
1763
1954
|
|
|
1955
|
+
options = options.merge(type: type) if type
|
|
1764
1956
|
if block_given?
|
|
1765
1957
|
builder = ChartBuilder.new
|
|
1958
|
+
builder.type = type if type
|
|
1766
1959
|
yield builder
|
|
1767
1960
|
options = builder.options.merge(options)
|
|
1768
1961
|
end
|
|
1769
1962
|
|
|
1770
1963
|
@current_charts << options
|
|
1964
|
+
nil
|
|
1771
1965
|
end
|
|
1772
1966
|
|
|
1773
1967
|
# Adds a hyperlink on a cell.
|
|
@@ -1799,15 +1993,25 @@ module Xlsxrb
|
|
|
1799
1993
|
@current_hyperlinks << link
|
|
1800
1994
|
end
|
|
1801
1995
|
|
|
1802
|
-
#
|
|
1996
|
+
# Returns the auto-filter range on the active sheet, or nil if none.
|
|
1803
1997
|
#
|
|
1804
|
-
# @
|
|
1805
|
-
# @return [void]
|
|
1998
|
+
# @return [String, nil]
|
|
1806
1999
|
# @api public
|
|
1807
|
-
#: (
|
|
1808
|
-
def auto_filter
|
|
1809
|
-
|
|
1810
|
-
@current_auto_filter
|
|
2000
|
+
#: () -> String?
|
|
2001
|
+
def auto_filter
|
|
2002
|
+
ensure_sheet_started!
|
|
2003
|
+
@current_auto_filter
|
|
2004
|
+
end
|
|
2005
|
+
|
|
2006
|
+
# Sets the auto-filter range for the current worksheet.
|
|
2007
|
+
#
|
|
2008
|
+
# @param range [String, nil] Cell range (e.g. "A1:E100").
|
|
2009
|
+
# @return [String, nil]
|
|
2010
|
+
# @api public
|
|
2011
|
+
#: (String? range) -> String?
|
|
2012
|
+
def auto_filter=(range)
|
|
2013
|
+
ensure_sheet_started!
|
|
2014
|
+
@current_auto_filter = range&.to_s
|
|
1811
2015
|
end
|
|
1812
2016
|
|
|
1813
2017
|
# Sets filter criteria on a column in the auto-filter.
|
|
@@ -1816,34 +2020,67 @@ module Xlsxrb
|
|
|
1816
2020
|
# @param filter [Hash] Filter criteria.
|
|
1817
2021
|
# @return [void]
|
|
1818
2022
|
# @api public
|
|
1819
|
-
|
|
2023
|
+
# Sets filter criteria on an auto-filter column.
|
|
2024
|
+
#
|
|
2025
|
+
# @param col_id [Integer, String, Symbol] 0-based column index relative to auto-filter or column letter ("A", :B).
|
|
2026
|
+
# @param filter [Hash] Filter definition.
|
|
2027
|
+
# @return [void]
|
|
2028
|
+
# @api public
|
|
2029
|
+
#: (Integer | String | Symbol col_id, (Hash[untyped, untyped] | Array[untyped]) filter) -> void
|
|
1820
2030
|
def filter_column(col_id, filter)
|
|
1821
2031
|
sheet if @current_sheet.nil?
|
|
2032
|
+
col_id = Elements::Cell._column_index(col_id) if col_id.is_a?(String) || col_id.is_a?(Symbol)
|
|
1822
2033
|
@current_filter_columns[col_id] = filter
|
|
2034
|
+
nil
|
|
1823
2035
|
end
|
|
1824
2036
|
|
|
1825
|
-
# Configures column sort state on the active sheet.
|
|
2037
|
+
# Configures or queries column sort state on the active sheet.
|
|
2038
|
+
#
|
|
2039
|
+
# When called with no arguments, returns the {Elements::SortState} value object.
|
|
2040
|
+
# When called with arguments, updates sort state and returns nil.
|
|
1826
2041
|
#
|
|
1827
|
-
# @param ref [String] The sorted range.
|
|
1828
|
-
# @param sort_conditions [Array<Hash
|
|
2042
|
+
# @param ref [String, nil] The sorted range.
|
|
2043
|
+
# @param sort_conditions [Array<Hash>, nil] Sort conditions.
|
|
2044
|
+
# @param case_sensitive [Boolean] Whether sorting is case sensitive.
|
|
2045
|
+
# @param sort_method [String, nil] Sort method.
|
|
1829
2046
|
# @param opts [Hash] Additional options.
|
|
2047
|
+
# @return [Elements::SortState, nil, void]
|
|
2048
|
+
# @api public
|
|
2049
|
+
#: () -> Elements::SortState?
|
|
2050
|
+
#: (?String? ref, ?Array[Hash[untyped, untyped]]? sort_conditions, ?case_sensitive: bool, ?sort_method: String?, **untyped opts) -> void
|
|
2051
|
+
def sort_state(ref = nil, sort_conditions = nil, case_sensitive: false, sort_method: nil, **opts)
|
|
2052
|
+
sheet if @current_sheet.nil?
|
|
2053
|
+
if ref.nil? && sort_conditions.nil?
|
|
2054
|
+
return @current_sort_state ? Elements::SortState.new(**@current_sort_state) : nil
|
|
2055
|
+
end
|
|
2056
|
+
|
|
2057
|
+
entry = { ref: ref, sort_conditions: sort_conditions, case_sensitive: case_sensitive }
|
|
2058
|
+
entry[:sort_method] = sort_method if sort_method
|
|
2059
|
+
@current_sort_state = entry.merge(opts)
|
|
2060
|
+
nil
|
|
2061
|
+
end
|
|
2062
|
+
|
|
2063
|
+
# Sets column sort state on the active sheet.
|
|
2064
|
+
#
|
|
2065
|
+
# @param opts [Elements::SortState, Hash, nil] Sort state options.
|
|
1830
2066
|
# @return [void]
|
|
1831
2067
|
# @api public
|
|
1832
|
-
#: (
|
|
1833
|
-
def sort_state(
|
|
2068
|
+
#: (Elements::SortState | Hash[Symbol, untyped] | nil opts) -> void
|
|
2069
|
+
def sort_state=(opts)
|
|
1834
2070
|
sheet if @current_sheet.nil?
|
|
1835
|
-
@current_sort_state =
|
|
2071
|
+
@current_sort_state = opts&.respond_to?(:to_h) ? opts.to_h : opts
|
|
2072
|
+
nil
|
|
1836
2073
|
end
|
|
1837
2074
|
|
|
1838
2075
|
# Adds a data validation rule.
|
|
1839
2076
|
#
|
|
1840
2077
|
# @param sqref [String, nil] Cell range.
|
|
1841
|
-
# @param opts [Hash] Validation options (or coordinate keywords: `columns:`, `rows:`, `except_rows:`, `in:`).
|
|
2078
|
+
# @param opts [Hash] Validation options (or coordinate keywords: `columns:`, `rows:`, `except_rows:`, `list:`, `in:`).
|
|
1842
2079
|
# @yield [data_validation_builder] Optional configuration block.
|
|
1843
2080
|
# @return [void]
|
|
1844
2081
|
# @api public
|
|
1845
2082
|
#: (?String? sqref, **untyped opts) ?{ (DataValidationBuilder) -> void } -> void
|
|
1846
|
-
def
|
|
2083
|
+
def data_validation(sqref = nil, **opts, &)
|
|
1847
2084
|
sheet if @current_sheet.nil?
|
|
1848
2085
|
normalized_list = DslHelpers.normalize_data_validation(sqref, **opts, &)
|
|
1849
2086
|
@current_data_validations.concat(normalized_list)
|
|
@@ -1902,24 +2139,27 @@ module Xlsxrb
|
|
|
1902
2139
|
# @param source_ref [String] Source data range.
|
|
1903
2140
|
# @param row_fields [Array<Integer>] 0-based field indices for rows.
|
|
1904
2141
|
# @param data_fields [Array<Hash>] Data fields.
|
|
1905
|
-
# @param
|
|
1906
|
-
# @param
|
|
2142
|
+
# @param column_fields [Array<Integer>, nil] 0-based field indices for columns.
|
|
2143
|
+
# @param ref [String, nil] Top-left destination cell (default: "E1").
|
|
1907
2144
|
# @param name [String, nil] Pivot table name.
|
|
1908
2145
|
# @param field_names [Array<String>, nil] Override field names.
|
|
1909
|
-
# @param items [Array, nil] Items
|
|
2146
|
+
# @param items [Hash{Integer => Array}, nil] Items of each field, by 0-based field index.
|
|
1910
2147
|
# @param opts [Hash] Additional options.
|
|
1911
2148
|
# @return [void]
|
|
1912
2149
|
# @api public
|
|
1913
|
-
#: (untyped source_ref, row_fields: untyped, data_fields: untyped, ?
|
|
1914
|
-
def pivot_table(source_ref, row_fields:, data_fields:,
|
|
2150
|
+
#: (untyped source_ref, row_fields: untyped, data_fields: untyped, ?column_fields: untyped, ?ref: untyped, ?name: untyped, ?field_names: untyped, ?items: untyped, **untyped opts) -> void
|
|
2151
|
+
def pivot_table(source_ref, row_fields:, data_fields:, column_fields: nil, ref: nil, name: nil, field_names: nil, items: nil, **opts)
|
|
1915
2152
|
sheet if @current_sheet.nil?
|
|
2153
|
+
c_fields = column_fields || []
|
|
2154
|
+
target_ref = ref || "E1"
|
|
1916
2155
|
@current_pivot_tables ||= []
|
|
1917
|
-
|
|
2156
|
+
entry = {
|
|
1918
2157
|
source_ref: source_ref, row_fields: row_fields,
|
|
1919
|
-
data_fields: data_fields,
|
|
1920
|
-
|
|
2158
|
+
data_fields: data_fields, column_fields: c_fields,
|
|
2159
|
+
ref: target_ref, destination: target_ref, name: name,
|
|
1921
2160
|
field_names: field_names, items: items
|
|
1922
|
-
}
|
|
2161
|
+
}.merge(opts)
|
|
2162
|
+
@current_pivot_tables << entry
|
|
1923
2163
|
end
|
|
1924
2164
|
|
|
1925
2165
|
# Adds a comment to a cell.
|
|
@@ -1927,12 +2167,15 @@ module Xlsxrb
|
|
|
1927
2167
|
# @param cell [String, Integer] Cell coordinate (e.g. "A1").
|
|
1928
2168
|
# @param text [String] Comment text.
|
|
1929
2169
|
# @param author [String] Author name.
|
|
2170
|
+
# @param visible [Boolean] Whether the comment is always shown instead of on hover.
|
|
1930
2171
|
# @return [void]
|
|
1931
2172
|
# @api public
|
|
1932
|
-
#: (String | Integer cell, String text, ?author: ::String) -> void
|
|
1933
|
-
def comment(cell, text, author: "Author")
|
|
2173
|
+
#: (String | Integer cell, String text, ?author: ::String, ?visible: bool) -> void
|
|
2174
|
+
def comment(cell, text, author: "Author", visible: false)
|
|
1934
2175
|
sheet if @current_sheet.nil?
|
|
1935
|
-
|
|
2176
|
+
ref_str = cell.to_s
|
|
2177
|
+
@current_comments << { ref: ref_str, text: text, author: author, visible: visible }
|
|
2178
|
+
nil
|
|
1936
2179
|
end
|
|
1937
2180
|
|
|
1938
2181
|
# Adds a threaded comment to a cell.
|
|
@@ -1940,7 +2183,7 @@ module Xlsxrb
|
|
|
1940
2183
|
# @param cell [String, Integer] Cell coordinate (e.g. "A1").
|
|
1941
2184
|
# @param text [String] Comment text.
|
|
1942
2185
|
# @param author [String] Author name.
|
|
1943
|
-
# @param timestamp [String, Time, nil] Optional ISO 8601 timestamp.
|
|
2186
|
+
# @param visible [Boolean] Whether the comment is always shown instead of on hover. # @param timestamp [String, Time, nil] Optional ISO 8601 timestamp.
|
|
1944
2187
|
# @param id [String, nil] Optional GUID for this comment.
|
|
1945
2188
|
# @param parent_id [String, nil] Optional parent comment GUID for replies.
|
|
1946
2189
|
# @param done [Boolean, nil] Optional resolved flag.
|
|
@@ -1951,19 +2194,23 @@ module Xlsxrb
|
|
|
1951
2194
|
#: (String | Integer cell, String text, ?author: untyped, ?timestamp: untyped, ?id: String?, ?parent_id: String?, ?done: bool?, ?user_id: String?, ?provider_id: String?) -> void
|
|
1952
2195
|
def threaded_comment(cell, text, author: "Author", timestamp: nil, id: nil, parent_id: nil, done: false, user_id: nil, provider_id: nil)
|
|
1953
2196
|
sheet if @current_sheet.nil?
|
|
2197
|
+
ref_str = cell.to_s
|
|
1954
2198
|
@current_threaded_comments << {
|
|
1955
|
-
|
|
2199
|
+
ref: ref_str,
|
|
1956
2200
|
text: text,
|
|
1957
2201
|
author: author,
|
|
1958
2202
|
timestamp: timestamp,
|
|
2203
|
+
created_at: timestamp,
|
|
1959
2204
|
id: id,
|
|
1960
2205
|
parent_id: parent_id,
|
|
1961
2206
|
done: done ? true : false,
|
|
2207
|
+
resolved: done ? true : false,
|
|
1962
2208
|
user_id: user_id,
|
|
2209
|
+
author_id: user_id,
|
|
1963
2210
|
provider_id: provider_id
|
|
1964
2211
|
}.compact
|
|
2212
|
+
nil
|
|
1965
2213
|
end
|
|
1966
|
-
alias add_threaded_comment threaded_comment
|
|
1967
2214
|
|
|
1968
2215
|
# Adds a sparkline group.
|
|
1969
2216
|
#
|
|
@@ -1981,101 +2228,170 @@ module Xlsxrb
|
|
|
1981
2228
|
@current_sparkline_groups << group
|
|
1982
2229
|
end
|
|
1983
2230
|
|
|
1984
|
-
#
|
|
1985
|
-
#
|
|
1986
|
-
# @example Add a line sparkline
|
|
1987
|
-
# writer.add_sparkline(location: "F1", range: "A1:E1")
|
|
1988
|
-
#
|
|
1989
|
-
# @example Add a column sparkline with high/low markers
|
|
1990
|
-
# writer.add_sparkline(location: "F2", range: "A2:E2", type: :column, high: true, low: true)
|
|
2231
|
+
# Merges a range of cells into a single cell.
|
|
1991
2232
|
#
|
|
1992
|
-
# @example
|
|
1993
|
-
#
|
|
2233
|
+
# @example
|
|
2234
|
+
# sheet.merge("A1:C1")
|
|
1994
2235
|
#
|
|
1995
|
-
# @param
|
|
1996
|
-
# @param range [String, nil] Data range for the sparkline (e.g. "A1:E1").
|
|
1997
|
-
# @param type [Symbol, String, nil] Sparkline type (:line, :column, :win_loss / :stacked).
|
|
1998
|
-
# @param opts [Hash] Additional sparkline options.
|
|
2236
|
+
# @param range [String] Cell range (e.g. "A1:B2").
|
|
1999
2237
|
# @return [void]
|
|
2000
2238
|
# @api public
|
|
2001
|
-
#: (
|
|
2002
|
-
def
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
raise ArgumentError, "Missing required range: parameter for sparkline" unless rng
|
|
2007
|
-
|
|
2008
|
-
mapped_type = case type&.to_s
|
|
2009
|
-
when "win_loss" then "stacked"
|
|
2010
|
-
when nil, "" then nil
|
|
2011
|
-
else type.to_s
|
|
2012
|
-
end
|
|
2013
|
-
sparkline_group(sparklines: [{ data_ref: rng.to_s, location_ref: loc.to_s }], type: mapped_type, **opts)
|
|
2239
|
+
#: (String range) -> void
|
|
2240
|
+
def merge(range)
|
|
2241
|
+
sheet if @current_sheet.nil?
|
|
2242
|
+
canonical = DslHelpers.normalize_merge_range(range, strict_excel_mode: @strict_excel_mode)
|
|
2243
|
+
@current_merge_cells << canonical unless @current_merge_cells.include?(canonical)
|
|
2014
2244
|
end
|
|
2015
2245
|
|
|
2016
|
-
#
|
|
2246
|
+
# Configures or queries freeze panes (<pane state="frozen">).
|
|
2017
2247
|
#
|
|
2018
|
-
#
|
|
2019
|
-
#
|
|
2020
|
-
#
|
|
2021
|
-
# @param
|
|
2022
|
-
# @param
|
|
2023
|
-
# @param
|
|
2024
|
-
# @
|
|
2248
|
+
# When called with no arguments, returns the {Elements::FreezePane} value object or nil.
|
|
2249
|
+
# When called with arguments, configures the freeze pane and returns nil.
|
|
2250
|
+
#
|
|
2251
|
+
# @param row [Integer, nil] Number of rows to freeze.
|
|
2252
|
+
# @param column [Integer, String, nil] Number of columns to freeze.
|
|
2253
|
+
# @param top_left_cell [String, nil] Top-left cell reference in bottom-right pane.
|
|
2254
|
+
# @param active_pane [String, Symbol, nil] Active pane identifier.
|
|
2255
|
+
# @return [Elements::FreezePane, nil, void]
|
|
2025
2256
|
# @api public
|
|
2026
|
-
#: (
|
|
2027
|
-
|
|
2257
|
+
#: () -> Elements::FreezePane?
|
|
2258
|
+
#: (?row: Integer | nil, ?column: (Integer | String)?, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
2259
|
+
def freeze_pane(row: nil, column: nil, top_left_cell: nil, active_pane: nil)
|
|
2028
2260
|
sheet if @current_sheet.nil?
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2261
|
+
if row.nil? && column.nil? && top_left_cell.nil? && active_pane.nil?
|
|
2262
|
+
return @current_freeze_pane ? Elements::FreezePane.new(**@current_freeze_pane) : nil
|
|
2263
|
+
end
|
|
2264
|
+
|
|
2265
|
+
col_val = column ? Elements::Cell._column_index(column) : 0
|
|
2266
|
+
entry = { row: row || 0, column: col_val }
|
|
2267
|
+
entry[:top_left_cell] = top_left_cell if top_left_cell
|
|
2268
|
+
entry[:active_pane] = active_pane.to_s if active_pane
|
|
2269
|
+
@current_freeze_pane = entry
|
|
2270
|
+
nil
|
|
2036
2271
|
end
|
|
2037
2272
|
|
|
2038
|
-
#
|
|
2273
|
+
# Sets or clears freeze pane configuration.
|
|
2039
2274
|
#
|
|
2040
|
-
# @param
|
|
2041
|
-
# @param col [Integer, String] Number of columns to freeze.
|
|
2275
|
+
# @param opts [Elements::FreezePane, Hash, nil] Freeze pane options.
|
|
2042
2276
|
# @return [void]
|
|
2043
2277
|
# @api public
|
|
2044
|
-
#: (
|
|
2045
|
-
def freeze_pane(
|
|
2046
|
-
col = Elements::Cell.column_index(col)
|
|
2278
|
+
#: (Elements::FreezePane | Hash[Symbol, untyped] | nil opts) -> void
|
|
2279
|
+
def freeze_pane=(opts)
|
|
2047
2280
|
sheet if @current_sheet.nil?
|
|
2048
|
-
|
|
2281
|
+
if opts.nil?
|
|
2282
|
+
@current_freeze_pane = nil
|
|
2283
|
+
else
|
|
2284
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
2285
|
+
c = h[:column] || h[:col]
|
|
2286
|
+
c = Elements::Cell._column_index(c) if c
|
|
2287
|
+
entry = { row: h[:row] || 0, column: c || 0 }
|
|
2288
|
+
entry[:top_left_cell] = h[:top_left_cell] if h[:top_left_cell]
|
|
2289
|
+
entry[:active_pane] = h[:active_pane].to_s if h[:active_pane]
|
|
2290
|
+
@current_freeze_pane = entry
|
|
2291
|
+
end
|
|
2292
|
+
nil
|
|
2049
2293
|
end
|
|
2050
2294
|
|
|
2051
|
-
# Splits window panes without freezing.
|
|
2295
|
+
# Splits window panes without freezing or queries split pane settings (<pane>).
|
|
2296
|
+
#
|
|
2297
|
+
# When called with no arguments, returns the {Elements::SplitPane} value object or nil.
|
|
2298
|
+
# When called with arguments, configures the split pane and returns nil.
|
|
2052
2299
|
#
|
|
2053
|
-
# @param x_split [Integer] Horizontal split in points.
|
|
2054
|
-
# @param y_split [Integer] Vertical split in points.
|
|
2300
|
+
# @param x_split [Integer, nil] Horizontal split in points.
|
|
2301
|
+
# @param y_split [Integer, nil] Vertical split in points.
|
|
2055
2302
|
# @param top_left_cell [String, nil] Top-left cell reference in bottom-right pane.
|
|
2303
|
+
# @param active_pane [String, Symbol, nil] Active pane identifier.
|
|
2304
|
+
# @param state [String, Symbol, nil] Split state.
|
|
2305
|
+
# @return [Elements::SplitPane, nil, void]
|
|
2306
|
+
# @api public
|
|
2307
|
+
#: () -> Elements::SplitPane?
|
|
2308
|
+
#: (?x_split: Integer | nil, ?y_split: Integer | nil, ?top_left_cell: String?, ?active_pane: (String | Symbol)?) -> void
|
|
2309
|
+
def split_pane(x_split: nil, y_split: nil, top_left_cell: nil, active_pane: nil)
|
|
2310
|
+
sheet if @current_sheet.nil?
|
|
2311
|
+
if x_split.nil? && y_split.nil? && top_left_cell.nil? && active_pane.nil?
|
|
2312
|
+
return @current_split_pane ? Elements::SplitPane.new(**@current_split_pane) : nil
|
|
2313
|
+
end
|
|
2314
|
+
|
|
2315
|
+
entry = { x_split: x_split || 0, y_split: y_split || 0, top_left_cell: top_left_cell }
|
|
2316
|
+
entry[:active_pane] = active_pane.to_s if active_pane
|
|
2317
|
+
@current_split_pane = entry
|
|
2318
|
+
nil
|
|
2319
|
+
end
|
|
2320
|
+
|
|
2321
|
+
# Sets or clears split pane configuration.
|
|
2322
|
+
#
|
|
2323
|
+
# @param opts [Elements::SplitPane, Hash, nil] Split pane options.
|
|
2056
2324
|
# @return [void]
|
|
2057
2325
|
# @api public
|
|
2058
|
-
#: (
|
|
2059
|
-
def split_pane(
|
|
2326
|
+
#: (Elements::SplitPane | Hash[Symbol, untyped] | nil opts) -> void
|
|
2327
|
+
def split_pane=(opts)
|
|
2060
2328
|
sheet if @current_sheet.nil?
|
|
2061
|
-
|
|
2329
|
+
if opts.nil?
|
|
2330
|
+
@current_split_pane = nil
|
|
2331
|
+
else
|
|
2332
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
2333
|
+
entry = { x_split: h[:x_split] || 0, y_split: h[:y_split] || 0, top_left_cell: h[:top_left_cell] }
|
|
2334
|
+
entry[:active_pane] = h[:active_pane].to_s if h[:active_pane]
|
|
2335
|
+
@current_split_pane = entry
|
|
2336
|
+
end
|
|
2337
|
+
nil
|
|
2062
2338
|
end
|
|
2063
2339
|
|
|
2064
|
-
# Sets the active cell selection on the current sheet.
|
|
2340
|
+
# Sets or queries the active cell selection on the current sheet (<selection>).
|
|
2065
2341
|
#
|
|
2066
|
-
#
|
|
2342
|
+
# When called with no arguments, returns the selection ({Elements::Selection}, Array, or nil).
|
|
2343
|
+
# When called with arguments, updates the selection and returns nil.
|
|
2344
|
+
#
|
|
2345
|
+
# @param active_cell [String, nil] Active cell reference (e.g. "A1") or range (e.g. "A1:D10").
|
|
2067
2346
|
# @param sqref [String, nil] Selection range.
|
|
2068
2347
|
# @param pane [String, Symbol, nil] Target pane.
|
|
2348
|
+
# @return [Elements::Selection, Array<Elements::Selection>, nil, void]
|
|
2349
|
+
# @api public
|
|
2350
|
+
#: () -> (Elements::Selection | Array[Elements::Selection])?
|
|
2351
|
+
#: (?String? active_cell, ?sqref: String?, ?pane: (String | Symbol)?) -> void
|
|
2352
|
+
def selection(active_cell = nil, sqref: nil, pane: nil)
|
|
2353
|
+
sheet if @current_sheet.nil?
|
|
2354
|
+
if active_cell.nil? && sqref.nil? && pane.nil?
|
|
2355
|
+
return nil if @current_selection.nil?
|
|
2356
|
+
return @current_selection.map { |s| Elements::Selection.new(**s) } if @current_selection.is_a?(Array)
|
|
2357
|
+
|
|
2358
|
+
return Elements::Selection.new(**@current_selection)
|
|
2359
|
+
end
|
|
2360
|
+
|
|
2361
|
+
if sqref.nil? && active_cell.is_a?(String) && active_cell.include?(":")
|
|
2362
|
+
sqref = active_cell
|
|
2363
|
+
active_cell = sqref.split(":").first
|
|
2364
|
+
else
|
|
2365
|
+
sqref ||= active_cell
|
|
2366
|
+
end
|
|
2367
|
+
sel = { active_cell: active_cell, sqref: sqref }
|
|
2368
|
+
sel[:pane] = pane if pane
|
|
2369
|
+
@current_selection = sel
|
|
2370
|
+
nil
|
|
2371
|
+
end
|
|
2372
|
+
|
|
2373
|
+
# Sets or clears the selection configuration.
|
|
2374
|
+
#
|
|
2375
|
+
# @param opts [Elements::Selection, Array<Elements::Selection, Hash>, Hash, nil]
|
|
2069
2376
|
# @return [void]
|
|
2070
2377
|
# @api public
|
|
2071
|
-
#: (
|
|
2072
|
-
def
|
|
2378
|
+
#: (Elements::Selection | Array[Elements::Selection | Hash[Symbol, untyped]] | Hash[Symbol, untyped] | nil opts) -> void
|
|
2379
|
+
def selection=(opts)
|
|
2073
2380
|
sheet if @current_sheet.nil?
|
|
2074
|
-
@current_selection =
|
|
2075
|
-
|
|
2381
|
+
@current_selection = if opts.nil?
|
|
2382
|
+
nil
|
|
2383
|
+
elsif opts.is_a?(Array)
|
|
2384
|
+
opts.map { |o| o.respond_to?(:to_h) ? o.to_h : o }
|
|
2385
|
+
else
|
|
2386
|
+
opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
2387
|
+
end
|
|
2388
|
+
nil
|
|
2076
2389
|
end
|
|
2077
2390
|
|
|
2078
|
-
#
|
|
2391
|
+
# Configures or queries page margins in inches for printing (<pageMargins>).
|
|
2392
|
+
#
|
|
2393
|
+
# When called with no arguments, returns the {Elements::PageMargins} value object or nil.
|
|
2394
|
+
# When called with arguments, configures page margins and returns nil.
|
|
2079
2395
|
#
|
|
2080
2396
|
# @param left [Float, nil] Left margin.
|
|
2081
2397
|
# @param right [Float, nil] Right margin.
|
|
@@ -2083,103 +2399,219 @@ module Xlsxrb
|
|
|
2083
2399
|
# @param bottom [Float, nil] Bottom margin.
|
|
2084
2400
|
# @param header [Float, nil] Header margin.
|
|
2085
2401
|
# @param footer [Float, nil] Footer margin.
|
|
2086
|
-
# @return [void]
|
|
2402
|
+
# @return [Elements::PageMargins, nil, void]
|
|
2087
2403
|
# @api public
|
|
2404
|
+
#: () -> Elements::PageMargins?
|
|
2088
2405
|
#: (?left: Float?, ?right: Float?, ?top: Float?, ?bottom: Float?, ?header: Float?, ?footer: Float?) -> void
|
|
2089
2406
|
def page_margins(left: nil, right: nil, top: nil, bottom: nil, header: nil, footer: nil)
|
|
2090
2407
|
sheet if @current_sheet.nil?
|
|
2408
|
+
if left.nil? && right.nil? && top.nil? && bottom.nil? && header.nil? && footer.nil?
|
|
2409
|
+
return @current_page_margins ? Elements::PageMargins.new(**@current_page_margins) : nil
|
|
2410
|
+
end
|
|
2411
|
+
|
|
2091
2412
|
@current_page_margins = DslHelpers.normalize_page_margins(
|
|
2092
2413
|
left: left, right: right, top: top, bottom: bottom, header: header, footer: footer
|
|
2093
2414
|
)
|
|
2415
|
+
nil
|
|
2094
2416
|
end
|
|
2095
2417
|
|
|
2096
|
-
# Sets page
|
|
2418
|
+
# Sets or clears page margins configuration.
|
|
2097
2419
|
#
|
|
2098
|
-
# @param opts [Hash
|
|
2420
|
+
# @param opts [Hash, Elements::PageMargins, nil]
|
|
2099
2421
|
# @return [void]
|
|
2100
2422
|
# @api public
|
|
2423
|
+
#: (Hash[Symbol, untyped] | Elements::PageMargins | nil opts) -> void
|
|
2424
|
+
def page_margins=(opts)
|
|
2425
|
+
sheet if @current_sheet.nil?
|
|
2426
|
+
if opts.nil?
|
|
2427
|
+
@current_page_margins = nil
|
|
2428
|
+
else
|
|
2429
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
2430
|
+
@current_page_margins = DslHelpers.normalize_page_margins(**h)
|
|
2431
|
+
end
|
|
2432
|
+
nil
|
|
2433
|
+
end
|
|
2434
|
+
|
|
2435
|
+
# Configures or queries page setup configuration (<pageSetup>).
|
|
2436
|
+
#
|
|
2437
|
+
# When called with no arguments, returns the {Elements::PageSetup} value object.
|
|
2438
|
+
# When called with keyword arguments, updates page setup and returns nil.
|
|
2439
|
+
#
|
|
2440
|
+
# @param opts [Hash] Page setup options (e.g. orientation: :landscape).
|
|
2441
|
+
# @return [Elements::PageSetup, void]
|
|
2442
|
+
# @api public
|
|
2443
|
+
#: () -> Elements::PageSetup
|
|
2101
2444
|
#: (**untyped opts) -> void
|
|
2102
2445
|
def page_setup(**opts)
|
|
2103
2446
|
sheet if @current_sheet.nil?
|
|
2447
|
+
return Elements::PageSetup.new(**@current_page_setup) if opts.empty?
|
|
2448
|
+
|
|
2104
2449
|
@current_page_setup.merge!(opts)
|
|
2105
|
-
|
|
2450
|
+
@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)
|
|
2451
|
+
nil
|
|
2452
|
+
end
|
|
2106
2453
|
|
|
2107
|
-
|
|
2454
|
+
# Sets page setup configuration.
|
|
2455
|
+
#
|
|
2456
|
+
# @param opts [Hash, Elements::PageSetup]
|
|
2457
|
+
# @return [void]
|
|
2458
|
+
# @api public
|
|
2459
|
+
#: (Hash[Symbol, untyped] | Elements::PageSetup opts) -> void
|
|
2460
|
+
def page_setup=(opts)
|
|
2461
|
+
sheet if @current_sheet.nil?
|
|
2462
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2463
|
+
@current_page_setup = h.transform_keys(&:to_sym)
|
|
2464
|
+
nil
|
|
2108
2465
|
end
|
|
2109
2466
|
|
|
2110
|
-
# Configures headers and footers for printing.
|
|
2467
|
+
# Configures or queries headers and footers for printing (<headerFooter>).
|
|
2468
|
+
#
|
|
2469
|
+
# When called with no arguments, returns the {Elements::HeaderFooter} value object.
|
|
2470
|
+
# When called with keyword arguments, updates headers and footers and returns nil.
|
|
2111
2471
|
#
|
|
2112
2472
|
# @param opts [Hash] Header/footer options.
|
|
2113
|
-
# @return [void]
|
|
2473
|
+
# @return [Elements::HeaderFooter, void]
|
|
2114
2474
|
# @api public
|
|
2475
|
+
#: () -> Elements::HeaderFooter
|
|
2115
2476
|
#: (**untyped opts) -> void
|
|
2116
2477
|
def header_footer(**opts)
|
|
2117
2478
|
sheet if @current_sheet.nil?
|
|
2479
|
+
return Elements::HeaderFooter.new(**@current_header_footer) if opts.empty?
|
|
2480
|
+
|
|
2118
2481
|
@current_header_footer.merge!(opts)
|
|
2482
|
+
nil
|
|
2119
2483
|
end
|
|
2120
2484
|
|
|
2121
|
-
# Sets
|
|
2485
|
+
# Sets header and footer configuration.
|
|
2122
2486
|
#
|
|
2123
|
-
# @param
|
|
2124
|
-
# @param value [Object] Option value.
|
|
2487
|
+
# @param opts [Hash, Elements::HeaderFooter]
|
|
2125
2488
|
# @return [void]
|
|
2126
2489
|
# @api public
|
|
2127
|
-
#: (Symbol
|
|
2128
|
-
def
|
|
2490
|
+
#: (Hash[Symbol, untyped] | Elements::HeaderFooter opts) -> void
|
|
2491
|
+
def header_footer=(opts)
|
|
2129
2492
|
sheet if @current_sheet.nil?
|
|
2130
|
-
|
|
2493
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2494
|
+
@current_header_footer = h.transform_keys(&:to_sym)
|
|
2495
|
+
nil
|
|
2131
2496
|
end
|
|
2132
2497
|
|
|
2133
|
-
#
|
|
2498
|
+
# Configures or queries print options (<printOptions>).
|
|
2134
2499
|
#
|
|
2135
|
-
#
|
|
2500
|
+
# When called with no arguments, returns the {Elements::PrintOptions} value object.
|
|
2501
|
+
# When called with keyword options, configures print options and returns nil.
|
|
2502
|
+
#
|
|
2503
|
+
# @param opts [Hash] Additional print options.
|
|
2504
|
+
# @return [Elements::PrintOptions, void]
|
|
2505
|
+
# @api public
|
|
2506
|
+
#: () -> Elements::PrintOptions
|
|
2507
|
+
#: (**untyped opts) -> void
|
|
2508
|
+
def print_options(**opts)
|
|
2509
|
+
sheet if @current_sheet.nil?
|
|
2510
|
+
return Elements::PrintOptions.new(**@current_print_options) if opts.empty?
|
|
2511
|
+
|
|
2512
|
+
opts.each { |k, v| @current_print_options[k.to_sym] = v }
|
|
2513
|
+
nil
|
|
2514
|
+
end
|
|
2515
|
+
|
|
2516
|
+
# Replaces print options with the given hash or {Elements::PrintOptions} object.
|
|
2517
|
+
#
|
|
2518
|
+
# @param opts [Hash, Elements::PrintOptions]
|
|
2136
2519
|
# @return [void]
|
|
2137
2520
|
# @api public
|
|
2521
|
+
#: (Hash[Symbol, untyped] | Elements::PrintOptions opts) -> void
|
|
2522
|
+
def print_options=(opts)
|
|
2523
|
+
sheet if @current_sheet.nil?
|
|
2524
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2525
|
+
@current_print_options = h.transform_keys(&:to_sym)
|
|
2526
|
+
nil
|
|
2527
|
+
end
|
|
2528
|
+
|
|
2529
|
+
# Sets or queries sheet-level protection with optional password hashing (<sheetProtection>).
|
|
2530
|
+
#
|
|
2531
|
+
# When called with no arguments, returns the {Elements::SheetProtection} value object or nil.
|
|
2532
|
+
# When called with keyword arguments, sets sheet protection and returns nil.
|
|
2533
|
+
#
|
|
2534
|
+
# @param opts [Hash] Protection options.
|
|
2535
|
+
# @return [Elements::SheetProtection, nil, void]
|
|
2536
|
+
# @api public
|
|
2537
|
+
#: () -> Elements::SheetProtection?
|
|
2138
2538
|
#: (**untyped opts) -> void
|
|
2139
|
-
def
|
|
2539
|
+
def sheet_protection(**opts)
|
|
2140
2540
|
sheet if @current_sheet.nil?
|
|
2141
|
-
|
|
2541
|
+
if opts.empty?
|
|
2542
|
+
@current_sheet_protection ? Elements::SheetProtection.new(**@current_sheet_protection) : nil
|
|
2543
|
+
else
|
|
2544
|
+
@current_sheet_protection = DslHelpers.normalize_protection_options(opts)
|
|
2545
|
+
nil
|
|
2546
|
+
end
|
|
2547
|
+
end
|
|
2548
|
+
|
|
2549
|
+
# Sets or clears sheet protection configuration.
|
|
2550
|
+
#
|
|
2551
|
+
# @param opts [Elements::SheetProtection, Hash, Boolean, nil]
|
|
2552
|
+
# @return [void]
|
|
2553
|
+
# @api public
|
|
2554
|
+
#: (Elements::SheetProtection | Hash[Symbol, untyped] | bool | nil opts) -> void
|
|
2555
|
+
def sheet_protection=(opts)
|
|
2556
|
+
sheet if @current_sheet.nil?
|
|
2557
|
+
if opts.nil? || opts == false
|
|
2558
|
+
@current_sheet_protection = nil
|
|
2559
|
+
elsif opts == true
|
|
2560
|
+
@current_sheet_protection = DslHelpers.normalize_protection_options(sheet: true)
|
|
2561
|
+
else
|
|
2562
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
2563
|
+
@current_sheet_protection = DslHelpers.normalize_protection_options(h)
|
|
2564
|
+
end
|
|
2565
|
+
nil
|
|
2142
2566
|
end
|
|
2143
2567
|
|
|
2144
2568
|
# Inserts an embedded image into the active sheet.
|
|
2145
2569
|
#
|
|
2146
2570
|
# @param file_data [String] Binary image data.
|
|
2147
2571
|
# @param ext [String] File extension ("png", "jpeg", etc.).
|
|
2148
|
-
# @param
|
|
2572
|
+
# @param from_column [Integer, nil] Top-left starting column.
|
|
2149
2573
|
# @param from_row [Integer] Top-left starting row.
|
|
2150
|
-
# @param
|
|
2574
|
+
# @param to_column [Integer, nil] Bottom-right ending column.
|
|
2151
2575
|
# @param to_row [Integer] Bottom-right ending row.
|
|
2152
2576
|
# @param opts [Hash] Additional options.
|
|
2153
2577
|
# @return [void]
|
|
2154
2578
|
# @api public
|
|
2155
|
-
#: (String file_data, ?ext: ::String, ?
|
|
2156
|
-
def image(file_data, ext: "png",
|
|
2579
|
+
#: (String file_data, ?ext: ::String, ?from_column: ::Integer?, ?from_row: ::Integer, ?to_column: ::Integer?, ?to_row: ::Integer, **untyped opts) -> void
|
|
2580
|
+
def image(file_data, ext: "png", from_column: nil, from_row: 0, to_column: nil, to_row: 10, **opts)
|
|
2581
|
+
fc = from_column || 0
|
|
2582
|
+
tc = to_column || 5
|
|
2157
2583
|
sheet if @current_sheet.nil?
|
|
2158
|
-
img = { file_data: file_data, ext: ext,
|
|
2584
|
+
img = { file_data: file_data, ext: ext, from_column: fc, from_row: from_row, to_column: tc, to_row: to_row }
|
|
2159
2585
|
img.merge!(opts)
|
|
2160
2586
|
@current_images << img
|
|
2161
2587
|
end
|
|
2162
2588
|
|
|
2163
|
-
#
|
|
2164
|
-
#
|
|
2165
|
-
# @example Set background image from binary data
|
|
2166
|
-
# sheet.background_image(png_bytes, ext: "png")
|
|
2167
|
-
#
|
|
2168
|
-
# @example Set background image from file path
|
|
2169
|
-
# sheet.background_image("path/to/background.png")
|
|
2589
|
+
# Worksheet background image (<picture>).
|
|
2170
2590
|
#
|
|
2171
|
-
# @
|
|
2172
|
-
# @param ext [String, nil] Image extension ("png", "jpeg", "jpg", "gif", etc.).
|
|
2173
|
-
# @param opts [Hash] Additional image options.
|
|
2174
|
-
# @return [Hash, nil]
|
|
2591
|
+
# @return [Elements::BackgroundImage, nil]
|
|
2175
2592
|
# @api public
|
|
2176
|
-
#: (
|
|
2177
|
-
def background_image
|
|
2178
|
-
|
|
2593
|
+
#: () -> Elements::BackgroundImage?
|
|
2594
|
+
def background_image
|
|
2595
|
+
sheet if @current_sheet.nil?
|
|
2596
|
+
return nil unless @current_background_image
|
|
2179
2597
|
|
|
2598
|
+
@current_background_image.is_a?(Elements::BackgroundImage) ? @current_background_image : Elements::BackgroundImage.new(**@current_background_image)
|
|
2599
|
+
end
|
|
2600
|
+
|
|
2601
|
+
# Sets the worksheet background image (<picture>).
|
|
2602
|
+
#
|
|
2603
|
+
# @param val [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
|
|
2604
|
+
# @return [untyped]
|
|
2605
|
+
# @api public
|
|
2606
|
+
#: (untyped val) -> untyped
|
|
2607
|
+
def background_image=(val)
|
|
2180
2608
|
sheet if @current_sheet.nil?
|
|
2609
|
+
if val.nil?
|
|
2610
|
+
@current_background_image = nil
|
|
2611
|
+
return
|
|
2612
|
+
end
|
|
2181
2613
|
|
|
2182
|
-
data =
|
|
2614
|
+
data = val
|
|
2183
2615
|
inferred_ext = nil
|
|
2184
2616
|
if data.is_a?(String) && !data.include?("\x00") && File.file?(data)
|
|
2185
2617
|
inferred_ext = File.extname(data).delete_prefix(".").downcase
|
|
@@ -2192,7 +2624,7 @@ module Xlsxrb
|
|
|
2192
2624
|
data = data.data
|
|
2193
2625
|
end
|
|
2194
2626
|
|
|
2195
|
-
final_ext = (
|
|
2627
|
+
final_ext = (inferred_ext || (val.is_a?(Hash) ? val[:ext] : nil) || "png").to_s.delete_prefix(".").downcase
|
|
2196
2628
|
mime = case final_ext
|
|
2197
2629
|
when "png" then "image/png"
|
|
2198
2630
|
when "jpg", "jpeg" then "image/jpeg"
|
|
@@ -2203,163 +2635,211 @@ module Xlsxrb
|
|
|
2203
2635
|
else "application/octet-stream"
|
|
2204
2636
|
end
|
|
2205
2637
|
|
|
2638
|
+
opts = val.is_a?(Hash) ? val : {}
|
|
2206
2639
|
@current_background_image = {
|
|
2207
2640
|
data: data&.b,
|
|
2208
2641
|
file_data: data&.b,
|
|
2642
|
+
extension: final_ext,
|
|
2209
2643
|
ext: final_ext,
|
|
2644
|
+
path: "background.#{final_ext}",
|
|
2210
2645
|
filename: "background.#{final_ext}",
|
|
2211
2646
|
content_type: mime
|
|
2212
2647
|
}.merge(opts).freeze
|
|
2648
|
+
val
|
|
2213
2649
|
end
|
|
2214
|
-
alias background_picture background_image
|
|
2215
|
-
alias picture background_image
|
|
2216
|
-
|
|
2217
|
-
def background_image=(val)
|
|
2218
|
-
background_image(val)
|
|
2219
|
-
end
|
|
2220
|
-
alias background_picture= background_image=
|
|
2221
|
-
alias picture= background_image=
|
|
2222
2650
|
|
|
2223
2651
|
# Inserts a drawing shape.
|
|
2224
2652
|
#
|
|
2225
2653
|
# @param preset [String] Preset shape name.
|
|
2226
2654
|
# @param text [String, nil] Label text.
|
|
2227
|
-
# @param
|
|
2655
|
+
# @param from_column [Integer, nil] Top-left column.
|
|
2228
2656
|
# @param from_row [Integer] Top-left row.
|
|
2229
|
-
# @param
|
|
2657
|
+
# @param to_column [Integer, nil] Bottom-right column.
|
|
2230
2658
|
# @param to_row [Integer] Bottom-right row.
|
|
2231
2659
|
# @param opts [Hash] Additional options.
|
|
2232
2660
|
# @return [void]
|
|
2233
2661
|
# @api public
|
|
2234
2662
|
#: (**untyped opts) -> void
|
|
2235
|
-
def shape(preset: "rect", text: nil,
|
|
2663
|
+
def shape(preset: "rect", text: nil, from_column: nil, from_row: 0, to_column: nil, to_row: 5, **opts)
|
|
2664
|
+
fc = from_column || 0
|
|
2665
|
+
tc = to_column || 5
|
|
2236
2666
|
sheet if @current_sheet.nil?
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
@current_shapes <<
|
|
2667
|
+
shape_data = { preset: preset, text: text, from_column: fc, from_row: from_row, to_column: tc, to_row: to_row }
|
|
2668
|
+
shape_data[:name] = opts.delete(:name) || "Shape #{@current_shapes.size + 1}"
|
|
2669
|
+
shape_data.merge!(opts)
|
|
2670
|
+
@current_shapes << shape_data
|
|
2241
2671
|
end
|
|
2242
2672
|
|
|
2243
|
-
# Gets
|
|
2673
|
+
# Gets the sheet visibility state (:visible, :hidden, or :very_hidden).
|
|
2244
2674
|
#
|
|
2245
|
-
# @param new_state [Symbol, nil] The new state.
|
|
2246
2675
|
# @return [Symbol]
|
|
2247
2676
|
# @api public
|
|
2248
|
-
#: (
|
|
2249
|
-
def state
|
|
2677
|
+
#: () -> Symbol
|
|
2678
|
+
def state
|
|
2250
2679
|
sheet if @current_sheet.nil?
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2680
|
+
@current_sheet_state || :visible
|
|
2681
|
+
end
|
|
2682
|
+
|
|
2683
|
+
# Sets the sheet visibility state (:visible, :hidden, or :very_hidden).
|
|
2684
|
+
#
|
|
2685
|
+
# @param new_state [Symbol, String] The new state.
|
|
2686
|
+
# @return [Symbol]
|
|
2687
|
+
# @api public
|
|
2688
|
+
#: (Symbol | String new_state) -> Symbol
|
|
2689
|
+
def state=(new_state)
|
|
2690
|
+
sheet if @current_sheet.nil?
|
|
2691
|
+
sheet_properties(state: new_state)
|
|
2692
|
+
@current_sheet_state
|
|
2693
|
+
end
|
|
2694
|
+
|
|
2695
|
+
# Gets the tab color of the current worksheet.
|
|
2696
|
+
#
|
|
2697
|
+
# @return [String, Hash, nil]
|
|
2698
|
+
# @api public
|
|
2699
|
+
#: () -> (String | Hash[Symbol, untyped] | nil)
|
|
2700
|
+
def tab_color
|
|
2701
|
+
sheet if @current_sheet.nil?
|
|
2702
|
+
@current_sheet_properties[:tab_color]
|
|
2257
2703
|
end
|
|
2258
2704
|
|
|
2259
|
-
#
|
|
2705
|
+
# Sets the tab color of the current worksheet.
|
|
2260
2706
|
#
|
|
2261
2707
|
# @param spec [String, Hash, Symbol, nil] Tab color hex string or hash options.
|
|
2262
|
-
# @param opts [Hash] Color keyword arguments (e.g. theme: 1, tint: 0.5).
|
|
2263
2708
|
# @return [String, Hash, nil]
|
|
2264
2709
|
# @api public
|
|
2265
|
-
#: (
|
|
2266
|
-
def tab_color(spec
|
|
2710
|
+
#: (String | Symbol | Hash[Symbol, untyped] | nil spec) -> (String | Hash[Symbol, untyped] | nil)
|
|
2711
|
+
def tab_color=(spec)
|
|
2267
2712
|
sheet if @current_sheet.nil?
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2713
|
+
@current_sheet_properties[:tab_color] = spec
|
|
2714
|
+
end
|
|
2715
|
+
|
|
2716
|
+
# Configures or queries sheet properties (<sheetPr>).
|
|
2717
|
+
#
|
|
2718
|
+
# When called with no arguments, returns the {Elements::SheetProperties} value object.
|
|
2719
|
+
# When called with keyword options, configures properties and returns nil.
|
|
2720
|
+
#
|
|
2721
|
+
# @param opts [Hash] Additional sheet properties.
|
|
2722
|
+
# @return [Elements::SheetProperties, void]
|
|
2723
|
+
# @api public
|
|
2724
|
+
#: () -> Elements::SheetProperties
|
|
2725
|
+
#: (**untyped opts) -> void
|
|
2726
|
+
def sheet_properties(**opts)
|
|
2727
|
+
sheet if @current_sheet.nil?
|
|
2728
|
+
return Elements::SheetProperties.new(**@current_sheet_properties) if opts.empty?
|
|
2729
|
+
|
|
2730
|
+
opts.each do |k, v|
|
|
2731
|
+
sym = k.to_sym
|
|
2732
|
+
if sym == :state
|
|
2733
|
+
val = v.to_sym
|
|
2734
|
+
raise ArgumentError, "Invalid sheet state ':#{val}'. Allowed states are :visible, :hidden, :very_hidden" unless VALID_SHEET_STATES.include?(val)
|
|
2735
|
+
|
|
2736
|
+
@current_sheet_state = val
|
|
2737
|
+
elsif sym == :hidden
|
|
2738
|
+
@current_sheet_state = v ? :hidden : :visible
|
|
2739
|
+
else
|
|
2740
|
+
@current_sheet_properties[sym] = v
|
|
2741
|
+
end
|
|
2277
2742
|
end
|
|
2743
|
+
nil
|
|
2278
2744
|
end
|
|
2279
|
-
alias tab_color= tab_color
|
|
2280
2745
|
|
|
2281
|
-
#
|
|
2746
|
+
# Replaces worksheet properties with the given hash or {Elements::SheetProperties} object.
|
|
2282
2747
|
#
|
|
2283
|
-
# @param
|
|
2284
|
-
# @param value [Object] Property value.
|
|
2748
|
+
# @param opts [Hash, Elements::SheetProperties]
|
|
2285
2749
|
# @return [void]
|
|
2286
2750
|
# @api public
|
|
2287
|
-
#: (Symbol
|
|
2288
|
-
def sheet_properties(
|
|
2751
|
+
#: (Hash[Symbol, untyped] | Elements::SheetProperties opts) -> void
|
|
2752
|
+
def sheet_properties=(opts)
|
|
2289
2753
|
sheet if @current_sheet.nil?
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2754
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2755
|
+
@current_sheet_properties = {}
|
|
2756
|
+
sheet_properties(**h)
|
|
2757
|
+
nil
|
|
2758
|
+
end
|
|
2294
2759
|
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2760
|
+
# Configures or queries sheet view display properties (<sheetView>).
|
|
2761
|
+
#
|
|
2762
|
+
# When called with no arguments, returns the {Elements::SheetView} value object.
|
|
2763
|
+
# When called with keyword options, configures view properties and returns nil.
|
|
2764
|
+
#
|
|
2765
|
+
# @param opts [Hash] Additional view properties.
|
|
2766
|
+
# @return [Elements::SheetView, void]
|
|
2767
|
+
# @api public
|
|
2768
|
+
#: () -> Elements::SheetView
|
|
2769
|
+
#: (**untyped opts) -> void
|
|
2770
|
+
def sheet_view(**opts)
|
|
2771
|
+
sheet if @current_sheet.nil?
|
|
2772
|
+
return Elements::SheetView.new(**@current_sheet_view) if opts.empty?
|
|
2301
2773
|
|
|
2302
|
-
@
|
|
2774
|
+
opts.each { |k, v| @current_sheet_view[k.to_sym] = v }
|
|
2775
|
+
nil
|
|
2303
2776
|
end
|
|
2304
2777
|
|
|
2305
|
-
#
|
|
2778
|
+
# Replaces sheet view properties with the given hash or {Elements::SheetView} object.
|
|
2306
2779
|
#
|
|
2307
|
-
# @param
|
|
2308
|
-
# @param value [Object] View property value.
|
|
2780
|
+
# @param opts [Hash, Elements::SheetView]
|
|
2309
2781
|
# @return [void]
|
|
2310
2782
|
# @api public
|
|
2311
|
-
#: (Symbol
|
|
2312
|
-
def sheet_view(
|
|
2783
|
+
#: (Hash[Symbol, untyped] | Elements::SheetView opts) -> void
|
|
2784
|
+
def sheet_view=(opts)
|
|
2313
2785
|
sheet if @current_sheet.nil?
|
|
2314
|
-
|
|
2786
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2787
|
+
@current_sheet_view = h.transform_keys(&:to_sym)
|
|
2788
|
+
nil
|
|
2315
2789
|
end
|
|
2316
2790
|
|
|
2317
|
-
# Configures sheet format properties (
|
|
2791
|
+
# Configures or queries sheet format properties (<sheetFormatPr>).
|
|
2792
|
+
#
|
|
2793
|
+
# When called with no arguments, returns the {Elements::SheetFormat} value object.
|
|
2794
|
+
# When called with keyword options, configures format properties and returns nil.
|
|
2318
2795
|
#
|
|
2319
|
-
# @param name [Symbol, String, Hash, nil] Property name or hash of properties.
|
|
2320
|
-
# @param value [Object, nil] Property value when name is provided.
|
|
2321
2796
|
# @param opts [Hash] Keyword arguments for sheet format properties.
|
|
2322
|
-
# @return [
|
|
2797
|
+
# @return [Elements::SheetFormat, void]
|
|
2323
2798
|
# @api public
|
|
2324
|
-
#: (
|
|
2325
|
-
|
|
2799
|
+
#: () -> Elements::SheetFormat
|
|
2800
|
+
#: (**untyped opts) -> void
|
|
2801
|
+
def sheet_format(**opts)
|
|
2326
2802
|
sheet if @current_sheet.nil?
|
|
2327
|
-
if
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
end
|
|
2332
|
-
@current_sheet_format.merge!(opts) unless opts.empty?
|
|
2333
|
-
@current_sheet_format
|
|
2803
|
+
return Elements::SheetFormat.new(**@current_sheet_format) if opts.empty?
|
|
2804
|
+
|
|
2805
|
+
opts.each { |k, v| @current_sheet_format[k.to_sym] = v }
|
|
2806
|
+
nil
|
|
2334
2807
|
end
|
|
2335
2808
|
|
|
2336
|
-
#
|
|
2809
|
+
# Replaces sheet format properties with the given hash or {Elements::SheetFormat} object.
|
|
2337
2810
|
#
|
|
2338
|
-
# @param
|
|
2811
|
+
# @param opts [Hash, Elements::SheetFormat]
|
|
2339
2812
|
# @return [void]
|
|
2340
2813
|
# @api public
|
|
2341
|
-
#: (
|
|
2342
|
-
def
|
|
2343
|
-
# simplecov:disable
|
|
2344
|
-
# Edge case / untested delegation block
|
|
2814
|
+
#: (Hash[Symbol, untyped] | Elements::SheetFormat opts) -> void
|
|
2815
|
+
def sheet_format=(opts)
|
|
2345
2816
|
sheet if @current_sheet.nil?
|
|
2346
|
-
|
|
2347
|
-
|
|
2817
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : (opts || {})
|
|
2818
|
+
@current_sheet_format = h.transform_keys(&:to_sym)
|
|
2819
|
+
nil
|
|
2348
2820
|
end
|
|
2349
2821
|
|
|
2350
|
-
# Inserts a
|
|
2822
|
+
# Inserts a horizontal page break after the given 0-based row.
|
|
2351
2823
|
#
|
|
2352
|
-
# @param
|
|
2824
|
+
# @param row_index [Integer] 0-based row index.
|
|
2353
2825
|
# @return [void]
|
|
2354
2826
|
# @api public
|
|
2355
|
-
#: (Integer
|
|
2356
|
-
def
|
|
2357
|
-
# simplecov:disable
|
|
2358
|
-
# Edge case / untested delegation block
|
|
2359
|
-
col_index = Elements::Cell.column_index(col_index)
|
|
2827
|
+
#: (Integer row_index) -> void
|
|
2828
|
+
def row_break(row_index)
|
|
2360
2829
|
sheet if @current_sheet.nil?
|
|
2361
|
-
@
|
|
2362
|
-
|
|
2830
|
+
@current_row_breaks << { id: row_index, max: 16_383, man: 1 }
|
|
2831
|
+
end
|
|
2832
|
+
|
|
2833
|
+
# Inserts a vertical page break after the given column.
|
|
2834
|
+
#
|
|
2835
|
+
# @param col [Integer, String, Symbol] 0-based column index or letter ("B", :B).
|
|
2836
|
+
# @return [void]
|
|
2837
|
+
# @api public
|
|
2838
|
+
#: (Integer | String | Symbol col) -> void
|
|
2839
|
+
def column_break(col)
|
|
2840
|
+
col_index = Elements::Cell._column_index(col)
|
|
2841
|
+
sheet if @current_sheet.nil?
|
|
2842
|
+
@current_col_breaks << { id: col_index, max: 1_048_575, man: 1 }
|
|
2363
2843
|
end
|
|
2364
2844
|
|
|
2365
2845
|
# Adds a protected range to the current sheet.
|
|
@@ -2378,7 +2858,6 @@ module Xlsxrb
|
|
|
2378
2858
|
entry.merge!(opts) unless opts.empty?
|
|
2379
2859
|
@current_protected_ranges << DslHelpers.normalize_protection_options(entry)
|
|
2380
2860
|
end
|
|
2381
|
-
alias add_protected_range protected_range
|
|
2382
2861
|
|
|
2383
2862
|
# Adds a cell watch to the current sheet.
|
|
2384
2863
|
#
|
|
@@ -2390,7 +2869,6 @@ module Xlsxrb
|
|
|
2390
2869
|
sheet if @current_sheet.nil?
|
|
2391
2870
|
@current_cell_watches << ref.to_s
|
|
2392
2871
|
end
|
|
2393
|
-
alias add_cell_watch cell_watch
|
|
2394
2872
|
|
|
2395
2873
|
# Adds an ignored error entry to the current sheet.
|
|
2396
2874
|
#
|
|
@@ -2399,123 +2877,137 @@ module Xlsxrb
|
|
|
2399
2877
|
# @return [void]
|
|
2400
2878
|
# @api public
|
|
2401
2879
|
#: (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
|
|
2402
|
-
def
|
|
2880
|
+
def ignored_error(sqref, **opts)
|
|
2403
2881
|
sheet if @current_sheet.nil?
|
|
2404
2882
|
@current_ignored_errors << { sqref: sqref.to_s }.merge(opts)
|
|
2405
2883
|
end
|
|
2406
|
-
alias add_ignored_error ignore_error
|
|
2407
2884
|
|
|
2408
2885
|
# Returns the ignored error entries configured for the current sheet.
|
|
2409
2886
|
#
|
|
2410
|
-
# @return [Array<
|
|
2887
|
+
# @return [Array<Elements::IgnoredError>]
|
|
2411
2888
|
# @api public
|
|
2412
|
-
#: () -> Array[
|
|
2889
|
+
#: () -> Array[Elements::IgnoredError]
|
|
2413
2890
|
def ignored_errors
|
|
2414
|
-
@current_ignored_errors.
|
|
2891
|
+
@current_ignored_errors.map { |ie| ie.is_a?(Elements::IgnoredError) ? ie : Elements::IgnoredError.new(**ie) }.freeze
|
|
2415
2892
|
end
|
|
2416
2893
|
|
|
2417
|
-
#
|
|
2894
|
+
# Phonetic (furigana) guide properties for the current sheet.
|
|
2418
2895
|
#
|
|
2419
|
-
# @
|
|
2420
|
-
# Returns the current phonetic properties.
|
|
2421
|
-
# @return [Hash, nil]
|
|
2422
|
-
# @overload phonetic_properties(spec = nil, font_id: nil, type: nil, alignment: nil)
|
|
2423
|
-
# Sets phonetic properties for the current sheet.
|
|
2424
|
-
# @param spec [Hash, Integer, nil]
|
|
2425
|
-
# @param font_id [Integer, nil]
|
|
2426
|
-
# @param type [Symbol, String, nil]
|
|
2427
|
-
# @param alignment [Symbol, String, nil]
|
|
2428
|
-
# @return [Hash, nil]
|
|
2896
|
+
# @return [Elements::PhoneticProperties, nil]
|
|
2429
2897
|
# @api public
|
|
2430
|
-
#: (
|
|
2431
|
-
def phonetic_properties
|
|
2898
|
+
#: () -> Elements::PhoneticProperties?
|
|
2899
|
+
def phonetic_properties
|
|
2432
2900
|
sheet if @current_sheet.nil?
|
|
2433
|
-
|
|
2434
|
-
|
|
2901
|
+
return nil unless @current_phonetic_properties
|
|
2902
|
+
|
|
2903
|
+
@current_phonetic_properties.is_a?(Elements::PhoneticProperties) ? @current_phonetic_properties : Elements::PhoneticProperties.new(**@current_phonetic_properties)
|
|
2904
|
+
end
|
|
2905
|
+
|
|
2906
|
+
# Sets phonetic (furigana) guide properties for the current sheet.
|
|
2907
|
+
#
|
|
2908
|
+
# @param spec [Hash, Integer, nil]
|
|
2909
|
+
# @return [Hash[Symbol, untyped], Integer, nil]
|
|
2910
|
+
# @api public
|
|
2911
|
+
#: (Hash[Symbol, untyped] | Integer | nil spec) -> (Hash[Symbol, untyped] | Integer | nil)
|
|
2912
|
+
def phonetic_properties=(spec)
|
|
2913
|
+
sheet if @current_sheet.nil?
|
|
2914
|
+
if spec.nil?
|
|
2915
|
+
@current_phonetic_properties = nil
|
|
2435
2916
|
else
|
|
2436
2917
|
props = if spec.is_a?(Hash)
|
|
2437
|
-
spec.
|
|
2918
|
+
spec.dup
|
|
2438
2919
|
elsif spec.is_a?(Integer)
|
|
2439
|
-
{ font_id: spec
|
|
2920
|
+
{ font_id: spec }
|
|
2440
2921
|
else
|
|
2441
|
-
{
|
|
2922
|
+
{}
|
|
2442
2923
|
end
|
|
2443
|
-
props.compact!
|
|
2444
2924
|
@current_phonetic_properties = WorksheetBuilder.normalize_phonetic_properties(props)
|
|
2445
2925
|
end
|
|
2926
|
+
spec
|
|
2446
2927
|
end
|
|
2447
|
-
alias phonetic_properties= phonetic_properties
|
|
2448
|
-
alias phonetic_pr phonetic_properties
|
|
2449
|
-
alias phonetic_pr= phonetic_properties
|
|
2450
2928
|
|
|
2451
|
-
#
|
|
2929
|
+
# Gets the internal code name of the current worksheet (or workbook if no sheet is open).
|
|
2452
2930
|
#
|
|
2453
|
-
# @param val [String, Symbol, nil] The code name.
|
|
2454
2931
|
# @return [String, nil]
|
|
2455
2932
|
# @api public
|
|
2456
|
-
#: (
|
|
2457
|
-
def code_name
|
|
2933
|
+
#: () -> String?
|
|
2934
|
+
def code_name
|
|
2458
2935
|
if @current_sheet.nil?
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
else
|
|
2462
|
-
@workbook_properties[:code_name] = val.to_s
|
|
2463
|
-
end
|
|
2464
|
-
elsif val.nil?
|
|
2936
|
+
@workbook_properties[:code_name]
|
|
2937
|
+
else
|
|
2465
2938
|
@current_sheet_properties[:code_name]
|
|
2939
|
+
end
|
|
2940
|
+
end
|
|
2941
|
+
|
|
2942
|
+
# Sets the internal code name of the current worksheet (or workbook if no sheet is open).
|
|
2943
|
+
#
|
|
2944
|
+
# @param val [String, Symbol, nil] The code name.
|
|
2945
|
+
# @return [String, nil]
|
|
2946
|
+
# @api public
|
|
2947
|
+
#: (String | Symbol | nil val) -> String?
|
|
2948
|
+
def code_name=(val)
|
|
2949
|
+
if @current_sheet.nil?
|
|
2950
|
+
@workbook_properties[:code_name] = val&.to_s
|
|
2466
2951
|
else
|
|
2467
|
-
@current_sheet_properties[:code_name] = val
|
|
2952
|
+
@current_sheet_properties[:code_name] = val&.to_s
|
|
2468
2953
|
end
|
|
2469
2954
|
end
|
|
2470
|
-
alias code_name= code_name
|
|
2471
2955
|
|
|
2472
|
-
#
|
|
2473
|
-
# When enabled, optionally sets fit_to_width and/or fit_to_height on page_setup.
|
|
2956
|
+
# Returns whether page setup fits content to page width/height for the current sheet.
|
|
2474
2957
|
#
|
|
2475
|
-
# @
|
|
2476
|
-
# @param width [Integer, nil] Pages wide to fit to.
|
|
2477
|
-
# @param height [Integer, nil] Pages tall to fit to.
|
|
2478
|
-
# @return [Boolean, void]
|
|
2958
|
+
# @return [Boolean]
|
|
2479
2959
|
# @api public
|
|
2480
|
-
#: (
|
|
2481
|
-
def fit_to_page
|
|
2960
|
+
#: () -> bool
|
|
2961
|
+
def fit_to_page?
|
|
2482
2962
|
sheet if @current_sheet.nil?
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
end
|
|
2963
|
+
@current_sheet_properties[:fit_to_page] ? true : false
|
|
2964
|
+
end
|
|
2486
2965
|
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2966
|
+
# Sets whether page setup fits content to page width/height for the current sheet.
|
|
2967
|
+
#
|
|
2968
|
+
# @param enabled [Boolean, nil] Whether to fit to page.
|
|
2969
|
+
# @return [Boolean]
|
|
2970
|
+
# @api public
|
|
2971
|
+
#: (bool? enabled) -> bool?
|
|
2972
|
+
def fit_to_page=(enabled)
|
|
2973
|
+
sheet if @current_sheet.nil?
|
|
2974
|
+
@current_sheet_properties[:fit_to_page] = enabled ? true : false
|
|
2490
2975
|
end
|
|
2491
|
-
alias fit_to_page= fit_to_page
|
|
2492
|
-
alias fit_to_page? fit_to_page
|
|
2493
2976
|
|
|
2494
|
-
#
|
|
2977
|
+
# Worksheet calculation properties (<sheetCalcPr>) for the current sheet.
|
|
2495
2978
|
#
|
|
2496
2979
|
# @example Instruct Excel to recalculate formulas when loading sheet
|
|
2497
|
-
# w.
|
|
2980
|
+
# w.sheet_calc_properties = { full_calc_on_load: true }
|
|
2981
|
+
#
|
|
2982
|
+
# @return [Elements::SheetCalcProperties, nil]
|
|
2983
|
+
# @api public
|
|
2984
|
+
#: () -> Elements::SheetCalcProperties?
|
|
2985
|
+
def sheet_calc_properties
|
|
2986
|
+
sheet if @current_sheet.nil?
|
|
2987
|
+
calc = @current_sheet_calc_pr || (@current_sheet_properties[:full_calc_on_load] ? { full_calc_on_load: true } : nil)
|
|
2988
|
+
return nil unless calc
|
|
2989
|
+
|
|
2990
|
+
calc.is_a?(Elements::SheetCalcProperties) ? calc : Elements::SheetCalcProperties.new(**calc)
|
|
2991
|
+
end
|
|
2992
|
+
|
|
2993
|
+
# Sets worksheet calculation properties (<sheetCalcPr>) for the current sheet.
|
|
2498
2994
|
#
|
|
2499
2995
|
# @param spec [Hash, nil] Calculation properties hash.
|
|
2500
|
-
# @param full_calc_on_load [Boolean, nil] Whether to recalculate when loading.
|
|
2501
2996
|
# @return [Hash, nil]
|
|
2502
2997
|
# @api public
|
|
2503
|
-
#: (
|
|
2504
|
-
def
|
|
2998
|
+
#: (Hash[Symbol, untyped]? spec) -> Hash[Symbol, untyped]?
|
|
2999
|
+
def sheet_calc_properties=(spec)
|
|
2505
3000
|
sheet if @current_sheet.nil?
|
|
2506
|
-
if spec.nil?
|
|
2507
|
-
|
|
3001
|
+
if spec.nil?
|
|
3002
|
+
@current_sheet_properties.delete(:full_calc_on_load)
|
|
3003
|
+
@current_sheet_calc_pr = nil
|
|
3004
|
+
else
|
|
3005
|
+
pr = spec.is_a?(Hash) ? spec.dup : {}
|
|
3006
|
+
@current_sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
|
|
3007
|
+
@current_sheet_calc_pr = pr
|
|
2508
3008
|
end
|
|
2509
|
-
|
|
2510
|
-
pr = spec.is_a?(Hash) ? spec.dup : {}
|
|
2511
|
-
pr[:full_calc_on_load] = full_calc_on_load unless full_calc_on_load.nil?
|
|
2512
|
-
pr.merge!(opts) unless opts.empty?
|
|
2513
|
-
@current_sheet_properties[:full_calc_on_load] = pr[:full_calc_on_load] unless pr[:full_calc_on_load].nil?
|
|
2514
|
-
@current_sheet_calc_pr = pr
|
|
3009
|
+
spec
|
|
2515
3010
|
end
|
|
2516
|
-
alias sheet_calc_pr= sheet_calc_pr
|
|
2517
|
-
alias calc_pr sheet_calc_pr
|
|
2518
|
-
alias calc_pr= sheet_calc_pr
|
|
2519
3011
|
|
|
2520
3012
|
# --- Workbook-Level Methods ---
|
|
2521
3013
|
|
|
@@ -2523,19 +3015,21 @@ module Xlsxrb
|
|
|
2523
3015
|
#
|
|
2524
3016
|
# @param name [String] The defined name.
|
|
2525
3017
|
# @param value [Object, nil] The formula or value expression.
|
|
2526
|
-
# @param sheet [String, nil]
|
|
3018
|
+
# @param sheet [String, nil] Reference sheet name.
|
|
3019
|
+
# @param scope [String, Symbol, nil] Local scope sheet name or :workbook.
|
|
2527
3020
|
# @param hidden [Boolean] Whether the defined name is hidden.
|
|
2528
|
-
# @param
|
|
2529
|
-
# @param rows [Integer, Range, nil] Row or row range (
|
|
3021
|
+
# @param columns [Integer, String, nil] Column index or letter for coordinate-based reference.
|
|
3022
|
+
# @param rows [Integer, Range, nil] Row or row range (0-based) for coordinate-based reference.
|
|
2530
3023
|
# @param range [String, nil] Cell range reference.
|
|
2531
3024
|
# @return [void]
|
|
2532
3025
|
# @api public
|
|
2533
|
-
#: (String name, ?untyped value, ?sheet: String?, ?hidden: bool, ?
|
|
2534
|
-
def defined_name(name, value = nil, sheet: nil, hidden: false,
|
|
2535
|
-
|
|
2536
|
-
normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: target_ref_sheet, col: col, rows: rows, range: range)
|
|
3026
|
+
#: (String name, ?untyped value, ?sheet: String?, ?scope: (String | Symbol)?, ?hidden: bool, ?columns: untyped, ?rows: untyped, ?range: untyped) -> void
|
|
3027
|
+
def defined_name(name, value = nil, sheet: nil, scope: nil, hidden: false, columns: nil, rows: nil, range: nil)
|
|
3028
|
+
normalized_val = DslHelpers.normalize_defined_name_value(value, sheet: sheet, columns: columns, rows: rows, range: range)
|
|
2537
3029
|
entry = { name: name, value: normalized_val, hidden: hidden }
|
|
2538
|
-
local_sheet =
|
|
3030
|
+
local_sheet = if scope
|
|
3031
|
+
scope == :workbook ? nil : scope.to_s
|
|
3032
|
+
end
|
|
2539
3033
|
if local_sheet
|
|
2540
3034
|
# local_sheet_id will be resolved at close time
|
|
2541
3035
|
entry[:local_sheet_name] = local_sheet
|
|
@@ -2543,44 +3037,99 @@ module Xlsxrb
|
|
|
2543
3037
|
@defined_names << entry
|
|
2544
3038
|
end
|
|
2545
3039
|
|
|
2546
|
-
#
|
|
3040
|
+
# Returns workbook-level defined names.
|
|
3041
|
+
#
|
|
3042
|
+
# @return [Array<Elements::DefinedName>]
|
|
3043
|
+
# @api public
|
|
3044
|
+
#: () -> Array[Elements::DefinedName]
|
|
3045
|
+
def defined_names
|
|
3046
|
+
@defined_names.map { |dn| dn.is_a?(Elements::DefinedName) ? dn : Elements::DefinedName.new(**dn) }
|
|
3047
|
+
end
|
|
3048
|
+
|
|
3049
|
+
# Returns the print area range for the current or named sheet, or nil if none.
|
|
2547
3050
|
#
|
|
2548
|
-
# @param range [String] Cell range (e.g. "A1:G50").
|
|
2549
3051
|
# @param sheet [String, nil] Target sheet name.
|
|
2550
|
-
# @return [
|
|
3052
|
+
# @return [String, nil]
|
|
2551
3053
|
# @api public
|
|
2552
|
-
#: (
|
|
2553
|
-
def print_area(
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
3054
|
+
#: (?sheet: String?) -> String?
|
|
3055
|
+
def print_area(sheet: nil)
|
|
3056
|
+
sheet_name = sheet || @current_sheet
|
|
3057
|
+
if sheet_name.nil? || sheet_name == @current_sheet
|
|
3058
|
+
@current_print_area
|
|
3059
|
+
else
|
|
3060
|
+
dn = @defined_names.find { |d| d[:name] == "_xlnm.Print_Area" && d[:local_sheet_name] == sheet_name }
|
|
3061
|
+
dn ? dn[:value].split("!", 2).last.tr("$", "") : nil
|
|
3062
|
+
end
|
|
2561
3063
|
end
|
|
2562
3064
|
|
|
2563
|
-
# Sets print
|
|
3065
|
+
# Sets the print area for the current worksheet.
|
|
2564
3066
|
#
|
|
2565
|
-
# @param
|
|
2566
|
-
# @
|
|
3067
|
+
# @param range [String, nil] Cell range (e.g. "A1:G50").
|
|
3068
|
+
# @return [String, nil]
|
|
3069
|
+
# @api public
|
|
3070
|
+
#: (String? range) -> String?
|
|
3071
|
+
def print_area=(range)
|
|
3072
|
+
set_print_area(range, sheet: @current_sheet)
|
|
3073
|
+
end
|
|
3074
|
+
|
|
3075
|
+
# Sets or gets repeating print titles (rows and/or columns) for pagination.
|
|
3076
|
+
#
|
|
3077
|
+
# When called with no row/column arguments, returns the {Elements::PrintTitles} value object or nil.
|
|
3078
|
+
# When called with row/column arguments, sets repeating print titles and returns nil.
|
|
3079
|
+
#
|
|
3080
|
+
# @param rows [String, Integer, Range, Object, nil] Repeating row range (e.g. "1:2" or 0-based 0..1).
|
|
3081
|
+
# @param columns [String, Integer, Symbol, Range, Object, nil] Repeating column range (e.g. "A:B" or 0..1).
|
|
2567
3082
|
# @param sheet [String, nil] Target sheet name.
|
|
2568
|
-
# @return [void]
|
|
3083
|
+
# @return [Elements::PrintTitles, nil, void]
|
|
2569
3084
|
# @api public
|
|
2570
|
-
#: (
|
|
2571
|
-
|
|
3085
|
+
#: () -> Elements::PrintTitles?
|
|
3086
|
+
#: (?rows: (String | Integer | Range[Integer])?, ?columns: (String | Integer | Symbol | Range[untyped])?, ?sheet: String?) -> void
|
|
3087
|
+
def print_titles(rows: nil, columns: nil, sheet: nil)
|
|
2572
3088
|
sheet_name = sheet || @current_sheet || "Sheet1"
|
|
3089
|
+
if rows.nil? && columns.nil?
|
|
3090
|
+
return Elements::PrintTitles.new(rows: @current_print_titles[:rows], columns: @current_print_titles[:columns]) if sheet_name == @current_sheet && @current_print_titles
|
|
3091
|
+
|
|
3092
|
+
existing = @defined_names.find { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
|
|
3093
|
+
return nil unless existing
|
|
3094
|
+
|
|
3095
|
+
c = Regexp.last_match(1).delete("$") if existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
|
|
3096
|
+
r = Regexp.last_match(1).delete("$") if existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
|
|
3097
|
+
return Elements::PrintTitles.new(rows: r, columns: c)
|
|
3098
|
+
end
|
|
3099
|
+
|
|
3100
|
+
@current_print_titles = { rows: rows, columns: columns }.compact if sheet_name == @current_sheet
|
|
3101
|
+
c = DslHelpers.normalize_print_titles_columns(columns)
|
|
3102
|
+
r = DslHelpers.normalize_print_titles_rows(rows)
|
|
2573
3103
|
existing = @defined_names.find { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
|
|
2574
|
-
if existing && (
|
|
2575
|
-
|
|
2576
|
-
|
|
3104
|
+
if existing && (r.nil? || c.nil?)
|
|
3105
|
+
c = Regexp.last_match(1).delete("$") if c.nil? && existing[:value] =~ /'[^']*'!\$([A-Za-z]+:\$[A-Za-z]+)/
|
|
3106
|
+
r = Regexp.last_match(1).delete("$") if r.nil? && existing[:value] =~ /'[^']*'!\$([0-9]+:\$[0-9]+)/
|
|
2577
3107
|
end
|
|
2578
3108
|
parts = []
|
|
2579
|
-
parts << "'#{sheet_name}'!$#{
|
|
2580
|
-
parts << "'#{sheet_name}'!$#{
|
|
3109
|
+
parts << "'#{sheet_name}'!$#{c.sub(":", ":$")}" if c
|
|
3110
|
+
parts << "'#{sheet_name}'!$#{r.sub(":", ":$")}" if r
|
|
2581
3111
|
value = parts.join(",")
|
|
2582
3112
|
@defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
|
|
2583
|
-
defined_name("_xlnm.Print_Titles", value, sheet: sheet_name)
|
|
3113
|
+
defined_name("_xlnm.Print_Titles", value, sheet: sheet_name, scope: sheet_name) unless value.empty?
|
|
3114
|
+
nil
|
|
3115
|
+
end
|
|
3116
|
+
|
|
3117
|
+
# Sets repeating print titles for the current worksheet.
|
|
3118
|
+
#
|
|
3119
|
+
# @param opts [Elements::PrintTitles, Hash, nil] Options with :rows and/or :columns.
|
|
3120
|
+
# @return [Elements::PrintTitles, Hash, nil]
|
|
3121
|
+
# @api public
|
|
3122
|
+
#: (Elements::PrintTitles | Hash[Symbol, untyped] | nil opts) -> (Elements::PrintTitles | Hash[Symbol, untyped] | nil)
|
|
3123
|
+
def print_titles=(opts)
|
|
3124
|
+
if opts.nil?
|
|
3125
|
+
@current_print_titles = nil
|
|
3126
|
+
sheet_name = @current_sheet || "Sheet1"
|
|
3127
|
+
@defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Titles" && dn[:local_sheet_name] == sheet_name }
|
|
3128
|
+
else
|
|
3129
|
+
h = opts.respond_to?(:to_h) ? opts.to_h : opts
|
|
3130
|
+
print_titles(**h)
|
|
3131
|
+
end
|
|
3132
|
+
opts
|
|
2584
3133
|
end
|
|
2585
3134
|
|
|
2586
3135
|
# Sets repeating title rows for pagination on the current or named sheet.
|
|
@@ -2619,9 +3168,9 @@ module Xlsxrb
|
|
|
2619
3168
|
cols_str = if first.is_a?(String)
|
|
2620
3169
|
first.include?(":") ? first : "#{first}:#{last || first}"
|
|
2621
3170
|
else
|
|
2622
|
-
first_name =
|
|
3171
|
+
first_name = Elements::Cell._column_letter(first)
|
|
2623
3172
|
last_name = if last.is_a?(Integer)
|
|
2624
|
-
|
|
3173
|
+
Elements::Cell._column_letter(last)
|
|
2625
3174
|
elsif last
|
|
2626
3175
|
last.to_s
|
|
2627
3176
|
else
|
|
@@ -2629,42 +3178,94 @@ module Xlsxrb
|
|
|
2629
3178
|
end
|
|
2630
3179
|
"#{first_name}:#{last_name}"
|
|
2631
3180
|
end
|
|
2632
|
-
print_titles(
|
|
3181
|
+
print_titles(columns: cols_str, sheet: sheet)
|
|
2633
3182
|
end
|
|
2634
3183
|
|
|
2635
|
-
# Sets workbook protection.
|
|
3184
|
+
# Sets or returns workbook protection settings.
|
|
2636
3185
|
#
|
|
2637
3186
|
# @param opts [Hash] Protection options.
|
|
3187
|
+
# @return [Elements::WorkbookProtection, nil, void]
|
|
3188
|
+
# @api public
|
|
3189
|
+
#: (**String | Integer | bool | nil opts) -> (Elements::WorkbookProtection | nil)
|
|
3190
|
+
def workbook_protection(**opts)
|
|
3191
|
+
if opts.empty?
|
|
3192
|
+
@workbook_protection ? Elements::WorkbookProtection.new(**@workbook_protection) : nil
|
|
3193
|
+
else
|
|
3194
|
+
@workbook_protection = DslHelpers.normalize_workbook_protection(opts)
|
|
3195
|
+
nil
|
|
3196
|
+
end
|
|
3197
|
+
end
|
|
3198
|
+
|
|
3199
|
+
# Sets workbook protection settings.
|
|
3200
|
+
#
|
|
3201
|
+
# @param opts [Hash, Elements::MetadataRecord, nil]
|
|
2638
3202
|
# @return [void]
|
|
2639
3203
|
# @api public
|
|
2640
|
-
#: (
|
|
2641
|
-
def
|
|
2642
|
-
@workbook_protection = opts
|
|
3204
|
+
#: (untyped opts) -> void
|
|
3205
|
+
def workbook_protection=(opts)
|
|
3206
|
+
@workbook_protection = opts.is_a?(Elements::MetadataRecord) ? opts.to_h : (opts && DslHelpers.normalize_workbook_protection(opts))
|
|
2643
3207
|
end
|
|
2644
3208
|
|
|
2645
|
-
#
|
|
3209
|
+
# Configures or queries core document properties.
|
|
3210
|
+
#
|
|
3211
|
+
# When called with no arguments, returns the {Elements::CoreProperties} value object.
|
|
3212
|
+
# When called with keyword options, configures properties and returns nil.
|
|
2646
3213
|
#
|
|
2647
|
-
# @param
|
|
2648
|
-
# @
|
|
3214
|
+
# @param opts [Hash] Core properties map.
|
|
3215
|
+
# @return [Elements::CoreProperties, void]
|
|
3216
|
+
# @api public
|
|
3217
|
+
#: () -> Elements::CoreProperties
|
|
3218
|
+
#: (**untyped opts) -> void
|
|
3219
|
+
def core_properties(**opts)
|
|
3220
|
+
return Elements::CoreProperties.new(**@core_properties) if opts.empty?
|
|
3221
|
+
|
|
3222
|
+
@core_properties.merge!(opts)
|
|
3223
|
+
nil
|
|
3224
|
+
end
|
|
3225
|
+
|
|
3226
|
+
# Replaces core document properties.
|
|
3227
|
+
#
|
|
3228
|
+
# @param props [Hash, Elements::CoreProperties]
|
|
2649
3229
|
# @return [void]
|
|
2650
3230
|
# @api public
|
|
2651
|
-
#: (Symbol
|
|
2652
|
-
def
|
|
2653
|
-
|
|
3231
|
+
#: (Hash[Symbol, untyped] | Elements::CoreProperties props) -> void
|
|
3232
|
+
def core_properties=(props)
|
|
3233
|
+
h = props.respond_to?(:to_h) ? props.to_h : (props || {})
|
|
3234
|
+
@core_properties = h.transform_keys(&:to_sym)
|
|
3235
|
+
nil
|
|
3236
|
+
end
|
|
3237
|
+
|
|
3238
|
+
# Configures or queries application document properties.
|
|
3239
|
+
#
|
|
3240
|
+
# When called with no arguments, returns the {Elements::AppProperties} value object.
|
|
3241
|
+
# When called with keyword options, configures properties and returns nil.
|
|
3242
|
+
#
|
|
3243
|
+
# @param opts [Hash] Application properties map.
|
|
3244
|
+
# @return [Elements::AppProperties, void]
|
|
3245
|
+
# @api public
|
|
3246
|
+
#: () -> Elements::AppProperties
|
|
3247
|
+
#: (**untyped opts) -> void
|
|
3248
|
+
def app_properties(**opts)
|
|
3249
|
+
return Elements::AppProperties.new(**@app_properties) if opts.empty?
|
|
3250
|
+
|
|
3251
|
+
opts.each do |k, v|
|
|
3252
|
+
norm_name = k.to_sym == :application ? :app_name : k.to_sym
|
|
3253
|
+
@app_properties[norm_name] = v
|
|
3254
|
+
end
|
|
3255
|
+
nil
|
|
2654
3256
|
end
|
|
2655
3257
|
|
|
2656
|
-
#
|
|
3258
|
+
# Replaces application document properties.
|
|
2657
3259
|
#
|
|
2658
|
-
# @param
|
|
2659
|
-
# @param value [String, Integer, Time] Property value.
|
|
3260
|
+
# @param props [Hash, Elements::AppProperties]
|
|
2660
3261
|
# @return [void]
|
|
2661
3262
|
# @api public
|
|
2662
|
-
#: (Symbol
|
|
2663
|
-
def
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
3263
|
+
#: (Hash[Symbol, untyped] | Elements::AppProperties props) -> void
|
|
3264
|
+
def app_properties=(props)
|
|
3265
|
+
h = props.respond_to?(:to_h) ? props.to_h : (props || {})
|
|
3266
|
+
@app_properties = {}
|
|
3267
|
+
app_properties(**h)
|
|
3268
|
+
nil
|
|
2668
3269
|
end
|
|
2669
3270
|
|
|
2670
3271
|
# Sets multiple core and/or app properties.
|
|
@@ -2676,12 +3277,9 @@ module Xlsxrb
|
|
|
2676
3277
|
# @api public
|
|
2677
3278
|
#: (?core: Hash[Symbol, String | Integer | Time]?, ?app: Hash[Symbol, String | Integer | Time]?, ?custom: Hash[String | Symbol, untyped]?) -> void
|
|
2678
3279
|
def properties(core: nil, app: nil, custom: nil)
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
core&.each { |k, v| core_property(k, v) }
|
|
2682
|
-
app&.each { |k, v| app_property(k, v) }
|
|
3280
|
+
core_properties(**core) if core
|
|
3281
|
+
app_properties(**app) if app
|
|
2683
3282
|
custom&.each { |k, v| custom_property(k.to_s, v) }
|
|
2684
|
-
# simplecov:enable
|
|
2685
3283
|
end
|
|
2686
3284
|
|
|
2687
3285
|
# Adds a custom document property.
|
|
@@ -2699,6 +3297,18 @@ module Xlsxrb
|
|
|
2699
3297
|
# simplecov:enable
|
|
2700
3298
|
end
|
|
2701
3299
|
|
|
3300
|
+
# Returns custom document properties.
|
|
3301
|
+
#
|
|
3302
|
+
# @return [Hash<String, Elements::CustomProperty>]
|
|
3303
|
+
# @api public
|
|
3304
|
+
#: () -> Hash[String, Elements::CustomProperty]
|
|
3305
|
+
def custom_properties
|
|
3306
|
+
@custom_properties.to_h do |cp|
|
|
3307
|
+
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)
|
|
3308
|
+
[prop.name.to_s, prop]
|
|
3309
|
+
end.freeze
|
|
3310
|
+
end
|
|
3311
|
+
|
|
2702
3312
|
# Finalizes and writes all streaming sheet contents to the destination target.
|
|
2703
3313
|
#
|
|
2704
3314
|
# @return [void]
|
|
@@ -2722,7 +3332,8 @@ module Xlsxrb
|
|
|
2722
3332
|
|
|
2723
3333
|
resolved_names = resolve_defined_names(@defined_names, @sheets)
|
|
2724
3334
|
|
|
2725
|
-
@workbook_properties[:
|
|
3335
|
+
@workbook_properties[:active_sheet] = @active_sheet unless @active_sheet.nil?
|
|
3336
|
+
@workbook_properties[:active_sheet_index] = @active_sheet unless @active_sheet.nil?
|
|
2726
3337
|
@workbook_properties[:first_sheet] = @first_sheet unless @first_sheet.nil?
|
|
2727
3338
|
@workbook_properties[:show_sheet_tabs] = @show_sheet_tabs unless @show_sheet_tabs.nil?
|
|
2728
3339
|
@workbook_properties[:tab_ratio] = @tab_ratio unless @tab_ratio.nil?
|
|
@@ -2750,7 +3361,7 @@ module Xlsxrb
|
|
|
2750
3361
|
# Explicitly cleans up any resources if not already closed.
|
|
2751
3362
|
#
|
|
2752
3363
|
# @return [void]
|
|
2753
|
-
# @api
|
|
3364
|
+
# @api private
|
|
2754
3365
|
#: () -> void
|
|
2755
3366
|
def cleanup!
|
|
2756
3367
|
if @zip && !@zip.instance_variable_get(:@closed)
|
|
@@ -2771,6 +3382,59 @@ module Xlsxrb
|
|
|
2771
3382
|
|
|
2772
3383
|
private
|
|
2773
3384
|
|
|
3385
|
+
# Raises ArgumentError for any cell style name that has not been defined.
|
|
3386
|
+
#: (untyped cell_styles) -> void
|
|
3387
|
+
def check_style_names!(cell_styles)
|
|
3388
|
+
if cell_styles.is_a?(Array)
|
|
3389
|
+
cell_styles.each { |name| DslHelpers.check_style_name!(name, @style_name_to_id) }
|
|
3390
|
+
else
|
|
3391
|
+
DslHelpers.check_style_name!(cell_styles, @style_name_to_id)
|
|
3392
|
+
end
|
|
3393
|
+
end
|
|
3394
|
+
|
|
3395
|
+
# Gives Date and Time values whose named cell style has no number format a variant of
|
|
3396
|
+
# that style with the default date or time format, registered on first use.
|
|
3397
|
+
#: (Array[untyped] values, untyped cell_styles) -> untyped
|
|
3398
|
+
def with_date_style_variants(values, cell_styles)
|
|
3399
|
+
styles_for_cells = cell_styles.is_a?(Array) ? cell_styles : nil
|
|
3400
|
+
values.each_with_index do |value, idx|
|
|
3401
|
+
next unless value.is_a?(Date) || value.is_a?(Time)
|
|
3402
|
+
|
|
3403
|
+
style_name = styles_for_cells ? styles_for_cells[idx] : cell_styles
|
|
3404
|
+
next unless style_name.is_a?(String) || style_name.is_a?(Symbol)
|
|
3405
|
+
|
|
3406
|
+
variant = DslHelpers.date_style_variant(value, style_name.to_s, @styles[style_name.to_s])
|
|
3407
|
+
next unless variant
|
|
3408
|
+
|
|
3409
|
+
variant_name, number_format = variant
|
|
3410
|
+
unless @style_name_to_id.key?(variant_name)
|
|
3411
|
+
variant_builder = @styles[style_name.to_s].with_number_format(variant_name, number_format)
|
|
3412
|
+
@styles[variant_name] = variant_builder
|
|
3413
|
+
@style_name_to_id[variant_name] = variant_builder.register_with(@style_writer)
|
|
3414
|
+
end
|
|
3415
|
+
styles_for_cells ||= Array.new(values.size, cell_styles)
|
|
3416
|
+
styles_for_cells = styles_for_cells.dup if styles_for_cells.equal?(cell_styles)
|
|
3417
|
+
styles_for_cells[idx] = variant_name
|
|
3418
|
+
end
|
|
3419
|
+
styles_for_cells || cell_styles
|
|
3420
|
+
end
|
|
3421
|
+
|
|
3422
|
+
def ensure_sheet_started!
|
|
3423
|
+
sheet if @current_sheet.nil?
|
|
3424
|
+
end
|
|
3425
|
+
|
|
3426
|
+
#: (String? range, ?sheet: String?) -> String?
|
|
3427
|
+
def set_print_area(range, sheet: nil)
|
|
3428
|
+
sheet_name = sheet || @current_sheet || "Sheet1"
|
|
3429
|
+
@current_print_area = range&.to_s if sheet_name == @current_sheet
|
|
3430
|
+
@defined_names.reject! { |dn| dn[:name] == "_xlnm.Print_Area" && dn[:local_sheet_name] == sheet_name }
|
|
3431
|
+
if range
|
|
3432
|
+
value = "'#{sheet_name}'!#{absolute_range(range)}"
|
|
3433
|
+
defined_name("_xlnm.Print_Area", value, sheet: sheet_name, scope: sheet_name)
|
|
3434
|
+
end
|
|
3435
|
+
range&.to_s
|
|
3436
|
+
end
|
|
3437
|
+
|
|
2774
3438
|
#: (untyped range) -> untyped
|
|
2775
3439
|
def absolute_range(range)
|
|
2776
3440
|
DslHelpers.absolute_range(range)
|
|
@@ -2798,7 +3462,7 @@ module Xlsxrb
|
|
|
2798
3462
|
unless @current_conditional_formats.empty?
|
|
2799
3463
|
@dxfs ||= []
|
|
2800
3464
|
@current_conditional_formats = @current_conditional_formats.map do |rule|
|
|
2801
|
-
next rule if rule[:format_id]
|
|
3465
|
+
next rule if rule[:dxf_id] || rule[:format_id]
|
|
2802
3466
|
|
|
2803
3467
|
normalized = rule.dup
|
|
2804
3468
|
dxf = normalized.delete(:dxf) || DslHelpers.extract_dxf_from_rule!(normalized)
|
|
@@ -2809,7 +3473,7 @@ module Xlsxrb
|
|
|
2809
3473
|
@dxfs << dxf
|
|
2810
3474
|
dxf_id = @dxfs.size - 1
|
|
2811
3475
|
end
|
|
2812
|
-
normalized[:
|
|
3476
|
+
normalized[:dxf_id] = dxf_id
|
|
2813
3477
|
normalized
|
|
2814
3478
|
end
|
|
2815
3479
|
end
|
|
@@ -2847,7 +3511,7 @@ module Xlsxrb
|
|
|
2847
3511
|
sheet_format: @current_sheet_format,
|
|
2848
3512
|
sheet_view: @current_sheet_view,
|
|
2849
3513
|
row_breaks: @current_row_breaks,
|
|
2850
|
-
|
|
3514
|
+
column_breaks: @current_col_breaks,
|
|
2851
3515
|
protected_ranges: @current_protected_ranges,
|
|
2852
3516
|
cell_watches: @current_cell_watches,
|
|
2853
3517
|
ignored_errors: @current_ignored_errors,
|
|
@@ -2858,8 +3522,10 @@ module Xlsxrb
|
|
|
2858
3522
|
sheet_data[:cells] = @current_cells if @current_cells && !@current_cells.empty?
|
|
2859
3523
|
@current_cells = nil
|
|
2860
3524
|
|
|
2861
|
-
|
|
2862
|
-
|
|
3525
|
+
# One writer for all sheets, so that drawing, comment, table, and pivot part numbers
|
|
3526
|
+
# continue across sheets as write_package_parts numbers the parts.
|
|
3527
|
+
@auxiliary_writer ||= Ooxml::WorkbookWriter.new(sheets: [])
|
|
3528
|
+
info = @auxiliary_writer.prepare_sheet_auxiliary(sheet_data, @current_sheet_index - 1)
|
|
2863
3529
|
|
|
2864
3530
|
@current_row_writer.finish(
|
|
2865
3531
|
drawing_rid: info[:drawing_rid],
|
|
@@ -2878,7 +3544,7 @@ module Xlsxrb
|
|
|
2878
3544
|
page_setup: @current_page_setup.empty? ? nil : @current_page_setup,
|
|
2879
3545
|
header_footer: @current_header_footer.empty? ? nil : @current_header_footer,
|
|
2880
3546
|
row_breaks: @current_row_breaks.empty? ? nil : @current_row_breaks,
|
|
2881
|
-
|
|
3547
|
+
column_breaks: @current_col_breaks.empty? ? nil : @current_col_breaks,
|
|
2882
3548
|
cell_watches: @current_cell_watches.empty? ? nil : @current_cell_watches,
|
|
2883
3549
|
ignored_errors: @current_ignored_errors.empty? ? nil : @current_ignored_errors,
|
|
2884
3550
|
phonetic_pr: @current_phonetic_properties,
|