xlsxrb 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +88 -0
  3. data/README.md +25 -3
  4. data/lib/xlsxrb/dsl_helpers.rb +65 -1
  5. data/lib/xlsxrb/elements/styles.rb +15 -6
  6. data/lib/xlsxrb/elements/worksheet.rb +2 -2
  7. data/lib/xlsxrb/number_formatter.rb +26 -8
  8. data/lib/xlsxrb/ooxml/cfb.rb +11 -3
  9. data/lib/xlsxrb/ooxml/crypto/agile.rb +48 -10
  10. data/lib/xlsxrb/ooxml/crypto/standard.rb +5 -1
  11. data/lib/xlsxrb/ooxml/crypto.rb +3 -0
  12. data/lib/xlsxrb/ooxml/shared_strings_parser.rb +26 -8
  13. data/lib/xlsxrb/ooxml/utils.rb +13 -0
  14. data/lib/xlsxrb/ooxml/workbook_writer.rb +43 -21
  15. data/lib/xlsxrb/ooxml/worksheet_parser.rb +116 -12
  16. data/lib/xlsxrb/ooxml/worksheet_writer.rb +338 -259
  17. data/lib/xlsxrb/ooxml/writer/drawing_xml.rb +206 -201
  18. data/lib/xlsxrb/ooxml/writer/features_xml.rb +109 -102
  19. data/lib/xlsxrb/ooxml/writer/styles_xml.rb +46 -46
  20. data/lib/xlsxrb/ooxml/writer.rb +167 -160
  21. data/lib/xlsxrb/ooxml/xml_builder.rb +35 -7
  22. data/lib/xlsxrb/ooxml/xml_parser.rb +34 -1
  23. data/lib/xlsxrb/ooxml/zip_reader.rb +95 -68
  24. data/lib/xlsxrb/ooxml/zip_writer.rb +16 -0
  25. data/lib/xlsxrb/stream_row.rb +2 -2
  26. data/lib/xlsxrb/stream_sheet.rb +26 -11
  27. data/lib/xlsxrb/stream_writer.rb +212 -86
  28. data/lib/xlsxrb/style_builder.rb +339 -0
  29. data/lib/xlsxrb/version.rb +1 -1
  30. data/lib/xlsxrb/workbook_builder.rb +239 -88
  31. data/lib/xlsxrb/worksheet_builder.rb +847 -139
  32. data/lib/xlsxrb.rb +87 -21
  33. data/sig/generated/xlsxrb/dsl_helpers.rbs +37 -0
  34. data/sig/generated/xlsxrb/elements/styles.rbs +5 -0
  35. data/sig/generated/xlsxrb/number_formatter.rbs +7 -0
  36. data/sig/generated/xlsxrb/ooxml/cfb.rbs +2 -0
  37. data/sig/generated/xlsxrb/ooxml/crypto/agile.rbs +10 -0
  38. data/sig/generated/xlsxrb/ooxml/shared_strings_parser.rbs +7 -0
  39. data/sig/generated/xlsxrb/ooxml/utils.rbs +10 -0
  40. data/sig/generated/xlsxrb/ooxml/workbook_writer.rbs +13 -0
  41. data/sig/generated/xlsxrb/ooxml/worksheet_parser.rbs +40 -0
  42. data/sig/generated/xlsxrb/ooxml/worksheet_writer.rbs +53 -0
  43. data/sig/generated/xlsxrb/ooxml/writer/features_xml.rbs +3 -0
  44. data/sig/generated/xlsxrb/ooxml/writer.rbs +4 -0
  45. data/sig/generated/xlsxrb/ooxml/xml_builder.rbs +19 -2
  46. data/sig/generated/xlsxrb/ooxml/xml_parser.rbs +10 -0
  47. data/sig/generated/xlsxrb/ooxml/zip_reader.rbs +12 -1
  48. data/sig/generated/xlsxrb/ooxml/zip_writer.rbs +8 -0
  49. data/sig/generated/xlsxrb/stream_row.rbs +2 -2
  50. data/sig/generated/xlsxrb/stream_sheet.rbs +9 -0
  51. data/sig/generated/xlsxrb/stream_writer.rbs +46 -6
  52. data/sig/generated/xlsxrb/style_builder.rbs +261 -0
  53. data/sig/generated/xlsxrb/workbook_builder.rbs +42 -9
  54. data/sig/generated/xlsxrb/worksheet_builder.rbs +618 -4
  55. data/sig/generated/xlsxrb.rbs +53 -8
  56. metadata +9 -3
@@ -12,9 +12,12 @@ module Xlsxrb
12
12
  # @param name [String] The worksheet name.
13
13
  # @param strict_excel_mode [Boolean] Whether to enforce Microsoft Excel limits.
14
14
  # @param state [Symbol] Sheet visibility state (:visible, :hidden, or :very_hidden).
15
- #: (String name, ?strict_excel_mode: bool, ?state: Symbol) -> void
16
- def initialize(name, strict_excel_mode: true, state: :visible)
15
+ # @param style_log [StyleLog] When the workbook's styles are defined (internal).
16
+ #: (String name, ?strict_excel_mode: bool, ?state: Symbol, ?style_log: StyleLog) -> void
17
+ def initialize(name, strict_excel_mode: true, state: :visible, style_log: StyleLog.new)
17
18
  @name = name
19
+ @style_log = style_log
20
+ @column_style_clocks = {} # { column index => style log clock when its style was set }
18
21
  @strict_excel_mode = strict_excel_mode
19
22
  @state = state ? state.to_sym : :visible
20
23
  @next_row_index = 0
@@ -80,6 +83,8 @@ module Xlsxrb
80
83
  # @yield [style_builder]
81
84
  # @yieldparam style_builder [Xlsxrb::StyleBuilder]
82
85
  # @return [StyleBuilder]
86
+ # Using the returned value is deprecated and warns; in version 0.3.0, this method
87
+ # will return nil. Configure the style with options or in the block.
83
88
  # @api public
84
89
  #: (String | Symbol name, **untyped opts) ?{ (StyleBuilder) -> void } -> StyleBuilder
85
90
  def style(name, **opts)
@@ -88,7 +93,8 @@ module Xlsxrb
88
93
  style_builder.apply_options!(**opts) unless opts.empty?
89
94
  yield style_builder if block_given?
90
95
  @styles[style_name] = style_builder
91
- style_builder
96
+ @style_log.record(style_name, style_builder)
97
+ ReturnedStyleBuilder.new(style_builder)
92
98
  end
93
99
 
94
100
  # Creates an {Elements::Formula} object.
@@ -147,6 +153,7 @@ module Xlsxrb
147
153
  # @api public
148
154
  #: (Array[untyped] | Hash[untyped, untyped] values, ?cell_styles: untyped, ?row_style: (Integer | Symbol | String | Hash[Symbol, untyped])?, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?collapsed: bool, ?outline_level: Integer | nil) -> void
149
155
  def row(values, cell_styles: nil, row_style: nil, height: nil, hidden: false, custom_height: false, collapsed: false, outline_level: nil)
156
+ check_open!
150
157
  row_index = @next_row_index
151
158
  DslHelpers.validate_row_bounds!(row_index, height, strict_excel_mode: @strict_excel_mode)
152
159
  @next_row_index += 1
@@ -159,22 +166,52 @@ module Xlsxrb
159
166
 
160
167
  values = DslHelpers.normalize_row_values(values)
161
168
  cell_styles = DslHelpers.normalize_row_styles(cell_styles)
169
+ # The row is kept as given until the workbook resolves its styles, so it must not
170
+ # change with the caller's arrays. Each array is copied once, when first needed.
171
+ values_copied = false
172
+ styles_copied = false
162
173
 
163
174
  # Auto-detect Date / Time for built-in styles
164
175
  values.each_with_index do |val, idx|
165
176
  cell_style = cell_styles.is_a?(Array) ? cell_styles[idx] : cell_styles
166
177
 
167
178
  if val.is_a?(Date) && !val.is_a?(DateTime) && cell_style.nil?
168
- style("__xlsxrb_date", number_format: "yyyy-mm-dd") unless @styles.key?("__xlsxrb_date")
169
- cell_styles = [] if cell_styles.nil?
170
- cell_styles = Array.new(values.size, cell_styles) unless cell_styles.is_a?(Array)
171
- cell_styles[idx] = "__xlsxrb_date"
172
- elsif (val.is_a?(Time) || val.is_a?(DateTime)) && cell_style.nil?
173
- style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss") unless @styles.key?("__xlsxrb_time")
174
- cell_styles = [] if cell_styles.nil?
175
- cell_styles = Array.new(values.size, cell_styles) unless cell_styles.is_a?(Array)
176
- cell_styles[idx] = "__xlsxrb_time"
179
+ auto_style = inherited_date_style(row_style, idx)
180
+ unless auto_style
181
+ style("__xlsxrb_date", number_format: "yyyy-mm-dd") unless @styles.key?("__xlsxrb_date")
182
+ auto_style = "__xlsxrb_date"
183
+ end
184
+ elsif val.is_a?(Time) || val.is_a?(DateTime)
185
+ # A value that claims to be a Time without being one, such as
186
+ # ActiveSupport::TimeWithZone, is kept as a Time with the same wall clock.
187
+ unless Time === val || val.is_a?(DateTime) # rubocop:disable Style/CaseEquality
188
+ unless values_copied
189
+ values = values.dup
190
+ values_copied = true
191
+ end
192
+ values[idx] = Ooxml::WorksheetWriter::TimeLike.to_time(val)
193
+ end
194
+ next unless cell_style.nil?
195
+
196
+ auto_style = inherited_date_style(row_style, idx)
197
+ unless auto_style
198
+ style("__xlsxrb_time", number_format: "yyyy-mm-dd hh:mm:ss") unless @styles.key?("__xlsxrb_time")
199
+ auto_style = "__xlsxrb_time"
200
+ end
201
+ else
202
+ next
177
203
  end
204
+ unless styles_copied
205
+ cell_styles = if cell_styles.nil?
206
+ []
207
+ elsif cell_styles.is_a?(Array)
208
+ cell_styles.dup
209
+ else
210
+ Array.new(values.size, cell_styles)
211
+ end
212
+ styles_copied = true
213
+ end
214
+ cell_styles[idx] = auto_style
178
215
  end
179
216
 
180
217
  max_len = values.size
@@ -182,103 +219,66 @@ module Xlsxrb
182
219
  # See: https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
183
220
  raise ArgumentError, "Row contains #{max_len} columns, exceeding Excel limit of 16_384 columns" if @strict_excel_mode && max_len > 16_384
184
221
 
185
- cells = Array.new(max_len)
186
222
  style_lookup = cell_styles.is_a?(Array)
223
+ # Number format codes of the cells' sheet styles, as of this call.
224
+ format_codes = style_lookup ? nil : format_code_of(cell_styles)
187
225
 
188
226
  col_index = 0
189
227
  while col_index < max_len
190
228
  val = col_index < values.size ? values[col_index] : nil
191
229
  raise ArgumentError, "Invalid cell value type or value: #{val.class} for value #{val.inspect}" unless val.nil? || val.is_a?(String) || (val.is_a?(Numeric) && !(val.is_a?(Float) && (val.infinite? || val.nan?))) || val.is_a?(TrueClass) || val.is_a?(FalseClass) || val.is_a?(Date) || val.is_a?(Time) || val.is_a?(Elements::Formula) || (val.is_a?(Hash) && val.key?(:formula)) || val.is_a?(Elements::RichText) || val.is_a?(Elements::CellError) || (val.is_a?(Array) && val.first.is_a?(Hash) && (val.first.key?(:text) || val.first.key?("text")))
230
+
192
231
  # See: https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
193
- raise ArgumentError, "Cell text length #{val.length} exceeds Excel limit of 32,767 characters" if @strict_excel_mode && val.is_a?(String) && val.length > 32_767
194
-
195
- if val.is_a?(Array) && val.first.is_a?(Hash) && (val.first.key?(:text) || val.first.key?("text"))
196
- # Coerce array of hashes to RichText
197
- runs = val.map do |run|
198
- text = run[:text] || run["text"]
199
- font = run.reject { |k| k.to_s == "text" }
200
- { text: text, font: font.empty? ? nil : font }.compact
232
+ DslHelpers.check_cell_text_length!(val) if @strict_excel_mode && val.is_a?(String) && val.bytesize > DslHelpers::MAX_CELL_TEXT_LENGTH
233
+
234
+ if val.is_a?(Array) || val.is_a?(Hash)
235
+ unless values_copied
236
+ values = values.dup
237
+ values_copied = true
201
238
  end
202
- val = Elements::RichText.new(runs: runs)
239
+ values[col_index] = if val.is_a?(Array)
240
+ # Coerce array of hashes to RichText
241
+ runs = val.map do |run|
242
+ text = run[:text] || run["text"]
243
+ font = run.reject { |k| k.to_s == "text" }
244
+ { text: text, font: font.empty? ? nil : font }.compact
245
+ end
246
+ Elements::RichText.new(runs: runs)
247
+ else
248
+ # A Hash with :formula becomes the cell's formula.
249
+ Elements::Formula.new(
250
+ expression: val[:formula] || val[:expression] || "",
251
+ cached_value: val.key?(:value) ? val[:value] : val[:cached_value],
252
+ type: val[:type] || (:shared if val.key?(:shared_index)),
253
+ ref: val[:ref],
254
+ shared_index: val[:shared_index],
255
+ calculate_always: val[:calculate_always]
256
+ )
257
+ end
203
258
  end
204
259
 
205
- style_name = if style_lookup
206
- col_index < cell_styles.size ? cell_styles[col_index] : nil
207
- else
208
- cell_styles
209
- end
210
-
211
- if style_name.is_a?(Hash)
212
- inline_name = "__inline_#{style_name.hash}"
213
- style(inline_name, **style_name) unless @styles.key?(inline_name)
214
- style_name = inline_name
215
- end
216
- if val.nil? && style_name.nil?
217
- col_index += 1
218
- next
260
+ if style_lookup
261
+ style_name = col_index < cell_styles.size ? cell_styles[col_index] : nil
262
+ if style_name.is_a?(Hash)
263
+ inline_name = "__inline_#{style_name.hash}"
264
+ style(inline_name, **style_name) unless @styles.key?(inline_name)
265
+ unless styles_copied
266
+ cell_styles = cell_styles.dup
267
+ styles_copied = true
268
+ end
269
+ cell_styles[col_index] = style_name = inline_name
270
+ end
271
+ format_code = style_name.nil? ? nil : format_code_of(style_name)
272
+ (format_codes ||= [])[col_index] = format_code if format_code
219
273
  end
220
- sb = @styles[style_name]
221
- fmt_code = if sb&.number_format
222
- sb.number_format.is_a?(String) ? sb.number_format : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[sb.number_format]
223
- end
224
- # If value is a Formula object or Hash with :formula, store it as the cell's formula
225
- cells[col_index] = if val.is_a?(Elements::Formula)
226
- Elements::Cell.new(
227
- row_index: row_index,
228
- column_index: col_index,
229
- value: val.cached_value,
230
- formula: val,
231
- style: style_name,
232
- raw_value: val.cached_value&.to_s,
233
- format_code: fmt_code
234
- )
235
- elsif val.is_a?(Hash) && (val.key?(:formula) || val.key?(:expression) || (val[:type]&.to_sym == :shared && val.key?(:shared_index)))
236
- cached_val = val.key?(:value) ? val[:value] : val[:cached_value]
237
- f_expr = val[:formula] || val[:expression] || ""
238
- f_type = val[:type] || (:shared if val.key?(:shared_index))
239
- f_obj = Elements::Formula.new(
240
- expression: f_expr,
241
- cached_value: cached_val,
242
- type: f_type,
243
- ref: val[:ref],
244
- shared_index: val[:shared_index],
245
- calculate_always: val[:calculate_always]
246
- )
247
- Elements::Cell.new(
248
- row_index: row_index,
249
- column_index: col_index,
250
- value: cached_val,
251
- formula: f_obj,
252
- style: style_name,
253
- raw_value: cached_val&.to_s,
254
- format_code: fmt_code
255
- )
256
- else
257
- Elements::Cell.new(
258
- row_index: row_index,
259
- column_index: col_index,
260
- value: val,
261
- style: style_name,
262
- raw_value: val&.to_s,
263
- format_code: fmt_code
264
- )
265
- end
266
274
  col_index += 1
267
275
  end
268
276
 
269
- cells.compact!
270
- unmapped = Elements::EMPTY_HASH
271
- @rows << Elements::Row.new(
272
- index: row_index,
273
- cells: cells,
274
- height: height,
275
- hidden: hidden,
276
- custom_height: custom_height || !height.nil?,
277
- collapsed: collapsed,
278
- outline_level: outline_level,
279
- style_index: row_style,
280
- unmapped_data: unmapped
281
- )
277
+ values = values.dup unless values_copied || values.frozen?
278
+ cell_styles = cell_styles.dup if style_lookup && !styles_copied && !cell_styles.frozen?
279
+ @rows << PendingRow.new(row_index, values, cell_styles, format_codes, max_len, height, hidden,
280
+ custom_height || !height.nil?, collapsed, outline_level, row_style, @style_log.clock)
281
+ nil
282
282
  end
283
283
 
284
284
  # Appends a row to the worksheet and returns self for chaining.
@@ -305,9 +305,11 @@ module Xlsxrb
305
305
  # @api public
306
306
  #: (?Integer count) -> void
307
307
  def skip_rows(count = 1)
308
+ check_open!
308
309
  raise ArgumentError, "count must be positive: #{count.inspect}" if !count.is_a?(Integer) || count < 1
309
310
 
310
311
  @next_row_index += count
312
+ nil
311
313
  end
312
314
 
313
315
  # Sets column formatting and properties for one or multiple columns.
@@ -330,6 +332,7 @@ module Xlsxrb
330
332
  raise ArgumentError, "Column width #{width} must be between 0 and 255 characters (Excel limitation)" if @strict_excel_mode && width && (width.negative? || width > 255)
331
333
 
332
334
  DslHelpers.normalize_column_indices(index).each do |idx|
335
+ @column_style_clocks[idx] = @style_log.clock unless style.nil?
333
336
  existing_idx = @columns.find_index { |c| c.index == idx }
334
337
  if existing_idx
335
338
  prev = @columns[existing_idx]
@@ -440,26 +443,22 @@ module Xlsxrb
440
443
  when Array then rows
441
444
  else [rows.to_i]
442
445
  end
446
+ check_open!
443
447
  row_indices.each do |idx|
444
448
  existing_row = @rows.find { |r| r.index == idx }
445
449
  if existing_row
446
450
  existing_idx = @rows.index(existing_row)
447
- @rows[existing_idx] = Elements::Row.new(
448
- index: existing_row.index,
449
- cells: existing_row.cells,
450
- height: existing_row.height,
451
- hidden: hidden || existing_row.hidden?,
452
- custom_height: existing_row.custom_height?,
453
- collapsed: collapsed || existing_row.collapsed?,
454
- outline_level: level,
455
- style_index: existing_row.style_index,
456
- unmapped_data: existing_row.unmapped_data
451
+ @rows[existing_idx] = existing_row.with_outline(
452
+ hidden: hidden || existing_row.hidden,
453
+ collapsed: collapsed || existing_row.collapsed,
454
+ outline_level: level
457
455
  )
458
456
  else
459
457
  @pending_row_attributes[idx] = { outline_level: level, collapsed: collapsed, hidden: hidden }
460
458
  end
461
459
  end
462
460
  end
461
+ nil
463
462
  end
464
463
 
465
464
  # Configures or queries worksheet-level outline and grouping view properties.
@@ -1285,7 +1284,9 @@ module Xlsxrb
1285
1284
 
1286
1285
  # Sets the worksheet background image (<picture>).
1287
1286
  #
1288
- # @param val [String, Hash, Elements::Image, nil] Image binary data, file path, or image options hash.
1287
+ # @param val [String, Hash, Elements::Image, nil] Image binary data, or a Hash with +:data+ and
1288
+ # +:ext+. A String is always the image itself: to use a file, pass its bytes, as in
1289
+ # +{ data: File.binread(path), ext: "jpg" }+.
1289
1290
  # @return [untyped]
1290
1291
  # @api public
1291
1292
  #: (untyped val) -> untyped
@@ -1297,10 +1298,9 @@ module Xlsxrb
1297
1298
 
1298
1299
  data = val
1299
1300
  inferred_ext = nil
1300
- if data.is_a?(String) && !data.include?("\x00") && File.file?(data)
1301
- inferred_ext = File.extname(data).delete_prefix(".").downcase
1302
- data = File.binread(data)
1303
- elsif data.is_a?(Hash)
1301
+ # SECURITY NOTE: A String is the image itself and is never read as a path. Reading it
1302
+ # as one let text that names a file put that file's bytes into the workbook (ADR 0012).
1303
+ if data.is_a?(Hash)
1304
1304
  inferred_ext = data[:ext] || (data[:filename] && File.extname(data[:filename]).delete_prefix("."))
1305
1305
  data = data[:file_data] || data[:data]
1306
1306
  elsif data.is_a?(Elements::Image)
@@ -1680,12 +1680,68 @@ module Xlsxrb
1680
1680
  spec
1681
1681
  end
1682
1682
 
1683
- # Builds and returns the in-memory {Elements::Worksheet}.
1683
+ # Builds and returns the in-memory {Elements::Worksheet}. Cells carry their style
1684
+ # names; {WorkbookBuilder#build} resolves them to style indexes.
1684
1685
  #
1686
+ # @deprecated Read the sheet from the workbook that {Xlsxrb.build} returns. This
1687
+ # method will be private in version 0.3.0.
1685
1688
  # @return [Elements::Worksheet]
1686
1689
  # @api public
1687
1690
  #: () -> Elements::Worksheet
1688
1691
  def build
1692
+ Deprecation.warn("WorksheetBuilder#build is deprecated; read the sheet from the workbook that Xlsxrb.build returns. It will be private in version 0.3.0.")
1693
+ snapshot(@rows.dup.freeze).worksheet
1694
+ end
1695
+
1696
+ # Ends the sheet block: rows can no longer be added, and the sheet's state is taken
1697
+ # as it is now.
1698
+ #
1699
+ # @return [Snapshot]
1700
+ # @api private
1701
+ #: () -> Snapshot
1702
+ def close
1703
+ @closed = true
1704
+ snapshot(@rows.freeze)
1705
+ end
1706
+
1707
+ # Internal: returns styles for later processing by WorkbookBuilder
1708
+ # @return [Hash{String => StyleBuilder}]
1709
+ #: Hash[String, StyleBuilder]
1710
+ attr_reader :styles
1711
+
1712
+ private
1713
+
1714
+ #: () -> void
1715
+ def check_open!
1716
+ raise Error, "Sheet '#{@name}' is closed: add its rows inside its sheet block" if @closed
1717
+ end
1718
+
1719
+ # The style that a Date or Time cell without a cell style inherits, to give the cell
1720
+ # in its place: the row style, or the sheet's column style in a row without one. The
1721
+ # workbook then gives the cell a variant of that style with the default date or
1722
+ # date-time format, so it keeps the style's font, fill, and border, as StreamWriter
1723
+ # does. Returns nil for a style index or for no style.
1724
+ #: (untyped row_style, Integer column_index) -> (String | Symbol | Hash[Symbol, untyped])?
1725
+ def inherited_date_style(row_style, column_index)
1726
+ style = if !row_style.nil?
1727
+ row_style
1728
+ elsif @column_style_clocks.key?(column_index)
1729
+ @columns.find { |column| column.index == column_index }&.style_index
1730
+ end
1731
+ style if style.is_a?(String) || style.is_a?(Symbol) || style.is_a?(Hash)
1732
+ end
1733
+
1734
+ # Returns the number format code of the sheet style named +style_name+, if it has one.
1735
+ #: (untyped style_name) -> String?
1736
+ def format_code_of(style_name)
1737
+ number_format = @styles[style_name]&.number_format
1738
+ return nil unless number_format
1739
+
1740
+ number_format.is_a?(String) ? number_format : Ooxml::Utils::BUILTIN_NUM_FMT_CODES[number_format]
1741
+ end
1742
+
1743
+ #: (Array[PendingRow] rows) -> Snapshot
1744
+ def snapshot(rows)
1689
1745
  facade_meta = {}
1690
1746
  facade_meta[:hyperlinks] = @hyperlinks unless @hyperlinks.empty?
1691
1747
  facade_meta[:auto_filter] = @auto_filter if @auto_filter
@@ -1755,30 +1811,8 @@ module Xlsxrb
1755
1811
  (tc_hash[ref] ||= []) << obj
1756
1812
  end
1757
1813
 
1758
- rows = if hl_hash.empty? && cm_hash.empty? && tc_hash.empty?
1759
- @rows
1760
- else
1761
- @rows.map do |row|
1762
- new_cells = row.cells.map do |cell|
1763
- hl = hl_hash[cell.ref]
1764
- cm = cm_hash[cell.ref]
1765
- tcs = tc_hash[cell.ref]
1766
- if hl || cm || tcs
1767
- cell.with(
1768
- hyperlink: hl || cell.hyperlink,
1769
- comment: cm || cell.comment,
1770
- threaded_comments: (tcs ? (cell.threaded_comments + tcs) : cell.threaded_comments)
1771
- )
1772
- else
1773
- cell
1774
- end
1775
- end
1776
- row.with(cells: new_cells)
1777
- end
1778
- end
1779
-
1780
- Elements::Worksheet.new(
1781
- name: @name, rows: rows, columns: @columns, charts: @charts,
1814
+ frame = Elements::Worksheet.new(
1815
+ name: @name, rows: [], columns: @columns, charts: @charts,
1782
1816
  conditional_formats: @conditional_formats,
1783
1817
  data_validations: @data_validations,
1784
1818
  unmapped_data: facade_meta.empty? ? {} : { facade: facade_meta },
@@ -1815,12 +1849,686 @@ module Xlsxrb
1815
1849
  sheet_calc_properties: @sheet_calc_pr,
1816
1850
  background_image: @background_image
1817
1851
  )
1852
+ Snapshot.new(frame, rows, hl_hash, cm_hash, tc_hash, @column_style_clocks.dup)
1818
1853
  end
1854
+ end
1819
1855
 
1820
- # Internal: returns styles for later processing by WorkbookBuilder
1821
- # @return [Hash{String => StyleBuilder}]
1822
- #: Hash[String, StyleBuilder]
1823
- attr_reader :styles
1856
+ class WorksheetBuilder
1857
+ # A row as given to {WorksheetBuilder#row}, kept until the workbook resolves its
1858
+ # style names, so that its cells are created once.
1859
+ #
1860
+ # @api private
1861
+ class PendingRow
1862
+ #: Integer
1863
+ attr_reader :index
1864
+ # Cell values; Hashes with :formula and rich text runs are already converted.
1865
+ #: Array[untyped]
1866
+ attr_reader :values
1867
+ # Style of each cell: a name, an index, or nil; or one of these for every cell.
1868
+ #: untyped
1869
+ attr_reader :styles
1870
+ # Number format codes of the cells' sheet styles: an Array, one code, or nil.
1871
+ #: untyped
1872
+ attr_reader :format_codes
1873
+ # Number of columns the row spans, including styled cells past the last value.
1874
+ #: Integer
1875
+ attr_reader :width
1876
+ #: (Float | Integer)?
1877
+ attr_reader :height
1878
+ #: untyped
1879
+ attr_reader :hidden
1880
+ #: bool
1881
+ attr_reader :custom_height
1882
+ #: untyped
1883
+ attr_reader :collapsed
1884
+ #: Integer?
1885
+ attr_reader :outline_level
1886
+ # The row style as given: a name, an index, an inline Hash, or nil.
1887
+ #: untyped
1888
+ attr_reader :style
1889
+ # The style log clock when the row was added: its styles are the definitions made before.
1890
+ #: Integer
1891
+ attr_reader :clock
1892
+
1893
+ #: (Integer index, Array[untyped] values, untyped styles, untyped format_codes, Integer width, (Float | Integer)? height, untyped hidden, bool custom_height, untyped collapsed, Integer? outline_level, untyped style, Integer clock) -> void
1894
+ def initialize(index, values, styles, format_codes, width, height, hidden, custom_height, collapsed, outline_level, style, clock)
1895
+ @index = index
1896
+ @values = values
1897
+ @styles = styles
1898
+ @format_codes = format_codes
1899
+ @width = width
1900
+ @height = height
1901
+ @hidden = hidden
1902
+ @custom_height = custom_height
1903
+ @collapsed = collapsed
1904
+ @outline_level = outline_level
1905
+ @style = style
1906
+ @clock = clock
1907
+ end
1908
+
1909
+ #: (hidden: untyped, collapsed: untyped, outline_level: Integer?) -> PendingRow
1910
+ def with_outline(hidden:, collapsed:, outline_level:)
1911
+ PendingRow.new(@index, @values, @styles, @format_codes, @width, @height, hidden, @custom_height, collapsed, outline_level, @style, @clock)
1912
+ end
1913
+
1914
+ # Returns whether every cell of the row is within Excel's row and column limits.
1915
+ #: () -> bool
1916
+ def within_limits?
1917
+ Elements::Cell.valid_coordinates?(@index, 0) && @width <= 16_384
1918
+ end
1919
+
1920
+ # Returns the row's cells with their style names, as {WorksheetBuilder#build} gives them.
1921
+ #: () -> Array[Elements::Cell]
1922
+ def named_cells
1923
+ values = @values
1924
+ styles = @styles
1925
+ codes = @format_codes
1926
+ style_lookup = styles.is_a?(Array)
1927
+ code_lookup = codes.is_a?(Array)
1928
+ all_valid = within_limits?
1929
+ cells = [] #: Array[Elements::Cell]
1930
+ col_index = 0
1931
+ while col_index < @width
1932
+ value = col_index < values.size ? values[col_index] : nil
1933
+ style = style_lookup ? styles[col_index] : styles
1934
+ unless value.nil? && style.nil?
1935
+ code = code_lookup ? codes[col_index] : codes
1936
+ cells << PendingRow.cell(@index, col_index, value, style, code, all_valid || Elements::Cell.valid_coordinates?(@index, col_index))
1937
+ end
1938
+ col_index += 1
1939
+ end
1940
+ cells
1941
+ end
1942
+
1943
+ #: (Array[Elements::Cell] cells, untyped style_index) -> Elements::Row
1944
+ def to_row(cells, style_index)
1945
+ Elements::Row.new(
1946
+ index: @index,
1947
+ cells: cells,
1948
+ height: @height,
1949
+ hidden: @hidden,
1950
+ custom_height: @custom_height,
1951
+ collapsed: @collapsed,
1952
+ outline_level: @outline_level,
1953
+ style_index: style_index,
1954
+ unmapped_data: Elements::EMPTY_HASH
1955
+ )
1956
+ end
1957
+
1958
+ # Creates a cell for +value+ with +style+ (a name, an index, or nil).
1959
+ # +valid_coordinates+ tells whether the cell is within Excel's limits; a valid cell
1960
+ # has no errors, so it skips the checks of Cell.new.
1961
+ #: (Integer row_index, Integer column_index, untyped value, untyped style, String? format_code, bool valid_coordinates) -> Elements::Cell
1962
+ def self.cell(row_index, column_index, value, style, format_code, valid_coordinates)
1963
+ formula = nil
1964
+ if value.is_a?(Elements::Formula)
1965
+ formula = value
1966
+ value = formula.cached_value
1967
+ valid_coordinates &&= Elements::Cell.valid_value?(value)
1968
+ end
1969
+ raw_value = value&.to_s
1970
+ if valid_coordinates && !style.is_a?(Integer)
1971
+ Elements::Cell.fast_create(row_index, column_index, value, style, formula, raw_value, format_code)
1972
+ else
1973
+ Elements::Cell.new(row_index: row_index, column_index: column_index, value: value, formula: formula,
1974
+ style: style, raw_value: raw_value, format_code: format_code)
1975
+ end
1976
+ end
1977
+ end
1978
+
1979
+ # The state of a sheet when its block ended: the worksheet without its rows, the
1980
+ # pending rows, and the hyperlinks and comments to attach to their cells.
1981
+ #
1982
+ # @api private
1983
+ class Snapshot
1984
+ # The worksheet with every part except its rows.
1985
+ #: Elements::Worksheet
1986
+ attr_reader :frame
1987
+ #: Array[PendingRow]
1988
+ attr_reader :rows
1989
+ # The style log clock when each column's style was set.
1990
+ #: Hash[Integer, Integer]
1991
+ attr_reader :column_style_clocks
1992
+
1993
+ #: (Elements::Worksheet frame, Array[PendingRow] rows, Hash[String, untyped] hyperlinks, Hash[String, untyped] comments, Hash[String, Array[untyped]] threaded_comments, Hash[Integer, Integer] column_style_clocks) -> void
1994
+ def initialize(frame, rows, hyperlinks, comments, threaded_comments, column_style_clocks)
1995
+ @frame = frame
1996
+ @rows = rows
1997
+ @column_style_clocks = column_style_clocks
1998
+ @hyperlinks = hyperlinks
1999
+ @comments = comments
2000
+ @threaded_comments = threaded_comments
2001
+ @links = !(hyperlinks.empty? && comments.empty? && threaded_comments.empty?)
2002
+ end
2003
+
2004
+ # Returns the worksheet with +rows+, or with the rows' named cells by default.
2005
+ #: (?Array[Elements::Row]? rows, ?Array[Elements::Column]? columns) -> Elements::Worksheet
2006
+ def worksheet(rows = nil, columns = nil)
2007
+ rows ||= @rows.map { |row| row.to_row(attach_links(row.named_cells), row.style) }
2008
+ @frame.with(rows: rows, columns: columns || @frame.columns, errors: nil)
2009
+ end
2010
+
2011
+ # Attaches the sheet's hyperlinks and comments to the cells they refer to.
2012
+ #: (Array[Elements::Cell] cells) -> Array[Elements::Cell]
2013
+ def attach_links(cells)
2014
+ return cells unless @links
2015
+
2016
+ cells.map do |cell|
2017
+ hl = @hyperlinks[cell.ref]
2018
+ cm = @comments[cell.ref]
2019
+ tcs = @threaded_comments[cell.ref]
2020
+ if hl || cm || tcs
2021
+ cell.with(
2022
+ hyperlink: hl || cell.hyperlink,
2023
+ comment: cm || cell.comment,
2024
+ threaded_comments: (tcs ? (cell.threaded_comments + tcs) : cell.threaded_comments)
2025
+ )
2026
+ else
2027
+ cell
2028
+ end
2029
+ end
2030
+ end
2031
+ end
2032
+ end
2033
+
2034
+ # Stands in for the {Elements::Worksheet} of a sheet defined in {Xlsxrb.build}, as
2035
+ # returned by {WorkbookBuilder#sheet}. It answers the same methods with the same
2036
+ # results. The worksheet is built the first time one of them is called, or when the
2037
+ # object is frozen (as Ractor.make_shareable does), so a sheet whose return value is
2038
+ # never used costs nothing.
2039
+ #
2040
+ # @deprecated Read the sheet from the workbook that {Xlsxrb.build} returns. In version
2041
+ # 0.3.0, {WorkbookBuilder#sheet} will return the sheet's {WorksheetBuilder}, and
2042
+ # {WorkbookBuilder#[]} will return the {WorksheetBuilder} of an existing sheet.
2043
+ # @api public
2044
+ class DeferredWorksheet
2045
+ DEPRECATION_MESSAGE = "Using the sheet that WorkbookBuilder#sheet and #[] return is deprecated; " \
2046
+ "read it from the workbook that Xlsxrb.build returns. In version 0.3.0, sheet will return " \
2047
+ "the sheet's WorksheetBuilder, and #[] will return the WorksheetBuilder of an existing sheet."
2048
+
2049
+ #: (WorksheetBuilder::Snapshot snapshot) -> void
2050
+ def initialize(snapshot)
2051
+ @snapshot = snapshot
2052
+ @built_worksheet = nil
2053
+ end
2054
+
2055
+ # Returns the worksheet, building it on first use.
2056
+ #
2057
+ # @return [Elements::Worksheet]
2058
+ # @api public
2059
+ #: () -> Elements::Worksheet
2060
+ def worksheet = built_worksheet
2061
+
2062
+ #: (untyped other) -> bool
2063
+ def ==(other)
2064
+ built_worksheet == (other.is_a?(DeferredWorksheet) ? other.built_worksheet : other)
2065
+ end
2066
+
2067
+ #: (untyped other) -> bool
2068
+ def eql?(other)
2069
+ built_worksheet.eql?(other.is_a?(DeferredWorksheet) ? other.built_worksheet : other)
2070
+ end
2071
+
2072
+ #: () -> Integer
2073
+ def hash = built_worksheet.hash
2074
+
2075
+ #: () -> String
2076
+ def inspect = built_worksheet.inspect
2077
+
2078
+ #: () -> String
2079
+ def to_s = built_worksheet.to_s
2080
+
2081
+ #: (untyped printer) -> untyped
2082
+ def pretty_print(printer) = printer.pp(built_worksheet)
2083
+
2084
+ # Builds the worksheet before freezing, so that a frozen stand-in still answers.
2085
+ #: () -> self
2086
+ def freeze
2087
+ built_worksheet
2088
+ @snapshot = nil
2089
+ super
2090
+ end
2091
+
2092
+ # Elements::Worksheet methods, written out as the method_missing policy in
2093
+ # ARCHITECTURE.md requires. A test checks that they cover every public method.
2094
+
2095
+ #: (String | Symbol | Integer ref_or_row, ?Integer | String | Symbol | nil col) -> Elements::Cell?
2096
+ def [](ref_or_row, col = nil) = built_worksheet[ref_or_row, col]
2097
+
2098
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2099
+ def all?(...) = built_worksheet.all?(...)
2100
+
2101
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2102
+ def any?(...) = built_worksheet.any?(...)
2103
+
2104
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2105
+ def auto_filter(...) = built_worksheet.auto_filter(...)
2106
+
2107
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2108
+ def background_image(...) = built_worksheet.background_image(...)
2109
+
2110
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2111
+ def cell_watches(...) = built_worksheet.cell_watches(...)
2112
+
2113
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2114
+ def cells(...) = built_worksheet.cells(...)
2115
+
2116
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2117
+ def chain(...) = built_worksheet.chain(...)
2118
+
2119
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2120
+ def charts(...) = built_worksheet.charts(...)
2121
+
2122
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2123
+ def chunk(...) = built_worksheet.chunk(...)
2124
+
2125
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2126
+ def chunk_while(...) = built_worksheet.chunk_while(...)
2127
+
2128
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2129
+ def code_name(...) = built_worksheet.code_name(...)
2130
+
2131
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2132
+ def collect(...) = built_worksheet.collect(...)
2133
+
2134
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2135
+ def collect_concat(...) = built_worksheet.collect_concat(...)
2136
+
2137
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2138
+ def column_breaks(...) = built_worksheet.column_breaks(...)
2139
+
2140
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2141
+ def column_range(...) = built_worksheet.column_range(...)
2142
+
2143
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2144
+ def columns(...) = built_worksheet.columns(...)
2145
+
2146
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2147
+ def comment(...) = built_worksheet.comment(...)
2148
+
2149
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2150
+ def comments(...) = built_worksheet.comments(...)
2151
+
2152
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2153
+ def comments_by_ref(...) = built_worksheet.comments_by_ref(...)
2154
+
2155
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2156
+ def compact(...) = built_worksheet.compact(...)
2157
+
2158
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2159
+ def conditional_formats(...) = built_worksheet.conditional_formats(...)
2160
+
2161
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2162
+ def count(...) = built_worksheet.count(...)
2163
+
2164
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2165
+ def cycle(...) = built_worksheet.cycle(...)
2166
+
2167
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2168
+ def data_validations(...) = built_worksheet.data_validations(...)
2169
+
2170
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2171
+ def date1904?(...) = built_worksheet.date1904?(...)
2172
+
2173
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2174
+ def deconstruct(...) = built_worksheet.deconstruct(...)
2175
+
2176
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2177
+ def deconstruct_keys(...) = built_worksheet.deconstruct_keys(...)
2178
+
2179
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2180
+ def detect(...) = built_worksheet.detect(...)
2181
+
2182
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2183
+ def dimension(...) = built_worksheet.dimension(...)
2184
+
2185
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2186
+ def dimension_bounds(...) = built_worksheet.dimension_bounds(...)
2187
+
2188
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2189
+ def drop(...) = built_worksheet.drop(...)
2190
+
2191
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2192
+ def drop_while(...) = built_worksheet.drop_while(...)
2193
+
2194
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2195
+ def each(...) = built_worksheet.each(...)
2196
+
2197
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2198
+ def each_cell(...) = built_worksheet.each_cell(...)
2199
+
2200
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2201
+ def each_cons(...) = built_worksheet.each_cons(...)
2202
+
2203
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2204
+ def each_entry(...) = built_worksheet.each_entry(...)
2205
+
2206
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2207
+ def each_row(...) = built_worksheet.each_row(...)
2208
+
2209
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2210
+ def each_row_values(...) = built_worksheet.each_row_values(...)
2211
+
2212
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2213
+ def each_slice(...) = built_worksheet.each_slice(...)
2214
+
2215
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2216
+ def each_with_index(...) = built_worksheet.each_with_index(...)
2217
+
2218
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2219
+ def each_with_object(...) = built_worksheet.each_with_object(...)
2220
+
2221
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2222
+ def entries(...) = built_worksheet.entries(...)
2223
+
2224
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2225
+ def errors(...) = built_worksheet.errors(...)
2226
+
2227
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2228
+ def filter(...) = built_worksheet.filter(...)
2229
+
2230
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2231
+ def filter_columns(...) = built_worksheet.filter_columns(...)
2232
+
2233
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2234
+ def filter_map(...) = built_worksheet.filter_map(...)
2235
+
2236
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2237
+ def find(...) = built_worksheet.find(...)
2238
+
2239
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2240
+ def find_all(...) = built_worksheet.find_all(...)
2241
+
2242
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2243
+ def find_index(...) = built_worksheet.find_index(...)
2244
+
2245
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2246
+ def first(...) = built_worksheet.first(...)
2247
+
2248
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2249
+ def first_row(...) = built_worksheet.first_row(...)
2250
+
2251
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2252
+ def fit_to_page?(...) = built_worksheet.fit_to_page?(...)
2253
+
2254
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2255
+ def flat_map(...) = built_worksheet.flat_map(...)
2256
+
2257
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2258
+ def formatted_value(...) = built_worksheet.formatted_value(...)
2259
+
2260
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2261
+ def freeze_pane(...) = built_worksheet.freeze_pane(...)
2262
+
2263
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2264
+ def full_calc_on_load?(...) = built_worksheet.full_calc_on_load?(...)
2265
+
2266
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2267
+ def grep(...) = built_worksheet.grep(...)
2268
+
2269
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2270
+ def grep_v(...) = built_worksheet.grep_v(...)
2271
+
2272
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2273
+ def group_by(...) = built_worksheet.group_by(...)
2274
+
2275
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2276
+ def header_footer(...) = built_worksheet.header_footer(...)
2277
+
2278
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2279
+ def header_footer_images(...) = built_worksheet.header_footer_images(...)
2280
+
2281
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2282
+ def hidden?(...) = built_worksheet.hidden?(...)
2283
+
2284
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2285
+ def hyperlink(...) = built_worksheet.hyperlink(...)
2286
+
2287
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2288
+ def hyperlinks(...) = built_worksheet.hyperlinks(...)
2289
+
2290
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2291
+ def ignored_errors(...) = built_worksheet.ignored_errors(...)
2292
+
2293
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2294
+ def images(...) = built_worksheet.images(...)
2295
+
2296
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2297
+ def images_at(...) = built_worksheet.images_at(...)
2298
+
2299
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2300
+ def include?(...) = built_worksheet.include?(...)
2301
+
2302
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2303
+ def inject(...) = built_worksheet.inject(...)
2304
+
2305
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2306
+ def last_row(...) = built_worksheet.last_row(...)
2307
+
2308
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2309
+ def lazy(...) = built_worksheet.lazy(...)
2310
+
2311
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2312
+ def map(...) = built_worksheet.map(...)
2313
+
2314
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2315
+ def max(...) = built_worksheet.max(...)
2316
+
2317
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2318
+ def max_by(...) = built_worksheet.max_by(...)
2319
+
2320
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2321
+ def member?(...) = built_worksheet.member?(...)
2322
+
2323
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2324
+ def merged_cells(...) = built_worksheet.merged_cells(...)
2325
+
2326
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2327
+ def min(...) = built_worksheet.min(...)
2328
+
2329
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2330
+ def min_by(...) = built_worksheet.min_by(...)
2331
+
2332
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2333
+ def minmax(...) = built_worksheet.minmax(...)
2334
+
2335
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2336
+ def minmax_by(...) = built_worksheet.minmax_by(...)
2337
+
2338
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2339
+ def name(...) = built_worksheet.name(...)
2340
+
2341
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2342
+ def none?(...) = built_worksheet.none?(...)
2343
+
2344
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2345
+ def one?(...) = built_worksheet.one?(...)
2346
+
2347
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2348
+ def outline_properties(...) = built_worksheet.outline_properties(...)
2349
+
2350
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2351
+ def pad_empty_cells?(...) = built_worksheet.pad_empty_cells?(...)
2352
+
2353
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2354
+ def pad_empty_rows?(...) = built_worksheet.pad_empty_rows?(...)
2355
+
2356
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2357
+ def page_margins(...) = built_worksheet.page_margins(...)
2358
+
2359
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2360
+ def page_setup(...) = built_worksheet.page_setup(...)
2361
+
2362
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2363
+ def partition(...) = built_worksheet.partition(...)
2364
+
2365
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2366
+ def phonetic_properties(...) = built_worksheet.phonetic_properties(...)
2367
+
2368
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2369
+ def pivot_tables(...) = built_worksheet.pivot_tables(...)
2370
+
2371
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2372
+ def print_area(...) = built_worksheet.print_area(...)
2373
+
2374
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2375
+ def print_options(...) = built_worksheet.print_options(...)
2376
+
2377
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2378
+ def print_titles(...) = built_worksheet.print_titles(...)
2379
+
2380
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2381
+ def protected_ranges(...) = built_worksheet.protected_ranges(...)
2382
+
2383
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2384
+ def reduce(...) = built_worksheet.reduce(...)
2385
+
2386
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2387
+ def reject(...) = built_worksheet.reject(...)
2388
+
2389
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2390
+ def reverse_each(...) = built_worksheet.reverse_each(...)
2391
+
2392
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2393
+ def row_at(...) = built_worksheet.row_at(...)
2394
+
2395
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2396
+ def row_breaks(...) = built_worksheet.row_breaks(...)
2397
+
2398
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2399
+ def row_range(...) = built_worksheet.row_range(...)
2400
+
2401
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2402
+ def rows(...) = built_worksheet.rows(...)
2403
+
2404
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2405
+ def select(...) = built_worksheet.select(...)
2406
+
2407
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2408
+ def selection(...) = built_worksheet.selection(...)
2409
+
2410
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2411
+ def shapes(...) = built_worksheet.shapes(...)
2412
+
2413
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2414
+ def sheet_calc_properties(...) = built_worksheet.sheet_calc_properties(...)
2415
+
2416
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2417
+ def sheet_format(...) = built_worksheet.sheet_format(...)
2418
+
2419
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2420
+ def sheet_properties(...) = built_worksheet.sheet_properties(...)
2421
+
2422
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2423
+ def sheet_protection(...) = built_worksheet.sheet_protection(...)
2424
+
2425
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2426
+ def sheet_view(...) = built_worksheet.sheet_view(...)
2427
+
2428
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2429
+ def slice_after(...) = built_worksheet.slice_after(...)
2430
+
2431
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2432
+ def slice_before(...) = built_worksheet.slice_before(...)
2433
+
2434
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2435
+ def slice_when(...) = built_worksheet.slice_when(...)
2436
+
2437
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2438
+ def sort(...) = built_worksheet.sort(...)
2439
+
2440
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2441
+ def sort_by(...) = built_worksheet.sort_by(...)
2442
+
2443
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2444
+ def sort_state(...) = built_worksheet.sort_state(...)
2445
+
2446
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2447
+ def sparkline_groups(...) = built_worksheet.sparkline_groups(...)
2448
+
2449
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2450
+ def split_pane(...) = built_worksheet.split_pane(...)
2451
+
2452
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2453
+ def state(...) = built_worksheet.state(...)
2454
+
2455
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2456
+ def styles(...) = built_worksheet.styles(...)
2457
+
2458
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2459
+ def sum(...) = built_worksheet.sum(...)
2460
+
2461
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2462
+ def tab_color(...) = built_worksheet.tab_color(...)
2463
+
2464
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2465
+ def tables(...) = built_worksheet.tables(...)
2466
+
2467
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2468
+ def take(...) = built_worksheet.take(...)
2469
+
2470
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2471
+ def take_while(...) = built_worksheet.take_while(...)
2472
+
2473
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2474
+ def tally(...) = built_worksheet.tally(...)
2475
+
2476
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2477
+ def threaded_comment(...) = built_worksheet.threaded_comment(...)
2478
+
2479
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2480
+ def threaded_comments(...) = built_worksheet.threaded_comments(...)
2481
+
2482
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2483
+ def threaded_comments_at(...) = built_worksheet.threaded_comments_at(...)
2484
+
2485
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2486
+ def threaded_comments_by_ref(...) = built_worksheet.threaded_comments_by_ref(...)
2487
+
2488
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2489
+ def to_a(...) = built_worksheet.to_a(...)
2490
+
2491
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2492
+ def to_h(...) = built_worksheet.to_h(...)
2493
+
2494
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2495
+ def to_set(...) = built_worksheet.to_set(...)
2496
+
2497
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2498
+ def trim_empty_rows?(...) = built_worksheet.trim_empty_rows?(...)
2499
+
2500
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2501
+ def uniq(...) = built_worksheet.uniq(...)
2502
+
2503
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2504
+ def unmapped_data(...) = built_worksheet.unmapped_data(...)
2505
+
2506
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2507
+ def valid?(...) = built_worksheet.valid?(...)
2508
+
2509
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2510
+ def very_hidden?(...) = built_worksheet.very_hidden?(...)
2511
+
2512
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2513
+ def visible?(...) = built_worksheet.visible?(...)
2514
+
2515
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2516
+ def with(...) = built_worksheet.with(...)
2517
+
2518
+ #: (*untyped, **untyped) ?{ (*untyped) -> untyped } -> untyped
2519
+ def zip(...) = built_worksheet.zip(...)
2520
+
2521
+ protected
2522
+
2523
+ # Returns the worksheet, building it on first use with a deprecation warning that
2524
+ # points at the caller of the public method.
2525
+ #: () -> Elements::Worksheet
2526
+ def built_worksheet
2527
+ @built_worksheet ||= begin
2528
+ Deprecation.warn(DEPRECATION_MESSAGE, uplevel: 2)
2529
+ @snapshot&.worksheet || raise(Error, "worksheet is not available")
2530
+ end
2531
+ end
1824
2532
  end
1825
2533
 
1826
2534
  # Builder context for configuring an Excel Table (ListObject) in block form.