class Xlsxrb::StreamSheet
Represents a worksheet being streamed sequentially from an XLSX file. Provides O(1) constant-memory streaming over rows and cells.
Call {#load} (or {#to_worksheet}) to convert this streaming sheet into an in-memory {Elements::Worksheet} supporting coordinate random access (‘sheet`).
@example Iterate rows and cells in streaming mode (O(1) memory)
Xlsxrb.read("large_data.xlsx") do |sheet| puts "Processing sheet: #{sheet.name}" sheet.each_row do |row| row.each_cell do |cell| puts "#{cell.ref}: #{cell.value}" end end end
@example Load into an in-memory Worksheet for coordinate random access
wb = Xlsxrb.read("data.xlsx") doc_sheet = wb.sheets.first.load puts doc_sheet["A1"].value
@api public
Attributes
String
@return [String] The sheet name. @api public
Public Class Methods
(String name, String sheet_xml, Array[String] shared_strings, ?Hash[untyped, untyped]? styles) → void
Source
# File lib/xlsxrb/stream_sheet.rb, line 43 def initialize(name, sheet_xml, shared_strings, styles = nil) @name = name @sheet_xml = sheet_xml @shared_strings = shared_strings @styles = styles end
Initializes a streaming worksheet context.
@param name [String] The sheet name. @param sheet_xml [String] Raw XML content of the worksheet. @param shared_strings [Array<String>] Shared strings table. @param styles [Hash, nil] Optional parsed styles hash.
Public Instance Methods
Source
# File lib/xlsxrb/stream_sheet.rb, line 103 def each(&) each_row(&) end
Default Enumerable iteration delegates to {#each_row}.
@overload each(&block)
@yield [row] @yieldparam row [StreamRow, Elements::Row] @return [void]
@overload each
@return [Enumerator<StreamRow | Elements::Row, void>]
@api public
() { (Elements::Cell) → void } → void
() → Enumerator[Elements::Cell, void]
Source
# File lib/xlsxrb/stream_sheet.rb, line 82 def each_cell(&) return enum_for(:each_cell) unless block_given? each_row do |row| row.each_cell(&) end end
Source
# File lib/xlsxrb/stream_sheet.rb, line 63 def each_row(&) return enum_for(:each_row) unless block_given? Ooxml::WorksheetParser.each_row(@sheet_xml, shared_strings: @shared_strings, &) end
() → Elements::Worksheet
Source
# File lib/xlsxrb/stream_sheet.rb, line 114 def load Xlsxrb.send(:build_worksheet, @name, @sheet_xml, @shared_strings, @styles) end
Loads this sheet completely into an in-memory {Elements::Worksheet}, enabling coordinate random access (‘sheet`), row lookups (row_at), and immutable cell updates (update_cell).
@return [Elements::Worksheet] The fully parsed in-memory worksheet. @api public