xlsxrb 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +93 -1
- data/README.md +79 -19
- data/lib/ruby_lsp/xlsxrb/completion_listener.rb +31 -61
- data/lib/xlsxrb/chart_builder.rb +595 -113
- data/lib/xlsxrb/dsl_helpers.rb +72 -20
- data/lib/xlsxrb/elements/cell.rb +243 -56
- data/lib/xlsxrb/elements/column.rb +94 -5
- data/lib/xlsxrb/elements/coordinate_access.rb +108 -10
- data/lib/xlsxrb/elements/image.rb +81 -15
- data/lib/xlsxrb/elements/metadata.rb +2733 -0
- data/lib/xlsxrb/elements/row.rb +130 -46
- data/lib/xlsxrb/elements/styles.rb +184 -76
- data/lib/xlsxrb/elements/types.rb +242 -7
- data/lib/xlsxrb/elements/workbook.rb +171 -82
- data/lib/xlsxrb/elements/worksheet.rb +598 -102
- data/lib/xlsxrb/elements.rb +1 -0
- data/lib/xlsxrb/ooxml/reader/listeners/core_listeners.rb +12 -4
- data/lib/xlsxrb/ooxml/reader/listeners/drawing_listeners.rb +7 -2
- data/lib/xlsxrb/ooxml/reader/listeners/feature_listeners.rb +264 -17
- data/lib/xlsxrb/ooxml/reader/listeners/style_listeners.rb +17 -3
- data/lib/xlsxrb/ooxml/reader.rb +4 -0
- data/lib/xlsxrb/ooxml/styles_parser.rb +10 -3
- data/lib/xlsxrb/ooxml/workbook_writer.rb +90 -36
- data/lib/xlsxrb/ooxml/worksheet_parser.rb +2 -2
- data/lib/xlsxrb/ooxml/worksheet_writer.rb +64 -19
- data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +5 -2
- data/lib/xlsxrb/ooxml/writer/features_xml.rb +26 -5
- data/lib/xlsxrb/ooxml/writer/styles_xml.rb +19 -9
- data/lib/xlsxrb/ooxml/writer.rb +22 -6
- data/lib/xlsxrb/ooxml/zip_generator.rb +2 -0
- data/lib/xlsxrb/ooxml/zip_reader.rb +47 -10
- data/lib/xlsxrb/stream_row.rb +97 -18
- data/lib/xlsxrb/stream_sheet.rb +706 -190
- data/lib/xlsxrb/stream_writer.rb +1893 -374
- data/lib/xlsxrb/style_builder.rb +774 -111
- data/lib/xlsxrb/utils.rb +66 -106
- data/lib/xlsxrb/version.rb +1 -1
- data/lib/xlsxrb/workbook_builder.rb +380 -83
- data/lib/xlsxrb/worksheet_builder.rb +1210 -233
- data/lib/xlsxrb.rb +1266 -326
- data/sig/generated/xlsxrb/chart_builder.rbs +319 -90
- data/sig/generated/xlsxrb/dsl_helpers.rbs +20 -2
- data/sig/generated/xlsxrb/elements/cell.rbs +92 -20
- data/sig/generated/xlsxrb/elements/column.rbs +61 -2
- data/sig/generated/xlsxrb/elements/coordinate_access.rbs +49 -7
- data/sig/generated/xlsxrb/elements/image.rbs +30 -8
- data/sig/generated/xlsxrb/elements/metadata.rbs +1587 -0
- data/sig/generated/xlsxrb/elements/row.rbs +61 -21
- data/sig/generated/xlsxrb/elements/styles.rbs +96 -58
- data/sig/generated/xlsxrb/elements/types.rbs +27 -0
- data/sig/generated/xlsxrb/elements/workbook.rbs +63 -52
- data/sig/generated/xlsxrb/elements/worksheet.rbs +192 -51
- data/sig/generated/xlsxrb/ooxml/reader/listeners/feature_listeners.rbs +61 -0
- data/sig/generated/xlsxrb/ooxml/reader.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +1 -1
- data/sig/generated/xlsxrb/ooxml/writer.rbs +3 -0
- data/sig/generated/xlsxrb/ooxml/zip_generator.rbs +2 -0
- data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +2 -2
- data/sig/generated/xlsxrb/stream_row.rbs +48 -14
- data/sig/generated/xlsxrb/stream_sheet.rbs +324 -115
- data/sig/generated/xlsxrb/stream_writer.rbs +1068 -255
- data/sig/generated/xlsxrb/style_builder.rbs +389 -79
- data/sig/generated/xlsxrb/utils.rbs +34 -18
- data/sig/generated/xlsxrb/workbook_builder.rbs +234 -34
- data/sig/generated/xlsxrb/worksheet_builder.rbs +628 -126
- data/sig/generated/xlsxrb.rbs +257 -49
- metadata +3 -1
data/lib/xlsxrb/stream_sheet.rb
CHANGED
|
@@ -57,8 +57,15 @@ module Xlsxrb
|
|
|
57
57
|
# @param pad_empty_rows [Boolean] Whether to yield empty rows for skipped row numbers.
|
|
58
58
|
# @param pad_empty_cells [Boolean] Whether to pad missing cells within rows.
|
|
59
59
|
# @param images [Array<Elements::Image>, nil] Optional preloaded images array.
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
# @param defined_names [Array<Hash, Elements::DefinedName>, nil] Optional workbook defined names.
|
|
61
|
+
# @param sheet_index [Integer, nil] 0-based worksheet index.
|
|
62
|
+
# @param charts [Array<Elements::Chart>, nil] Optional preloaded charts.
|
|
63
|
+
# @param sparkline_groups [Array<Elements::SparklineGroup>, nil] Optional preloaded sparkline groups.
|
|
64
|
+
# @param print_area [String, nil] Optional print area range.
|
|
65
|
+
# @param print_titles [Elements::PrintTitles, nil] Optional repeating print titles.
|
|
66
|
+
# @param header_footer_images [Array<Elements::HeaderFooterImage>, nil] Optional preloaded header/footer images.
|
|
67
|
+
#: (String name, untyped sheet_source, Array[String] shared_strings, ?(Elements::Styles | Hash[untyped, untyped])? styles, ?zip_reader: Ooxml::ZipReader?, ?entry_name: String?, ?state: Symbol, ?date1904: bool, ?dimension: String?, ?trim_empty_rows: bool, ?pad_empty_rows: bool, ?pad_empty_cells: bool, ?images: Array[Elements::Image]?, ?defined_names: Array[untyped]?, ?sheet_index: Integer?, ?charts: Array[Elements::Chart]?, ?sparkline_groups: Array[Elements::SparklineGroup]?, ?print_area: String?, ?print_titles: Elements::PrintTitles?, ?header_footer_images: Array[Elements::HeaderFooterImage]?) -> void
|
|
68
|
+
def initialize(name, sheet_source, shared_strings, styles = nil, zip_reader: nil, entry_name: nil, state: :visible, date1904: false, dimension: nil, trim_empty_rows: false, pad_empty_rows: false, pad_empty_cells: false, images: nil, defined_names: nil, sheet_index: nil, charts: nil, sparkline_groups: nil, print_area: nil, print_titles: nil, header_footer_images: nil)
|
|
62
69
|
@name = name
|
|
63
70
|
@sheet_source = sheet_source
|
|
64
71
|
@shared_strings = shared_strings
|
|
@@ -74,6 +81,13 @@ module Xlsxrb
|
|
|
74
81
|
@pad_empty_rows = pad_empty_rows ? true : false
|
|
75
82
|
@pad_empty_cells = pad_empty_cells ? true : false
|
|
76
83
|
@images = images
|
|
84
|
+
@defined_names = defined_names || []
|
|
85
|
+
@sheet_index = sheet_index
|
|
86
|
+
@charts = charts
|
|
87
|
+
@sparkline_groups = sparkline_groups
|
|
88
|
+
@print_area = print_area
|
|
89
|
+
@print_titles = print_titles
|
|
90
|
+
@header_footer_images = header_footer_images
|
|
77
91
|
end
|
|
78
92
|
|
|
79
93
|
# Returns whether trailing empty rows are omitted during iteration.
|
|
@@ -84,7 +98,13 @@ module Xlsxrb
|
|
|
84
98
|
def trim_empty_rows?
|
|
85
99
|
@trim_empty_rows ? true : false
|
|
86
100
|
end
|
|
87
|
-
|
|
101
|
+
|
|
102
|
+
# @deprecated Use {#trim_empty_rows?} instead. Will be removed in 0.2.0.
|
|
103
|
+
#: () -> bool
|
|
104
|
+
def trim_empty_rows
|
|
105
|
+
warn "[DEPRECATION] #trim_empty_rows is deprecated; use #trim_empty_rows? instead.", uplevel: 1
|
|
106
|
+
trim_empty_rows?
|
|
107
|
+
end
|
|
88
108
|
|
|
89
109
|
# Returns whether skipped rows are padded during iteration.
|
|
90
110
|
#
|
|
@@ -94,7 +114,13 @@ module Xlsxrb
|
|
|
94
114
|
def pad_empty_rows?
|
|
95
115
|
@pad_empty_rows ? true : false
|
|
96
116
|
end
|
|
97
|
-
|
|
117
|
+
|
|
118
|
+
# @deprecated Use {#pad_empty_rows?} instead. Will be removed in 0.2.0.
|
|
119
|
+
#: () -> bool
|
|
120
|
+
def pad_empty_rows
|
|
121
|
+
warn "[DEPRECATION] #pad_empty_rows is deprecated; use #pad_empty_rows? instead.", uplevel: 1
|
|
122
|
+
pad_empty_rows?
|
|
123
|
+
end
|
|
98
124
|
|
|
99
125
|
# Returns whether missing cells within rows are padded during iteration.
|
|
100
126
|
#
|
|
@@ -104,7 +130,13 @@ module Xlsxrb
|
|
|
104
130
|
def pad_empty_cells?
|
|
105
131
|
@pad_empty_cells ? true : false
|
|
106
132
|
end
|
|
107
|
-
|
|
133
|
+
|
|
134
|
+
# @deprecated Use {#pad_empty_cells?} instead. Will be removed in 0.2.0.
|
|
135
|
+
#: () -> bool
|
|
136
|
+
def pad_empty_cells
|
|
137
|
+
warn "[DEPRECATION] #pad_empty_cells is deprecated; use #pad_empty_cells? instead.", uplevel: 1
|
|
138
|
+
pad_empty_cells?
|
|
139
|
+
end
|
|
108
140
|
|
|
109
141
|
# Returns the dimension reference string (e.g. "A1:Z50000"), or nil if not present.
|
|
110
142
|
#
|
|
@@ -120,42 +152,106 @@ module Xlsxrb
|
|
|
120
152
|
|
|
121
153
|
# Returns the 1-based index of the first row defined in the sheet dimension, or nil.
|
|
122
154
|
#
|
|
155
|
+
# @deprecated Returning an Integer row number is deprecated and will be removed in 0.2.0. Use {#row_range} or {#dimension_bounds} for row boundaries.
|
|
123
156
|
# @return [Integer, nil]
|
|
124
157
|
# @api public
|
|
125
158
|
#: () -> Integer?
|
|
126
159
|
def first_row
|
|
127
|
-
dimension_bounds
|
|
160
|
+
bounds = dimension_bounds
|
|
161
|
+
bounds ? bounds[:min_row] + 1 : nil
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
# Returns the 0-based index of the first column defined in the sheet dimension, or nil.
|
|
165
|
+
#
|
|
166
|
+
# @return [Integer, nil]
|
|
167
|
+
# @api public
|
|
168
|
+
#: () -> Integer?
|
|
169
|
+
def first_column_index
|
|
170
|
+
Xlsxrb::Deprecation.warn("StreamSheet#first_column_index is deprecated; use #column_range instead.", uplevel: 1)
|
|
171
|
+
bounds = dimension_bounds
|
|
172
|
+
bounds ? bounds[:min_column] : nil
|
|
128
173
|
end
|
|
129
174
|
|
|
130
175
|
# Returns the 1-based index of the first column defined in the sheet dimension, or nil.
|
|
131
176
|
#
|
|
177
|
+
# @deprecated Use 0-based {#first_column_index} instead. Will be removed in 0.2.0.
|
|
132
178
|
# @return [Integer, nil]
|
|
133
179
|
# @api public
|
|
134
180
|
#: () -> Integer?
|
|
135
181
|
def first_column
|
|
136
|
-
|
|
182
|
+
warn "[Xlsxrb DEPRECATION] StreamSheet#first_column is deprecated and will be removed in v0.2.0. Use 0-based #first_column_index instead.", uplevel: 1
|
|
183
|
+
bounds = dimension_bounds
|
|
184
|
+
bounds ? bounds[:min_column] + 1 : nil
|
|
137
185
|
end
|
|
186
|
+
# @deprecated Use {#first_column_index} instead. Will be removed in 0.2.0.
|
|
138
187
|
alias first_col first_column
|
|
139
188
|
|
|
140
189
|
# Returns the 1-based index of the last row defined in the sheet dimension, or nil.
|
|
141
190
|
#
|
|
191
|
+
# @deprecated Returning an Integer row number is deprecated and will be removed in 0.2.0. Use {#row_range} or {#dimension_bounds} for row boundaries.
|
|
142
192
|
# @return [Integer, nil]
|
|
143
193
|
# @api public
|
|
144
194
|
#: () -> Integer?
|
|
145
195
|
def last_row
|
|
146
|
-
dimension_bounds
|
|
196
|
+
bounds = dimension_bounds
|
|
197
|
+
bounds ? bounds[:max_row] + 1 : nil
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
# Returns the 0-based index of the last column defined in the sheet dimension, or nil.
|
|
201
|
+
#
|
|
202
|
+
# @return [Integer, nil]
|
|
203
|
+
# @api public
|
|
204
|
+
#: () -> Integer?
|
|
205
|
+
def last_column_index
|
|
206
|
+
Xlsxrb::Deprecation.warn("StreamSheet#last_column_index is deprecated; use #column_range instead.", uplevel: 1)
|
|
207
|
+
bounds = dimension_bounds
|
|
208
|
+
bounds ? bounds[:max_column] : nil
|
|
147
209
|
end
|
|
148
210
|
|
|
149
211
|
# Returns the 1-based index of the last column defined in the sheet dimension, or nil.
|
|
150
212
|
#
|
|
213
|
+
# @deprecated Use 0-based {#last_column_index} instead. Will be removed in 0.2.0.
|
|
151
214
|
# @return [Integer, nil]
|
|
152
215
|
# @api public
|
|
153
216
|
#: () -> Integer?
|
|
154
217
|
def last_column
|
|
155
|
-
|
|
218
|
+
warn "[Xlsxrb DEPRECATION] StreamSheet#last_column is deprecated and will be removed in v0.2.0. Use 0-based #last_column_index instead.", uplevel: 1
|
|
219
|
+
bounds = dimension_bounds
|
|
220
|
+
bounds ? bounds[:max_column] + 1 : nil
|
|
156
221
|
end
|
|
222
|
+
# @deprecated Use {#last_column_index} instead. Will be removed in 0.2.0.
|
|
157
223
|
alias last_col last_column
|
|
158
224
|
|
|
225
|
+
# Returns the 0-based range of rows defined in the sheet dimension, or nil.
|
|
226
|
+
#
|
|
227
|
+
# @example
|
|
228
|
+
# sheet.row_range #=> 0..9
|
|
229
|
+
#
|
|
230
|
+
# @return [Range<Integer>, nil]
|
|
231
|
+
# @api public
|
|
232
|
+
#: () -> Range[Integer]?
|
|
233
|
+
def row_range
|
|
234
|
+
bounds = dimension_bounds
|
|
235
|
+
return nil unless bounds
|
|
236
|
+
|
|
237
|
+
(bounds[:min_row]..bounds[:max_row])
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
# Returns the 0-based range of columns defined in the sheet dimension, or nil.
|
|
241
|
+
#
|
|
242
|
+
# @example
|
|
243
|
+
# sheet.column_range #=> 0..4
|
|
244
|
+
#
|
|
245
|
+
# @return [Range<Integer>, nil]
|
|
246
|
+
# @api public
|
|
247
|
+
#: () -> Range[Integer]?
|
|
248
|
+
def column_range
|
|
249
|
+
bounds = dimension_bounds
|
|
250
|
+
return nil unless bounds
|
|
251
|
+
|
|
252
|
+
(bounds[:min_column]..bounds[:max_column])
|
|
253
|
+
end
|
|
254
|
+
|
|
159
255
|
# Returns whether the sheet uses the 1904 date system.
|
|
160
256
|
#
|
|
161
257
|
# @return [Boolean]
|
|
@@ -336,16 +432,25 @@ module Xlsxrb
|
|
|
336
432
|
comments: comments,
|
|
337
433
|
threaded_comments: threaded_comments,
|
|
338
434
|
images: images,
|
|
435
|
+
charts: charts,
|
|
436
|
+
sparkline_groups: sparkline_groups,
|
|
437
|
+
print_area: print_area,
|
|
438
|
+
print_titles: print_titles,
|
|
339
439
|
date1904: @date1904,
|
|
340
440
|
dimension: dimension,
|
|
341
441
|
trim_empty_rows: @trim_empty_rows,
|
|
342
442
|
pad_empty_rows: @pad_empty_rows,
|
|
343
443
|
pad_empty_cells: @pad_empty_cells,
|
|
444
|
+
columns: columns,
|
|
344
445
|
merged_cells: merged_cells,
|
|
345
446
|
auto_filter: auto_filter,
|
|
447
|
+
filter_columns: filter_columns,
|
|
448
|
+
sort_state: sort_state,
|
|
346
449
|
tables: tables,
|
|
450
|
+
pivot_tables: pivot_tables,
|
|
347
451
|
shapes: shapes,
|
|
348
452
|
freeze_pane: freeze_pane,
|
|
453
|
+
split_pane: split_pane,
|
|
349
454
|
page_setup: page_setup,
|
|
350
455
|
page_margins: page_margins,
|
|
351
456
|
header_footer: header_footer,
|
|
@@ -355,23 +460,30 @@ module Xlsxrb
|
|
|
355
460
|
sheet_properties: sheet_properties,
|
|
356
461
|
sheet_format: sheet_format,
|
|
357
462
|
row_breaks: row_breaks,
|
|
358
|
-
|
|
463
|
+
column_breaks: column_breaks,
|
|
359
464
|
protected_ranges: protected_ranges,
|
|
360
465
|
cell_watches: cell_watches,
|
|
361
466
|
ignored_errors: ignored_errors,
|
|
362
467
|
phonetic_properties: phonetic_properties,
|
|
363
468
|
selection: selection,
|
|
364
|
-
|
|
365
|
-
background_image: background_image
|
|
469
|
+
sheet_calc_properties: sheet_calc_properties,
|
|
470
|
+
background_image: background_image,
|
|
471
|
+
header_footer_images: header_footer_images
|
|
366
472
|
)
|
|
367
473
|
end
|
|
368
|
-
alias to_worksheet load
|
|
369
474
|
|
|
370
|
-
#
|
|
475
|
+
# @deprecated Use {Xlsxrb.load} instead. Will be removed in 0.2.0.
|
|
476
|
+
#: () -> Elements::Worksheet
|
|
477
|
+
def to_worksheet
|
|
478
|
+
warn "[DEPRECATION] #to_worksheet is deprecated; use Xlsxrb.load(source) instead.", uplevel: 1
|
|
479
|
+
load
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
# Returns hyperlinks configured for this worksheet as a Hash of cell references to {Elements::Hyperlink} objects.
|
|
371
483
|
#
|
|
372
|
-
# @return [Hash<String,
|
|
484
|
+
# @return [Hash<String, Elements::Hyperlink>]
|
|
373
485
|
# @api public
|
|
374
|
-
#: () -> Hash[String,
|
|
486
|
+
#: () -> Hash[String, Elements::Hyperlink]
|
|
375
487
|
def hyperlinks
|
|
376
488
|
@hyperlinks ||= Xlsxrb.send(:resolve_hyperlinks, raw_sheet_xml, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
377
489
|
end
|
|
@@ -379,38 +491,54 @@ module Xlsxrb
|
|
|
379
491
|
# Returns hyperlink metadata for a specific cell reference, or nil.
|
|
380
492
|
#
|
|
381
493
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
382
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
383
|
-
# @return [
|
|
494
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
495
|
+
# @return [Elements::Hyperlink, nil]
|
|
384
496
|
# @api public
|
|
385
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
497
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Hyperlink?
|
|
386
498
|
def hyperlink(ref_or_row, col = nil)
|
|
387
499
|
ref = if col
|
|
388
|
-
|
|
500
|
+
c_idx = Xlsxrb.column_index(col)
|
|
501
|
+
"#{Xlsxrb.column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
389
502
|
else
|
|
390
503
|
ref_or_row.to_s.upcase
|
|
391
504
|
end
|
|
392
505
|
hyperlinks[ref]
|
|
393
506
|
end
|
|
394
507
|
|
|
395
|
-
# Returns comments configured for this worksheet as an Array of
|
|
508
|
+
# Returns comments configured for this worksheet as an Array of {Elements::Comment} objects.
|
|
396
509
|
#
|
|
397
|
-
# @return [Array<
|
|
510
|
+
# @return [Array<Elements::Comment>]
|
|
398
511
|
# @api public
|
|
399
|
-
#: () -> Array[
|
|
512
|
+
#: () -> Array[Elements::Comment]
|
|
400
513
|
def comments
|
|
401
|
-
@comments ||=
|
|
514
|
+
@comments ||= begin
|
|
515
|
+
raw = Xlsxrb.send(:resolve_comments, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
516
|
+
raw.map do |c|
|
|
517
|
+
if c.is_a?(Elements::Comment)
|
|
518
|
+
c
|
|
519
|
+
else
|
|
520
|
+
Elements::Comment.new(
|
|
521
|
+
ref: c[:ref] || c[:cell],
|
|
522
|
+
author: c[:author],
|
|
523
|
+
text: c[:text],
|
|
524
|
+
visible: c[:visible] || false
|
|
525
|
+
)
|
|
526
|
+
end
|
|
527
|
+
end.freeze
|
|
528
|
+
end
|
|
402
529
|
end
|
|
403
530
|
|
|
404
531
|
# Returns comment metadata for a specific cell reference, or nil.
|
|
405
532
|
#
|
|
406
533
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
407
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
408
|
-
# @return [
|
|
534
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
535
|
+
# @return [Elements::Comment, nil]
|
|
409
536
|
# @api public
|
|
410
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
537
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Comment?
|
|
411
538
|
def comment(ref_or_row, col = nil)
|
|
412
539
|
ref = if col
|
|
413
|
-
|
|
540
|
+
c_idx = Xlsxrb.column_index(col)
|
|
541
|
+
"#{Xlsxrb.column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
414
542
|
else
|
|
415
543
|
ref_or_row.to_s.upcase
|
|
416
544
|
end
|
|
@@ -419,35 +547,70 @@ module Xlsxrb
|
|
|
419
547
|
|
|
420
548
|
# Returns comments indexed by cell reference.
|
|
421
549
|
#
|
|
422
|
-
# @return [Hash<String,
|
|
550
|
+
# @return [Hash<String, Elements::Comment>]
|
|
423
551
|
# @api public
|
|
424
|
-
#: () -> Hash[String,
|
|
552
|
+
#: () -> Hash[String, Elements::Comment]
|
|
425
553
|
def comments_by_ref
|
|
426
554
|
@comments_by_ref ||= comments.each_with_object({}) do |c, acc|
|
|
427
|
-
r = c[:ref] || c[:cell]
|
|
555
|
+
r = c.respond_to?(:ref) ? c.ref : (c[:ref] || c[:cell])
|
|
428
556
|
acc[r.to_s.upcase] = c if r
|
|
429
|
-
end
|
|
557
|
+
end.freeze
|
|
430
558
|
end
|
|
431
559
|
|
|
432
|
-
# Returns threaded comments configured for this worksheet as an Array of
|
|
560
|
+
# Returns threaded comments configured for this worksheet as an Array of {Elements::ThreadedComment} objects.
|
|
433
561
|
#
|
|
434
|
-
# @return [Array<
|
|
562
|
+
# @return [Array<Elements::ThreadedComment>]
|
|
435
563
|
# @api public
|
|
436
|
-
#: () -> Array[
|
|
564
|
+
#: () -> Array[Elements::ThreadedComment]
|
|
437
565
|
def threaded_comments
|
|
438
|
-
@threaded_comments ||=
|
|
566
|
+
@threaded_comments ||= begin
|
|
567
|
+
raw = Xlsxrb.send(:resolve_threaded_comments, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
568
|
+
raw.map do |tc|
|
|
569
|
+
if tc.is_a?(Elements::ThreadedComment)
|
|
570
|
+
tc
|
|
571
|
+
else
|
|
572
|
+
Elements::ThreadedComment.new(
|
|
573
|
+
id: tc[:id],
|
|
574
|
+
ref: tc[:ref] || tc[:cell],
|
|
575
|
+
author: tc[:author],
|
|
576
|
+
text: tc[:text],
|
|
577
|
+
parent_id: tc[:parent_id],
|
|
578
|
+
done: tc[:done] || false,
|
|
579
|
+
created_at: tc[:created_at]
|
|
580
|
+
)
|
|
581
|
+
end
|
|
582
|
+
end.freeze
|
|
583
|
+
end
|
|
439
584
|
end
|
|
440
585
|
|
|
441
|
-
# Returns threaded
|
|
586
|
+
# Returns the root threaded comment for a specific cell reference, or nil.
|
|
442
587
|
#
|
|
443
588
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
444
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
445
|
-
# @return [
|
|
589
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
590
|
+
# @return [Elements::ThreadedComment, nil]
|
|
446
591
|
# @api public
|
|
447
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
592
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::ThreadedComment?
|
|
448
593
|
def threaded_comment(ref_or_row, col = nil)
|
|
449
594
|
ref = if col
|
|
450
|
-
|
|
595
|
+
c_idx = Xlsxrb.column_index(col)
|
|
596
|
+
"#{Xlsxrb.column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
597
|
+
else
|
|
598
|
+
ref_or_row.to_s.upcase
|
|
599
|
+
end
|
|
600
|
+
threaded_comments_by_ref[ref]&.first
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
# Returns threaded comments for a specific cell reference, or empty array.
|
|
604
|
+
#
|
|
605
|
+
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
606
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
607
|
+
# @return [Array<Elements::ThreadedComment>]
|
|
608
|
+
# @api public
|
|
609
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Array[Elements::ThreadedComment]
|
|
610
|
+
def threaded_comments_at(ref_or_row, col = nil)
|
|
611
|
+
ref = if col
|
|
612
|
+
c_idx = Xlsxrb.column_index(col)
|
|
613
|
+
"#{Xlsxrb.column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
451
614
|
else
|
|
452
615
|
ref_or_row.to_s.upcase
|
|
453
616
|
end
|
|
@@ -456,14 +619,14 @@ module Xlsxrb
|
|
|
456
619
|
|
|
457
620
|
# Returns threaded comments indexed by cell reference.
|
|
458
621
|
#
|
|
459
|
-
# @return [Hash<String, Array<
|
|
622
|
+
# @return [Hash<String, Array<Elements::ThreadedComment>>]
|
|
460
623
|
# @api public
|
|
461
|
-
#: () -> Hash[String, Array[
|
|
624
|
+
#: () -> Hash[String, Array[Elements::ThreadedComment]]
|
|
462
625
|
def threaded_comments_by_ref
|
|
463
626
|
@threaded_comments_by_ref ||= threaded_comments.each_with_object({}) do |c, acc|
|
|
464
|
-
r = c
|
|
627
|
+
r = c.ref
|
|
465
628
|
(acc[r.to_s.upcase] ||= []) << c if r
|
|
466
|
-
end
|
|
629
|
+
end.freeze
|
|
467
630
|
end
|
|
468
631
|
|
|
469
632
|
# Returns all embedded images in this worksheet.
|
|
@@ -478,21 +641,23 @@ module Xlsxrb
|
|
|
478
641
|
# Returns all images anchored at a specific cell reference or 0-based coordinate.
|
|
479
642
|
#
|
|
480
643
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
481
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
644
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter/Symbol.
|
|
482
645
|
# @return [Array<Elements::Image>]
|
|
483
646
|
# @api public
|
|
484
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
647
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Array[Elements::Image]
|
|
485
648
|
def images_at(ref_or_row, col = nil)
|
|
486
649
|
ref = if col
|
|
487
|
-
|
|
650
|
+
c_idx = Xlsxrb.column_index(col)
|
|
651
|
+
"#{Xlsxrb.column_letter(c_idx)}#{ref_or_row.to_i + 1}"
|
|
488
652
|
else
|
|
489
653
|
ref_or_row.to_s.upcase
|
|
490
654
|
end
|
|
491
|
-
images.select { |img| img.
|
|
655
|
+
images.select { |img| img.ref == ref }
|
|
492
656
|
end
|
|
493
657
|
|
|
494
658
|
# Loads and returns images for this worksheet, optionally yielding self for block syntax.
|
|
495
659
|
#
|
|
660
|
+
# @deprecated Access {#images} directly. Lazy-loading is automatic. Will be removed in 0.2.0.
|
|
496
661
|
# @yield [sheet]
|
|
497
662
|
# @yieldparam sheet [StreamSheet]
|
|
498
663
|
# @return [StreamSheet, void]
|
|
@@ -500,6 +665,7 @@ module Xlsxrb
|
|
|
500
665
|
#: () { (StreamSheet) -> void } -> void
|
|
501
666
|
#: () -> StreamSheet
|
|
502
667
|
def with_images
|
|
668
|
+
warn "[DEPRECATION] `with_images` is deprecated; access `images` directly.", uplevel: 1
|
|
503
669
|
images
|
|
504
670
|
if block_given?
|
|
505
671
|
yield self
|
|
@@ -511,16 +677,19 @@ module Xlsxrb
|
|
|
511
677
|
|
|
512
678
|
# Access a cell by reference or 0-based coordinates.
|
|
513
679
|
#
|
|
680
|
+
# @deprecated Use `ws = Xlsxrb.load(source)` to materialize an {Elements::Worksheet} and use {Elements::CoordinateAccess#[]} (e.g. ws["A1"] or ws[0, 0]). Will be removed in 0.2.0.
|
|
514
681
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
515
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
682
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter.
|
|
516
683
|
# @return [Elements::Cell, nil]
|
|
517
684
|
# @api public
|
|
518
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
685
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Cell?
|
|
519
686
|
def cell(ref_or_row, col = nil)
|
|
687
|
+
warn "[DEPRECATION] StreamSheet#cell is deprecated; use Xlsxrb.load(source) for in-memory random access (e.g. ws[\"A1\"]).", uplevel: 1
|
|
520
688
|
target_row, target_col = if col
|
|
521
|
-
|
|
689
|
+
c_idx = Xlsxrb.column_index(col)
|
|
690
|
+
[ref_or_row.to_i, c_idx]
|
|
522
691
|
else
|
|
523
|
-
parsed = Elements::Cell.
|
|
692
|
+
parsed = Elements::Cell._parse_ref(ref_or_row.to_s)
|
|
524
693
|
return nil unless parsed
|
|
525
694
|
|
|
526
695
|
parsed
|
|
@@ -536,12 +705,14 @@ module Xlsxrb
|
|
|
536
705
|
|
|
537
706
|
# Returns the formatted string representation of a cell's value.
|
|
538
707
|
#
|
|
708
|
+
# @deprecated Use `ws = Xlsxrb.load(source)` to materialize an {Elements::Worksheet} and access `ws["A1"].formatted_value`. Will be removed in 0.2.0.
|
|
539
709
|
# @param ref_or_row [String, Symbol, Integer] Cell reference (e.g. "A1") or 0-based row index.
|
|
540
|
-
# @param col [Integer, nil] Optional 0-based column index.
|
|
710
|
+
# @param col [Integer, String, Symbol, nil] Optional 0-based column index or column letter.
|
|
541
711
|
# @return [String, nil]
|
|
542
712
|
# @api public
|
|
543
|
-
#: (String | Symbol | Integer ref_or_row, ?Integer
|
|
713
|
+
#: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> String?
|
|
544
714
|
def formatted_value(ref_or_row, col = nil)
|
|
715
|
+
warn "[DEPRECATION] StreamSheet#formatted_value is deprecated; use Xlsxrb.load(source) for in-memory random access (e.g. ws[\"A1\"].formatted_value).", uplevel: 1
|
|
545
716
|
cell(ref_or_row, col)&.formatted_value
|
|
546
717
|
end
|
|
547
718
|
|
|
@@ -551,11 +722,13 @@ module Xlsxrb
|
|
|
551
722
|
# @api public
|
|
552
723
|
#: () -> Array[String]
|
|
553
724
|
def merged_cells
|
|
554
|
-
@merged_cells ||=
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
725
|
+
@merged_cells ||= if raw_sheet_xml.include?("<mergeCell") || raw_sheet_xml.include?(":mergeCell")
|
|
726
|
+
listener = Ooxml::Reader::MergeCellsListener.new
|
|
727
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
728
|
+
listener.ranges
|
|
729
|
+
else
|
|
730
|
+
[].freeze
|
|
731
|
+
end
|
|
559
732
|
end
|
|
560
733
|
|
|
561
734
|
# Returns the auto-filter range (e.g. "A1:E100") for this worksheet, or nil if none.
|
|
@@ -564,111 +737,231 @@ module Xlsxrb
|
|
|
564
737
|
# @api public
|
|
565
738
|
#: () -> String?
|
|
566
739
|
def auto_filter
|
|
567
|
-
@auto_filter ||=
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
740
|
+
@auto_filter ||= auto_filter_data[:ref]
|
|
741
|
+
end
|
|
742
|
+
|
|
743
|
+
# Returns column filter rules defined for this worksheet.
|
|
744
|
+
#
|
|
745
|
+
# @return [Hash<Integer, Elements::FilterColumn>]
|
|
746
|
+
# @api public
|
|
747
|
+
#: () -> Hash[Integer, Elements::FilterColumn]
|
|
748
|
+
def filter_columns
|
|
749
|
+
@filter_columns ||= (auto_filter_data[:filter_columns] || {}).to_h do |col_id, filter|
|
|
750
|
+
fc = if filter.is_a?(Elements::FilterColumn)
|
|
751
|
+
filter
|
|
752
|
+
else
|
|
753
|
+
Elements::FilterColumn.new(
|
|
754
|
+
column_id: filter[:column_id] || filter[:col_id] || col_id,
|
|
755
|
+
hidden: filter[:hidden] || false,
|
|
756
|
+
show_button: filter[:show_button] != false,
|
|
757
|
+
filters: filter[:filters] || [],
|
|
758
|
+
custom_filters: filter[:custom_filters] || [],
|
|
759
|
+
top10: filter[:top10],
|
|
760
|
+
dynamic_filter: filter[:dynamic_filter],
|
|
761
|
+
color_filter: filter[:color_filter],
|
|
762
|
+
icon_filter: filter[:icon_filter]
|
|
763
|
+
)
|
|
764
|
+
end
|
|
765
|
+
[col_id, fc]
|
|
766
|
+
end.freeze
|
|
572
767
|
end
|
|
573
768
|
|
|
574
769
|
# Returns data validation rules configured for this worksheet.
|
|
575
770
|
#
|
|
576
|
-
# @return [Array<
|
|
771
|
+
# @return [Array<Elements::DataValidation>]
|
|
577
772
|
# @api public
|
|
578
|
-
#: () -> Array[
|
|
773
|
+
#: () -> Array[Elements::DataValidation]
|
|
579
774
|
def data_validations
|
|
580
|
-
@data_validations ||=
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
775
|
+
@data_validations ||= if raw_sheet_xml.include?("<dataValidation") || raw_sheet_xml.include?(":dataValidation")
|
|
776
|
+
listener = Ooxml::Reader::DataValidationsListener.new
|
|
777
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
778
|
+
listener.validations.map do |dv|
|
|
779
|
+
dv.is_a?(Elements::DataValidation) ? dv : Elements::DataValidation.new(**dv)
|
|
780
|
+
end.freeze
|
|
781
|
+
else
|
|
782
|
+
[].freeze
|
|
783
|
+
end
|
|
585
784
|
end
|
|
586
785
|
|
|
587
786
|
# Returns conditional formatting rules configured for this worksheet.
|
|
588
787
|
#
|
|
589
|
-
#
|
|
788
|
+
# Corresponds to ECMA-376 Part 4 §18.3.1.18 (<conditionalFormatting> and <cfRule> elements).
|
|
789
|
+
#
|
|
790
|
+
# @return [Array<Elements::ConditionalFormat>]
|
|
590
791
|
# @api public
|
|
591
|
-
#: () -> Array[
|
|
792
|
+
#: () -> Array[Elements::ConditionalFormat]
|
|
592
793
|
def conditional_formats
|
|
593
|
-
@conditional_formats ||=
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
794
|
+
@conditional_formats ||= if raw_sheet_xml.include?("<conditionalFormatting") || raw_sheet_xml.include?(":conditionalFormatting")
|
|
795
|
+
listener = Ooxml::Reader::ConditionalFormattingListener.new
|
|
796
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
797
|
+
listener.rules.map do |cf|
|
|
798
|
+
if cf.is_a?(Elements::ConditionalFormat)
|
|
799
|
+
cf
|
|
800
|
+
else
|
|
801
|
+
rules = (cf[:rules] || []).map { |r| r.is_a?(Elements::ConditionalFormatRule) ? r : Elements::ConditionalFormatRule.new(**r) }
|
|
802
|
+
Elements::ConditionalFormat.new(**cf, rules: rules)
|
|
803
|
+
end
|
|
804
|
+
end.freeze
|
|
805
|
+
else
|
|
806
|
+
[].freeze
|
|
807
|
+
end
|
|
598
808
|
end
|
|
809
|
+
# @deprecated Use {#conditional_formats} instead. Matches the ECMA-376 XML element name (<conditionalFormatting>), but {#conditional_formats} is canonical in xlsxrb. Will be removed in version 0.2.0.
|
|
599
810
|
alias conditional_formatting conditional_formats
|
|
600
811
|
|
|
601
812
|
# Returns tables defined in this worksheet.
|
|
602
813
|
#
|
|
603
|
-
# @return [Array<
|
|
814
|
+
# @return [Array<Elements::Table>]
|
|
604
815
|
# @api public
|
|
605
|
-
#: () -> Array[
|
|
816
|
+
#: () -> Array[Elements::Table]
|
|
606
817
|
def tables
|
|
607
|
-
@tables ||=
|
|
818
|
+
@tables ||= begin
|
|
819
|
+
raw = Xlsxrb.send(:resolve_tables, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
820
|
+
raw.map do |tb|
|
|
821
|
+
if tb.is_a?(Elements::Table)
|
|
822
|
+
tb
|
|
823
|
+
else
|
|
824
|
+
cols = (tb[:columns] || []).map { |col| col.is_a?(Elements::TableColumn) ? col : Elements::TableColumn.new(**col) }
|
|
825
|
+
si = tb[:style_info]
|
|
826
|
+
si = Elements::TableStyleInfo.new(**si) if si.is_a?(Hash)
|
|
827
|
+
Elements::Table.new(**tb, columns: cols, style_info: si)
|
|
828
|
+
end
|
|
829
|
+
end.freeze
|
|
830
|
+
end
|
|
831
|
+
end
|
|
832
|
+
|
|
833
|
+
# Returns pivot tables defined in this worksheet.
|
|
834
|
+
#
|
|
835
|
+
# @return [Array<Elements::PivotTable>]
|
|
836
|
+
# @api public
|
|
837
|
+
#: () -> Array[Elements::PivotTable]
|
|
838
|
+
def pivot_tables
|
|
839
|
+
@pivot_tables ||= begin
|
|
840
|
+
raw = Xlsxrb.send(:resolve_pivot_tables, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
841
|
+
raw.map do |pt|
|
|
842
|
+
pt.is_a?(Elements::PivotTable) ? pt : Elements::PivotTable.new(**pt)
|
|
843
|
+
end.freeze
|
|
844
|
+
end
|
|
608
845
|
end
|
|
609
846
|
|
|
610
847
|
# Returns shapes defined in this worksheet.
|
|
611
848
|
#
|
|
612
|
-
# @return [Array<
|
|
849
|
+
# @return [Array<Elements::Shape>]
|
|
613
850
|
# @api public
|
|
614
|
-
#: () -> Array[
|
|
851
|
+
#: () -> Array[Elements::Shape]
|
|
615
852
|
def shapes
|
|
616
|
-
@shapes ||=
|
|
853
|
+
@shapes ||= begin
|
|
854
|
+
raw = Xlsxrb.send(:resolve_shapes, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
855
|
+
raw.map do |s|
|
|
856
|
+
s.is_a?(Elements::Shape) ? s : Elements::Shape.new(**s)
|
|
857
|
+
end.freeze
|
|
858
|
+
end
|
|
617
859
|
end
|
|
618
860
|
|
|
619
861
|
# Returns freeze pane settings for this worksheet, or nil if none.
|
|
620
862
|
#
|
|
621
|
-
# @return [
|
|
863
|
+
# @return [Elements::FreezePane, nil]
|
|
622
864
|
# @api public
|
|
623
|
-
#: () ->
|
|
865
|
+
#: () -> Elements::FreezePane?
|
|
624
866
|
def freeze_pane
|
|
625
|
-
sheet_view_data[:pane]
|
|
867
|
+
pane = sheet_view_data[:pane]
|
|
868
|
+
return unless pane && pane[:state] == :frozen
|
|
869
|
+
|
|
870
|
+
pane.is_a?(Elements::FreezePane) ? pane : Elements::FreezePane.new(**pane)
|
|
871
|
+
end
|
|
872
|
+
|
|
873
|
+
# Returns split pane settings for this worksheet, or nil if none.
|
|
874
|
+
#
|
|
875
|
+
# @return [Elements::SplitPane, nil]
|
|
876
|
+
# @api public
|
|
877
|
+
#: () -> Elements::SplitPane?
|
|
878
|
+
def split_pane
|
|
879
|
+
pane = sheet_view_data[:pane]
|
|
880
|
+
return unless pane && pane[:state] != :frozen
|
|
881
|
+
|
|
882
|
+
pane.is_a?(Elements::SplitPane) ? pane : Elements::SplitPane.new(**pane)
|
|
626
883
|
end
|
|
627
884
|
|
|
628
885
|
# Returns sheet view properties for this worksheet.
|
|
629
886
|
#
|
|
630
|
-
# @return [
|
|
887
|
+
# @return [Elements::SheetView]
|
|
631
888
|
# @api public
|
|
632
|
-
#: () ->
|
|
889
|
+
#: () -> Elements::SheetView
|
|
633
890
|
def sheet_view
|
|
634
|
-
sheet_view_data[:view] || {}
|
|
891
|
+
v = sheet_view_data[:view] || {}
|
|
892
|
+
v.is_a?(Elements::SheetView) ? v : Elements::SheetView.new(**v)
|
|
893
|
+
end
|
|
894
|
+
|
|
895
|
+
# Returns sheet views for this worksheet.
|
|
896
|
+
#
|
|
897
|
+
# @return [Array<Elements::SheetView>]
|
|
898
|
+
# @api public
|
|
899
|
+
#: () -> Array[Elements::SheetView]
|
|
900
|
+
def sheet_views
|
|
901
|
+
Xlsxrb::Deprecation.warn("StreamSheet#sheet_views is deprecated; use #sheet_view instead.", uplevel: 1)
|
|
902
|
+
[sheet_view]
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
# Returns sort state configuration for this worksheet, or nil if none.
|
|
906
|
+
#
|
|
907
|
+
# @return [Elements::SortState, nil]
|
|
908
|
+
# @api public
|
|
909
|
+
#: () -> Elements::SortState?
|
|
910
|
+
def sort_state
|
|
911
|
+
@sort_state ||= if raw_sheet_xml.include?("<sortState")
|
|
912
|
+
listener = Ooxml::Reader::SortStateListener.new
|
|
913
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
914
|
+
st = listener.sort_state
|
|
915
|
+
if st
|
|
916
|
+
st.is_a?(Elements::SortState) ? st : Elements::SortState.new(**st)
|
|
917
|
+
end
|
|
918
|
+
end
|
|
635
919
|
end
|
|
636
920
|
|
|
637
921
|
# Returns selection settings for this worksheet, or nil if none.
|
|
638
922
|
#
|
|
639
|
-
# @return [
|
|
923
|
+
# @return [Elements::Selection, nil]
|
|
640
924
|
# @api public
|
|
641
|
-
#: () ->
|
|
925
|
+
#: () -> Elements::Selection?
|
|
642
926
|
def selection
|
|
643
|
-
sheet_view_data[:selection]
|
|
927
|
+
sel = sheet_view_data[:selection]
|
|
928
|
+
return unless sel
|
|
929
|
+
|
|
930
|
+
sel.is_a?(Elements::Selection) ? sel : Elements::Selection.new(**sel)
|
|
644
931
|
end
|
|
645
932
|
|
|
646
933
|
# Returns sheet protection settings as a hash, or nil if unprotected.
|
|
647
934
|
#
|
|
648
|
-
# @return [
|
|
935
|
+
# @return [Elements::SheetProtection, nil]
|
|
649
936
|
# @api public
|
|
650
|
-
#: () ->
|
|
937
|
+
#: () -> Elements::SheetProtection?
|
|
651
938
|
def sheet_protection
|
|
652
939
|
@sheet_protection ||= if raw_sheet_xml.include?("<sheetProtection")
|
|
653
940
|
listener = Ooxml::Reader::SheetProtectionListener.new
|
|
654
941
|
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
655
|
-
listener.protection
|
|
942
|
+
sp = listener.protection
|
|
943
|
+
if sp
|
|
944
|
+
sp.is_a?(Elements::SheetProtection) ? sp : Elements::SheetProtection.new(**sp)
|
|
945
|
+
end
|
|
656
946
|
end
|
|
657
947
|
end
|
|
658
948
|
|
|
659
949
|
# Returns sheet-level properties (tabColor, outlinePr, sheetPr) for this worksheet.
|
|
660
950
|
#
|
|
661
|
-
# @return [
|
|
951
|
+
# @return [Elements::SheetProperties]
|
|
662
952
|
# @api public
|
|
663
|
-
#: () ->
|
|
953
|
+
#: () -> Elements::SheetProperties
|
|
664
954
|
def sheet_properties
|
|
665
|
-
@sheet_properties ||=
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
955
|
+
@sheet_properties ||= begin
|
|
956
|
+
raw = if raw_sheet_xml.include?("<sheetPr") || raw_sheet_xml.include?("<sheetCalcPr")
|
|
957
|
+
listener = Ooxml::Reader::SheetPropertiesListener.new
|
|
958
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
959
|
+
listener.properties
|
|
960
|
+
else
|
|
961
|
+
{}
|
|
962
|
+
end
|
|
963
|
+
raw.is_a?(Elements::SheetProperties) ? raw : Elements::SheetProperties.new(**raw)
|
|
964
|
+
end
|
|
672
965
|
end
|
|
673
966
|
|
|
674
967
|
# Returns the internal VBA or application code name of the worksheet, or nil if not specified.
|
|
@@ -677,7 +970,7 @@ module Xlsxrb
|
|
|
677
970
|
# @api public
|
|
678
971
|
#: () -> String?
|
|
679
972
|
def code_name
|
|
680
|
-
sheet_properties
|
|
973
|
+
sheet_properties.code_name
|
|
681
974
|
end
|
|
682
975
|
|
|
683
976
|
# Returns whether fit-to-page is enabled for page setup on this worksheet.
|
|
@@ -686,9 +979,15 @@ module Xlsxrb
|
|
|
686
979
|
# @api public
|
|
687
980
|
#: () -> bool
|
|
688
981
|
def fit_to_page?
|
|
689
|
-
sheet_properties
|
|
982
|
+
sheet_properties.fit_to_page == true
|
|
983
|
+
end
|
|
984
|
+
|
|
985
|
+
# @deprecated Use {#fit_to_page?} instead. Will be removed in 0.2.0.
|
|
986
|
+
#: () -> bool
|
|
987
|
+
def fit_to_page
|
|
988
|
+
warn "[DEPRECATION] #fit_to_page is deprecated; use #fit_to_page? instead.", uplevel: 1
|
|
989
|
+
fit_to_page?
|
|
690
990
|
end
|
|
691
|
-
alias fit_to_page fit_to_page?
|
|
692
991
|
|
|
693
992
|
# Returns whether full calculation on load is enabled on this worksheet.
|
|
694
993
|
#
|
|
@@ -696,19 +995,38 @@ module Xlsxrb
|
|
|
696
995
|
# @api public
|
|
697
996
|
#: () -> bool
|
|
698
997
|
def full_calc_on_load?
|
|
699
|
-
|
|
998
|
+
sheet_calc_properties&.full_calc_on_load == true || sheet_properties.full_calc_on_load == true
|
|
999
|
+
end
|
|
1000
|
+
|
|
1001
|
+
# @deprecated Use {#full_calc_on_load?} instead. Will be removed in 0.2.0.
|
|
1002
|
+
#: () -> bool
|
|
1003
|
+
def full_calc_on_load
|
|
1004
|
+
warn "[DEPRECATION] #full_calc_on_load is deprecated; use #full_calc_on_load? instead.", uplevel: 1
|
|
1005
|
+
full_calc_on_load?
|
|
700
1006
|
end
|
|
701
|
-
alias full_calc_on_load full_calc_on_load?
|
|
702
1007
|
|
|
703
1008
|
# Returns sheet calculation properties (<sheetCalcPr>), or nil if not present.
|
|
704
1009
|
#
|
|
705
|
-
# @return [
|
|
1010
|
+
# @return [Elements::SheetCalcProperties, nil]
|
|
706
1011
|
# @api public
|
|
707
|
-
#: () ->
|
|
1012
|
+
#: () -> Elements::SheetCalcProperties?
|
|
1013
|
+
def sheet_calc_properties
|
|
1014
|
+
sheet_properties.full_calc_on_load ? Elements::SheetCalcProperties.new(full_calc_on_load: true) : nil
|
|
1015
|
+
end
|
|
1016
|
+
|
|
1017
|
+
# @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
|
|
1018
|
+
#: () -> Elements::SheetCalcProperties?
|
|
708
1019
|
def sheet_calc_pr
|
|
709
|
-
|
|
1020
|
+
warn "[DEPRECATION] #sheet_calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
|
|
1021
|
+
sheet_calc_properties
|
|
1022
|
+
end
|
|
1023
|
+
|
|
1024
|
+
# @deprecated Use {#sheet_calc_properties} instead. Will be removed in 0.2.0.
|
|
1025
|
+
#: () -> Elements::SheetCalcProperties?
|
|
1026
|
+
def calc_pr
|
|
1027
|
+
warn "[DEPRECATION] #calc_pr is deprecated; use #sheet_calc_properties instead.", uplevel: 1
|
|
1028
|
+
sheet_calc_properties
|
|
710
1029
|
end
|
|
711
|
-
alias calc_pr sheet_calc_pr
|
|
712
1030
|
|
|
713
1031
|
# Returns the worksheet tab color specification, or nil if not set.
|
|
714
1032
|
#
|
|
@@ -717,6 +1035,7 @@ module Xlsxrb
|
|
|
717
1035
|
#: () -> (String | Hash[Symbol, untyped])?
|
|
718
1036
|
def tab_color
|
|
719
1037
|
props = sheet_properties
|
|
1038
|
+
props = props.to_h if props.is_a?(Elements::MetadataRecord)
|
|
720
1039
|
return props[:tab_color] if props[:tab_color]
|
|
721
1040
|
return { theme: props[:tab_color_theme], tint: props[:tab_color_tint] } if props[:tab_color_theme]
|
|
722
1041
|
return { indexed: props[:tab_color_indexed] } if props[:tab_color_indexed]
|
|
@@ -732,6 +1051,7 @@ module Xlsxrb
|
|
|
732
1051
|
#: () -> Hash[Symbol, untyped]
|
|
733
1052
|
def outline_properties
|
|
734
1053
|
props = sheet_properties
|
|
1054
|
+
props = props.to_h if props.is_a?(Elements::MetadataRecord)
|
|
735
1055
|
return props[:outline_properties] if props[:outline_properties]
|
|
736
1056
|
|
|
737
1057
|
res = {}
|
|
@@ -741,89 +1061,120 @@ module Xlsxrb
|
|
|
741
1061
|
res[:apply_styles] = props[:apply_styles] unless props[:apply_styles].nil?
|
|
742
1062
|
res
|
|
743
1063
|
end
|
|
1064
|
+
# @deprecated Use {#outline_properties} instead. Will be removed in 0.2.0.
|
|
744
1065
|
alias outline_pr outline_properties
|
|
745
1066
|
|
|
746
1067
|
# Returns sheet format properties (defaultRowHeight, defaultColWidth, baseColWidth) for this worksheet.
|
|
747
1068
|
#
|
|
748
|
-
# @return [
|
|
1069
|
+
# @return [Elements::SheetFormat]
|
|
749
1070
|
# @api public
|
|
750
|
-
#: () ->
|
|
1071
|
+
#: () -> Elements::SheetFormat
|
|
751
1072
|
def sheet_format
|
|
752
|
-
@sheet_format ||=
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1073
|
+
@sheet_format ||= begin
|
|
1074
|
+
raw = if raw_sheet_xml.include?("<sheetFormatPr")
|
|
1075
|
+
listener = Ooxml::Reader::SheetFormatListener.new
|
|
1076
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
1077
|
+
listener.properties
|
|
1078
|
+
else
|
|
1079
|
+
{}
|
|
1080
|
+
end
|
|
1081
|
+
raw.is_a?(Elements::SheetFormat) ? raw : Elements::SheetFormat.new(**raw)
|
|
1082
|
+
end
|
|
759
1083
|
end
|
|
760
1084
|
|
|
761
1085
|
# Returns page setup configurations for this worksheet.
|
|
762
1086
|
#
|
|
763
|
-
# @return [
|
|
1087
|
+
# @return [Elements::PageSetup]
|
|
764
1088
|
# @api public
|
|
765
|
-
#: () ->
|
|
1089
|
+
#: () -> Elements::PageSetup
|
|
766
1090
|
def page_setup
|
|
767
|
-
|
|
1091
|
+
@page_setup ||= begin
|
|
1092
|
+
ps = print_page_data[:page_setup] || {}
|
|
1093
|
+
ps.is_a?(Elements::PageSetup) ? ps : Elements::PageSetup.new(**ps)
|
|
1094
|
+
end
|
|
768
1095
|
end
|
|
769
1096
|
|
|
770
1097
|
# Returns page margins for this worksheet, or nil if none.
|
|
771
1098
|
#
|
|
772
|
-
# @return [
|
|
1099
|
+
# @return [Elements::PageMargins, nil]
|
|
773
1100
|
# @api public
|
|
774
|
-
#: () ->
|
|
1101
|
+
#: () -> Elements::PageMargins?
|
|
775
1102
|
def page_margins
|
|
776
|
-
|
|
1103
|
+
@page_margins ||= begin
|
|
1104
|
+
pm = print_page_data[:page_margins]
|
|
1105
|
+
if pm
|
|
1106
|
+
pm.is_a?(Elements::PageMargins) ? pm : Elements::PageMargins.new(**pm)
|
|
1107
|
+
end
|
|
1108
|
+
end
|
|
777
1109
|
end
|
|
778
1110
|
|
|
779
1111
|
# Returns header/footer configurations for this worksheet.
|
|
780
1112
|
#
|
|
781
|
-
# @return [
|
|
1113
|
+
# @return [Elements::HeaderFooter]
|
|
782
1114
|
# @api public
|
|
783
|
-
#: () ->
|
|
1115
|
+
#: () -> Elements::HeaderFooter
|
|
784
1116
|
def header_footer
|
|
785
|
-
|
|
1117
|
+
@header_footer ||= begin
|
|
1118
|
+
hf = print_page_data[:header_footer] || {}
|
|
1119
|
+
hf.is_a?(Elements::HeaderFooter) ? hf : Elements::HeaderFooter.new(**hf)
|
|
1120
|
+
end
|
|
786
1121
|
end
|
|
787
1122
|
|
|
788
1123
|
# Returns print options for this worksheet.
|
|
789
1124
|
#
|
|
790
|
-
# @return [
|
|
1125
|
+
# @return [Elements::PrintOptions]
|
|
791
1126
|
# @api public
|
|
792
|
-
#: () ->
|
|
1127
|
+
#: () -> Elements::PrintOptions
|
|
793
1128
|
def print_options
|
|
794
|
-
|
|
1129
|
+
@print_options ||= begin
|
|
1130
|
+
po = print_page_data[:print_options] || {}
|
|
1131
|
+
po.is_a?(Elements::PrintOptions) ? po : Elements::PrintOptions.new(**po)
|
|
1132
|
+
end
|
|
795
1133
|
end
|
|
796
1134
|
|
|
797
1135
|
# Returns explicit row page breaks for this worksheet.
|
|
798
1136
|
#
|
|
799
|
-
# @return [Array<
|
|
1137
|
+
# @return [Array<Elements::PageBreak>]
|
|
800
1138
|
# @api public
|
|
801
|
-
#: () -> Array[
|
|
1139
|
+
#: () -> Array[Elements::PageBreak]
|
|
802
1140
|
def row_breaks
|
|
803
|
-
print_page_data[:row_breaks] || []
|
|
1141
|
+
@row_breaks ||= (print_page_data[:row_breaks] || []).map do |rb|
|
|
1142
|
+
rb.is_a?(Elements::PageBreak) ? rb : Elements::PageBreak.new(**rb)
|
|
1143
|
+
end.freeze
|
|
804
1144
|
end
|
|
805
1145
|
|
|
806
1146
|
# Returns explicit column page breaks for this worksheet.
|
|
807
1147
|
#
|
|
808
|
-
# @return [Array<
|
|
1148
|
+
# @return [Array<Elements::PageBreak>]
|
|
809
1149
|
# @api public
|
|
810
|
-
#: () -> Array[
|
|
1150
|
+
#: () -> Array[Elements::PageBreak]
|
|
1151
|
+
def column_breaks
|
|
1152
|
+
@column_breaks ||= (print_page_data[:column_breaks] || print_page_data[:col_breaks] || []).map do |cb|
|
|
1153
|
+
cb.is_a?(Elements::PageBreak) ? cb : Elements::PageBreak.new(**cb)
|
|
1154
|
+
end.freeze
|
|
1155
|
+
end
|
|
1156
|
+
|
|
1157
|
+
# @deprecated Use {#column_breaks} instead.
|
|
1158
|
+
#: () -> Array[Elements::PageBreak]
|
|
811
1159
|
def col_breaks
|
|
812
|
-
|
|
1160
|
+
warn "[DEPRECATION] `col_breaks` is deprecated; use `column_breaks` instead.", uplevel: 1
|
|
1161
|
+
column_breaks
|
|
813
1162
|
end
|
|
814
1163
|
|
|
815
1164
|
# Returns protected ranges defined for this worksheet.
|
|
816
1165
|
#
|
|
817
|
-
# @return [Array<
|
|
1166
|
+
# @return [Array<Elements::ProtectedRange>]
|
|
818
1167
|
# @api public
|
|
819
|
-
#: () -> Array[
|
|
1168
|
+
#: () -> Array[Elements::ProtectedRange]
|
|
820
1169
|
def protected_ranges
|
|
821
1170
|
@protected_ranges ||= if raw_sheet_xml.include?("<protectedRanges")
|
|
822
1171
|
listener = Ooxml::Reader::ProtectedRangesListener.new
|
|
823
1172
|
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
824
|
-
listener.ranges
|
|
1173
|
+
listener.ranges.map do |pr|
|
|
1174
|
+
pr.is_a?(Elements::ProtectedRange) ? pr : Elements::ProtectedRange.new(**pr)
|
|
1175
|
+
end.freeze
|
|
825
1176
|
else
|
|
826
|
-
[]
|
|
1177
|
+
[].freeze
|
|
827
1178
|
end
|
|
828
1179
|
end
|
|
829
1180
|
|
|
@@ -844,42 +1195,55 @@ module Xlsxrb
|
|
|
844
1195
|
|
|
845
1196
|
# Returns ignored error rules defined for this worksheet.
|
|
846
1197
|
#
|
|
847
|
-
# @return [Array<
|
|
1198
|
+
# @return [Array<Elements::IgnoredError>]
|
|
848
1199
|
# @api public
|
|
849
|
-
#: () -> Array[
|
|
1200
|
+
#: () -> Array[Elements::IgnoredError]
|
|
850
1201
|
def ignored_errors
|
|
851
1202
|
@ignored_errors ||= if raw_sheet_xml.include?("<ignoredErrors")
|
|
852
1203
|
listener = Ooxml::Reader::IgnoredErrorsListener.new
|
|
853
1204
|
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
854
|
-
listener.errors
|
|
1205
|
+
listener.errors.map do |ie|
|
|
1206
|
+
ie.is_a?(Elements::IgnoredError) ? ie : Elements::IgnoredError.new(**ie)
|
|
1207
|
+
end.freeze
|
|
855
1208
|
else
|
|
856
|
-
[]
|
|
1209
|
+
[].freeze
|
|
857
1210
|
end
|
|
858
1211
|
end
|
|
859
1212
|
|
|
860
1213
|
# Returns phonetic properties defined for this worksheet, or nil.
|
|
861
1214
|
#
|
|
862
|
-
# @return [
|
|
1215
|
+
# @return [Elements::PhoneticProperties, nil]
|
|
863
1216
|
# @api public
|
|
864
|
-
#: () ->
|
|
1217
|
+
#: () -> Elements::PhoneticProperties?
|
|
865
1218
|
def phonetic_properties
|
|
866
1219
|
@phonetic_properties ||= if raw_sheet_xml.include?("<phoneticPr")
|
|
867
1220
|
listener = Ooxml::Reader::PhoneticPrListener.new
|
|
868
1221
|
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
869
|
-
listener.phonetic_pr
|
|
1222
|
+
pp = listener.phonetic_pr
|
|
1223
|
+
if pp
|
|
1224
|
+
pp.is_a?(Elements::PhoneticProperties) ? pp : Elements::PhoneticProperties.new(**pp)
|
|
1225
|
+
end
|
|
870
1226
|
end
|
|
871
1227
|
end
|
|
1228
|
+
# @deprecated Use {#phonetic_properties} instead. Will be removed in 0.2.0.
|
|
872
1229
|
alias phonetic_pr phonetic_properties
|
|
873
1230
|
|
|
874
1231
|
# Returns the background image configured for this worksheet, or nil.
|
|
875
1232
|
#
|
|
876
|
-
# @return [
|
|
1233
|
+
# @return [Elements::BackgroundImage, nil]
|
|
877
1234
|
# @api public
|
|
878
|
-
#: () ->
|
|
1235
|
+
#: () -> Elements::BackgroundImage?
|
|
879
1236
|
def background_image
|
|
880
|
-
@background_image ||=
|
|
1237
|
+
@background_image ||= begin
|
|
1238
|
+
bi = Xlsxrb.send(:resolve_background_image, raw_sheet_xml, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
1239
|
+
if bi
|
|
1240
|
+
bi.is_a?(Elements::BackgroundImage) ? bi : Elements::BackgroundImage.new(**bi)
|
|
1241
|
+
end
|
|
1242
|
+
end
|
|
881
1243
|
end
|
|
1244
|
+
# @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
|
|
882
1245
|
alias background_picture background_image
|
|
1246
|
+
# @deprecated Use {#background_image} instead. Will be removed in 0.2.0.
|
|
883
1247
|
alias picture background_image
|
|
884
1248
|
|
|
885
1249
|
# Closes any underlying reader resources.
|
|
@@ -889,8 +1253,186 @@ module Xlsxrb
|
|
|
889
1253
|
nil
|
|
890
1254
|
end
|
|
891
1255
|
|
|
1256
|
+
# Returns 0-based bounds { min_row: r1, max_row: r2, min_column: c1, max_column: c2 } from dimension ref.
|
|
1257
|
+
#
|
|
1258
|
+
# @example
|
|
1259
|
+
# sheet.dimension_bounds #=> { min_row: 0, max_row: 4, min_column: 0, max_column: 2 }
|
|
1260
|
+
#
|
|
1261
|
+
# @return [Hash{Symbol => Integer}, nil]
|
|
1262
|
+
# @api public
|
|
1263
|
+
#: () -> Hash[Symbol, Integer]?
|
|
1264
|
+
def dimension_bounds
|
|
1265
|
+
return @dimension_bounds if defined?(@dimension_bounds)
|
|
1266
|
+
|
|
1267
|
+
ref = dimension
|
|
1268
|
+
return @dimension_bounds = nil unless ref
|
|
1269
|
+
|
|
1270
|
+
parts = ref.split(":", 2)
|
|
1271
|
+
first_coords = Elements::Cell._parse_ref(parts[0])
|
|
1272
|
+
return @dimension_bounds = nil unless first_coords
|
|
1273
|
+
|
|
1274
|
+
last_coords = parts[1] ? Elements::Cell._parse_ref(parts[1]) : first_coords
|
|
1275
|
+
return @dimension_bounds = nil unless last_coords
|
|
1276
|
+
|
|
1277
|
+
@dimension_bounds = {
|
|
1278
|
+
min_row: first_coords[0],
|
|
1279
|
+
max_row: last_coords[0],
|
|
1280
|
+
min_column: first_coords[1],
|
|
1281
|
+
max_column: last_coords[1]
|
|
1282
|
+
}.freeze
|
|
1283
|
+
end
|
|
1284
|
+
|
|
1285
|
+
# Returns column definitions for this worksheet.
|
|
1286
|
+
#
|
|
1287
|
+
# @return [Array<Elements::Column>]
|
|
1288
|
+
# @api public
|
|
1289
|
+
#: () -> Array[Elements::Column]
|
|
1290
|
+
def columns
|
|
1291
|
+
@columns ||= begin
|
|
1292
|
+
raw_columns = Ooxml::WorksheetParser.parse_columns(raw_sheet_xml)
|
|
1293
|
+
raw_columns.map do |rc|
|
|
1294
|
+
col_unmapped = {}
|
|
1295
|
+
col_unmapped[:style_index] = rc[:style_index] if rc[:style_index]
|
|
1296
|
+
col_unmapped[:min] = rc[:min] if rc[:min]
|
|
1297
|
+
col_unmapped[:max] = rc[:max] if rc[:max]
|
|
1298
|
+
Elements::Column.new(
|
|
1299
|
+
index: (rc[:min] || 1) - 1,
|
|
1300
|
+
width: rc[:width],
|
|
1301
|
+
hidden: rc[:hidden] || false,
|
|
1302
|
+
custom_width: rc[:custom_width] || false,
|
|
1303
|
+
outline_level: rc[:outline_level],
|
|
1304
|
+
style_index: rc[:style_index],
|
|
1305
|
+
unmapped_data: col_unmapped
|
|
1306
|
+
)
|
|
1307
|
+
end
|
|
1308
|
+
end
|
|
1309
|
+
end
|
|
1310
|
+
|
|
1311
|
+
# Returns charts defined in this worksheet.
|
|
1312
|
+
#
|
|
1313
|
+
# @return [Array<Elements::Chart>]
|
|
1314
|
+
# @api public
|
|
1315
|
+
#: () -> Array[Elements::Chart]
|
|
1316
|
+
def charts
|
|
1317
|
+
@charts ||= Xlsxrb.send(:resolve_charts, zip_reader: @zip_reader, entry_name: @entry_name).freeze
|
|
1318
|
+
end
|
|
1319
|
+
|
|
1320
|
+
# Returns sparkline groups defined in this worksheet.
|
|
1321
|
+
#
|
|
1322
|
+
# @return [Array<Elements::SparklineGroup>]
|
|
1323
|
+
# @api public
|
|
1324
|
+
#: () -> Array[Elements::SparklineGroup]
|
|
1325
|
+
def sparkline_groups
|
|
1326
|
+
@sparkline_groups ||= begin
|
|
1327
|
+
groups = if raw_sheet_xml&.include?("sparklineGroup")
|
|
1328
|
+
Xlsxrb.send(:resolve_sparkline_groups, raw_sheet_xml)
|
|
1329
|
+
else
|
|
1330
|
+
[]
|
|
1331
|
+
end
|
|
1332
|
+
groups.map { |sg| sg.is_a?(Elements::SparklineGroup) ? sg : Elements::SparklineGroup.new(**sg) }.freeze
|
|
1333
|
+
end
|
|
1334
|
+
end
|
|
1335
|
+
|
|
1336
|
+
# Returns the print area range for this worksheet, or nil if unset.
|
|
1337
|
+
#
|
|
1338
|
+
# @return [String, nil]
|
|
1339
|
+
# @api public
|
|
1340
|
+
#: () -> String?
|
|
1341
|
+
def print_area
|
|
1342
|
+
return @print_area if defined?(@print_area_resolved) && @print_area_resolved
|
|
1343
|
+
|
|
1344
|
+
@print_area_resolved = true
|
|
1345
|
+
@print_area ||= Xlsxrb.send(:extract_sheet_print_area, @defined_names, @name, @sheet_index)
|
|
1346
|
+
end
|
|
1347
|
+
|
|
1348
|
+
# Returns print titles configuration for this worksheet, or nil if unset.
|
|
1349
|
+
#
|
|
1350
|
+
# @return [Elements::PrintTitles, nil]
|
|
1351
|
+
# @api public
|
|
1352
|
+
#: () -> Elements::PrintTitles?
|
|
1353
|
+
def print_titles
|
|
1354
|
+
return @print_titles if defined?(@print_titles_resolved) && @print_titles_resolved
|
|
1355
|
+
|
|
1356
|
+
@print_titles_resolved = true
|
|
1357
|
+
@print_titles ||= Xlsxrb.send(:extract_sheet_print_titles, @defined_names, @name, @sheet_index)
|
|
1358
|
+
end
|
|
1359
|
+
|
|
1360
|
+
# Returns whether the worksheet has any structural or schema validation errors.
|
|
1361
|
+
#
|
|
1362
|
+
# @return [Boolean]
|
|
1363
|
+
# @api public
|
|
1364
|
+
#: () -> bool
|
|
1365
|
+
def valid?
|
|
1366
|
+
errors.empty?
|
|
1367
|
+
end
|
|
1368
|
+
|
|
1369
|
+
# Returns validation error messages for this worksheet.
|
|
1370
|
+
#
|
|
1371
|
+
# @return [Array<String>]
|
|
1372
|
+
# @api public
|
|
1373
|
+
#: () -> Array[String]
|
|
1374
|
+
def errors
|
|
1375
|
+
[]
|
|
1376
|
+
end
|
|
1377
|
+
|
|
1378
|
+
# Returns unmapped metadata for this worksheet.
|
|
1379
|
+
#
|
|
1380
|
+
# @return [Hash[Symbol, untyped]]
|
|
1381
|
+
# @api public
|
|
1382
|
+
#: () -> Hash[Symbol, untyped]
|
|
1383
|
+
def unmapped_data
|
|
1384
|
+
{}
|
|
1385
|
+
end
|
|
1386
|
+
|
|
1387
|
+
# Returns legacy drawing relationship info, or nil.
|
|
1388
|
+
#
|
|
1389
|
+
# @return [Hash[Symbol, untyped], nil]
|
|
1390
|
+
# @api public
|
|
1391
|
+
#: () -> Hash[Symbol, untyped]?
|
|
1392
|
+
def legacy_drawing
|
|
1393
|
+
Xlsxrb::Deprecation.warn("StreamSheet#legacy_drawing is deprecated.", uplevel: 1)
|
|
1394
|
+
nil
|
|
1395
|
+
end
|
|
1396
|
+
|
|
1397
|
+
# Returns extension list elements, or nil.
|
|
1398
|
+
#
|
|
1399
|
+
# @return [Array[untyped], nil]
|
|
1400
|
+
# @api public
|
|
1401
|
+
#: () -> Array[untyped]?
|
|
1402
|
+
def ext_lst
|
|
1403
|
+
Xlsxrb::Deprecation.warn("StreamSheet#ext_lst is deprecated.", uplevel: 1)
|
|
1404
|
+
nil
|
|
1405
|
+
end
|
|
1406
|
+
|
|
1407
|
+
# Returns header/footer images configured for this worksheet.
|
|
1408
|
+
#
|
|
1409
|
+
# @return [Array<Elements::HeaderFooterImage>]
|
|
1410
|
+
# @api public
|
|
1411
|
+
#: () -> Array[Elements::HeaderFooterImage]
|
|
1412
|
+
def header_footer_images
|
|
1413
|
+
@header_footer_images ||= begin
|
|
1414
|
+
imgs = if raw_sheet_xml&.include?("legacyDrawingHF")
|
|
1415
|
+
Xlsxrb.send(:resolve_header_footer_images, raw_sheet_xml, zip_reader: @zip_reader, entry_name: @entry_name)
|
|
1416
|
+
else
|
|
1417
|
+
[]
|
|
1418
|
+
end
|
|
1419
|
+
imgs.map { |img| img.is_a?(Elements::HeaderFooterImage) ? img : Elements::HeaderFooterImage.new(**img) }.freeze
|
|
1420
|
+
end
|
|
1421
|
+
end
|
|
1422
|
+
|
|
892
1423
|
private
|
|
893
1424
|
|
|
1425
|
+
#: () -> Hash[Symbol, untyped]
|
|
1426
|
+
def auto_filter_data
|
|
1427
|
+
@auto_filter_data ||= if raw_sheet_xml.include?("<autoFilter")
|
|
1428
|
+
listener = Ooxml::Reader::AutoFilterListener.new
|
|
1429
|
+
Ooxml::XmlParser.parse(raw_sheet_xml, listener)
|
|
1430
|
+
{ ref: listener.ref, filter_columns: listener.filter_columns }
|
|
1431
|
+
else
|
|
1432
|
+
{ ref: nil, filter_columns: {} }
|
|
1433
|
+
end
|
|
1434
|
+
end
|
|
1435
|
+
|
|
894
1436
|
#: () -> Hash[Symbol, untyped]
|
|
895
1437
|
def sheet_view_data
|
|
896
1438
|
@sheet_view_data ||= if raw_sheet_xml.include?("<sheetView")
|
|
@@ -913,6 +1455,7 @@ module Xlsxrb
|
|
|
913
1455
|
header_footer: listener.header_footer,
|
|
914
1456
|
print_options: listener.print_options,
|
|
915
1457
|
row_breaks: listener.row_breaks,
|
|
1458
|
+
column_breaks: listener.column_breaks,
|
|
916
1459
|
col_breaks: listener.col_breaks
|
|
917
1460
|
}
|
|
918
1461
|
else
|
|
@@ -922,6 +1465,7 @@ module Xlsxrb
|
|
|
922
1465
|
header_footer: {},
|
|
923
1466
|
print_options: {},
|
|
924
1467
|
row_breaks: [],
|
|
1468
|
+
column_breaks: [],
|
|
925
1469
|
col_breaks: []
|
|
926
1470
|
}
|
|
927
1471
|
end
|
|
@@ -942,49 +1486,21 @@ module Xlsxrb
|
|
|
942
1486
|
end
|
|
943
1487
|
end
|
|
944
1488
|
|
|
945
|
-
# Returns 1-based bounds [first_row, first_col, last_row, last_col] from dimension ref.
|
|
946
|
-
#: () -> Array[Integer]?
|
|
947
|
-
def dimension_bounds
|
|
948
|
-
return @dimension_bounds if defined?(@dimension_bounds)
|
|
949
|
-
|
|
950
|
-
ref = dimension
|
|
951
|
-
return @dimension_bounds = nil unless ref
|
|
952
|
-
|
|
953
|
-
parts = ref.split(":", 2)
|
|
954
|
-
first_coords = Elements::Cell.parse_ref(parts[0])
|
|
955
|
-
return @dimension_bounds = nil unless first_coords
|
|
956
|
-
|
|
957
|
-
last_coords = parts[1] ? Elements::Cell.parse_ref(parts[1]) : first_coords
|
|
958
|
-
return @dimension_bounds = nil unless last_coords
|
|
959
|
-
|
|
960
|
-
@dimension_bounds = [
|
|
961
|
-
first_coords[0] + 1,
|
|
962
|
-
first_coords[1] + 1,
|
|
963
|
-
last_coords[0] + 1,
|
|
964
|
-
last_coords[1] + 1
|
|
965
|
-
].freeze
|
|
966
|
-
end
|
|
967
|
-
|
|
968
1489
|
# Extracts dimension reference from XML source lazily without parsing the entire file.
|
|
969
1490
|
#: () -> String?
|
|
970
1491
|
def extract_dimension
|
|
971
1492
|
if @sheet_source.is_a?(String)
|
|
972
1493
|
@sheet_source.slice(/<(?:[a-zA-Z0-9_]+:)?dimension\b[^>]*\bref=["']([^"']+)["']/, 1)
|
|
973
1494
|
elsif @zip_reader && @entry_name
|
|
974
|
-
stream = @zip_reader.open_entry_io(@entry_name)
|
|
975
1495
|
buf = +""
|
|
976
1496
|
dim = nil
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
break
|
|
983
|
-
end
|
|
984
|
-
break if buf.include?("<sheetData") || buf.include?(":sheetData")
|
|
1497
|
+
@zip_reader.each_entry_chunk(@entry_name) do |chunk|
|
|
1498
|
+
buf << chunk
|
|
1499
|
+
if (m = buf.match(/<(?:[a-zA-Z0-9_]+:)?dimension\b[^>]*\bref=["']([^"']+)["']/))
|
|
1500
|
+
dim = m[1]
|
|
1501
|
+
break
|
|
985
1502
|
end
|
|
986
|
-
|
|
987
|
-
stream.close
|
|
1503
|
+
break if buf.include?("<sheetData") || buf.include?(":sheetData")
|
|
988
1504
|
end
|
|
989
1505
|
dim
|
|
990
1506
|
elsif @sheet_source.respond_to?(:call)
|