class Xlsxrb::StreamRow
Streaming row implementation that parses cells on-demand / lazily. Provides O(1) memory consumption even for rows with tens of thousands of columns.
@example Streaming cells one-by-one (O(1) memory)
row.each_cell do |cell| puts "#{cell.ref}: #{cell.value}" end
@example Random access or array conversion (cached on-demand)
cell = row[0] values = row.to_a
@api public
Attributes
untyped
untyped
untyped
untyped
Public Class Methods
(untyped index, untyped xml_bytes, untyped from, untyped to, untyped shared_strings, ?untyped prefix, ?untyped height, ?untyped hidden, ?untyped custom_height, ?untyped outline_level) → untyped
Source
# File lib/xlsxrb/stream_row.rb, line 51 def self.fast_create(index, xml_bytes, from, to, shared_strings, prefix = "", height = nil, hidden = false, custom_height = false, outline_level = nil) inst = allocate inst.instance_variable_set(:@index, index) inst.instance_variable_set(:@xml, xml_bytes) inst.instance_variable_set(:@from, from) inst.instance_variable_set(:@to, to) inst.instance_variable_set(:@shared_strings, shared_strings) inst.instance_variable_set(:@prefix, prefix) inst.instance_variable_set(:@height, height) inst.instance_variable_set(:@hidden, hidden) inst.instance_variable_set(:@custom_height, custom_height) inst.instance_variable_set(:@outline_level, outline_level) inst.instance_variable_set(:@cells, nil) inst end
rubocop:disable Style/OptionalBooleanParameter
(index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?prefix: String, ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) → void
Source
# File lib/xlsxrb/stream_row.rb, line 35 def initialize(index:, xml_bytes:, from:, to:, shared_strings:, prefix: "", height: nil, hidden: false, custom_height: false, outline_level: nil) @index = index @xml = xml_bytes @from = from @to = to @shared_strings = shared_strings @prefix = prefix @height = height @hidden = hidden @custom_height = custom_height @outline_level = outline_level @cells = nil end
@param index [Integer] 0-based row index. @param xml_bytes [String] Raw ASCII-8BIT XML bytes. @param from [Integer] Byte offset where cells start. @param to [Integer] Byte offset where cells end. @param shared_strings [Array<String>] Shared strings table. @param prefix [String] XML namespace prefix (e.g. “x:” or “”). @param height [Float, Integer, nil] Row height in points. @param hidden [Boolean] Whether the row is hidden. @param custom_height [Boolean] Whether custom height is set. @param outline_level [Integer, nil] Grouping/outline level.
Public Instance Methods
(Integer | Symbol col_index) → untyped
Source
# File lib/xlsxrb/stream_row.rb, line 119 def [](col_index) case col_index when Symbol case col_index when :cells then cells when :index then index when :height then height when :hidden then hidden when :custom_height then custom_height when :outline_level then outline_level when :attrs then { height: height, hidden: hidden, custom_height: custom_height, outline_level: outline_level } end else cells[col_index] end end
Access a cell by 0-based column index, or access row attributes via Symbol.
@param col_index [Integer, Symbol] Column index or attribute symbol. @return [Elements::Cell, Object, nil] @api public
(Integer col_index) → Elements::Cell?
Source
# File lib/xlsxrb/stream_row.rb, line 142 def cell_at(col_index) cells.find { |c| c.column_index == col_index } end
Access a cell by 0-based column index.
@param col_index [Integer] 0-based column index. @return [Elements::Cell, nil] @api public
() → Array[Elements::Cell]
Source
# File lib/xlsxrb/stream_row.rb, line 103 def cells @cells ||= begin arr = [] Ooxml::WorksheetParser.fast_scan_cells_direct(@xml, @from, @to, @shared_strings, @index, @prefix) do |c| arr << c end arr.freeze end end
Returns all cells as an Array. Cached on first access.
@return [Array<Elements::Cell>] @api public
() { (Elements::Cell) → void } → void
() → Enumerator[Elements::Cell, void]
Source
# File lib/xlsxrb/stream_row.rb, line 94 def each(&) each_cell(&) end
Iterate over cells in this streaming row.
@yield [cell] @yieldparam cell [Elements::Cell] @return [Enumerator, void] @api public
() { (Elements::Cell) → void } → void
() → Enumerator[Elements::Cell, void]
Source
# File lib/xlsxrb/stream_row.rb, line 76 def each_cell(&block) return enum_for(:each_cell) unless block if @cells @cells.each(&block) else Ooxml::WorksheetParser.fast_scan_cells_direct(@xml, @from, @to, @shared_strings, @index, @prefix, &block) end end
Iterate over cells in this streaming row one by one.
@yield [cell] @yieldparam cell [Elements::Cell] @return [Enumerator, void] @api public
() → Array[String]
Source
# File lib/xlsxrb/stream_row.rb, line 194 def errors Elements::EMPTY_ERRORS end
Validation errors for compatibility with Elements::Row.
@return [Array<String>] @api public
() → String
Source
# File lib/xlsxrb/stream_row.rb, line 203 def inspect "#<#{self.class.name} index=#{index} height=#{height.inspect} hidden=#{hidden}>" end
Human-readable representation.
@return [String] @api public
() → Array[untyped]
Source
# File lib/xlsxrb/stream_row.rb, line 151 def to_a return [] if cells.empty? max_col = cells.map(&:column_index).max || 0 arr = Array.new(max_col + 1) cells.each do |cell| arr[cell.column_index] = cell.value end arr end
Convert row cells to an Array of raw values (sparse columns get nil).
@return [Array<Object>] @api public
() → Hash[untyped, untyped]
Source
# File lib/xlsxrb/stream_row.rb, line 185 def unmapped_data Elements::EMPTY_HASH end
Unmapped metadata for compatibility with Elements::Row.
@return [Hash] @api public
() → bool
Source
# File lib/xlsxrb/stream_row.rb, line 176 def valid? true end
Returns whether the row is valid according to OOXML specifications.
@return [Boolean] @api public
() → Array[untyped]
Source
# File lib/xlsxrb/stream_row.rb, line 167 def values to_a end
Returns cell values as an Array.
@return [Array<Object>] @api public