Class: Xlsxrb::StreamSheet

Inherits:
Object
  • Object
show all
Defined in:
lib/xlsxrb.rb,
sig/generated/xlsxrb.rbs

Overview

Represents a sheet 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).

Examples:

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

Load into an in-memory Worksheet for coordinate random access

wb = Xlsxrb.read("data.xlsx")
doc_sheet = wb.sheet(0).load
puts doc_sheet["A1"].value

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, sheet_xml, shared_strings, styles = nil) ⇒ StreamSheet

: (String name, String sheet_xml, Array shared_strings, ?Hash[untyped, untyped]? styles) -> void

Parameters:

  • name (String)

    The sheet name.

  • sheet_xml (String)

    Raw XML content of the sheet.

  • shared_strings (Array<String>)

    Shared strings table.

  • styles (Hash, nil) (defaults to: nil)

    Styles table.



707
708
709
710
711
712
# File 'lib/xlsxrb.rb', line 707

def initialize(name, sheet_xml, shared_strings, styles = nil)
  @name = name
  @sheet_xml = sheet_xml
  @shared_strings = shared_strings
  @styles = styles
end

Instance Attribute Details

#nameObject (readonly)

Returns:

  • (Object)


700
701
702
# File 'lib/xlsxrb.rb', line 700

def name
  @name
end

Instance Method Details

#eachvoid #eachEnumerator[StreamRow | Elements::Row, void]

Default Enumerable iteration iterates rows in the streaming sheet.

: () { (StreamRow | Elements::Row) -> void } -> void : () -> Enumerator[StreamRow | Elements::Row, void]

Overloads:

Yields:

  • (row)

Yield Parameters:

Returns:

  • (Enumerator, void)


758
759
760
# File 'lib/xlsxrb.rb', line 758

def each(&)
  each_row(&)
end

#each_cellvoid #each_cellEnumerator[Elements::Cell, void]

Iterate over all cells across rows continuously (O(1) memory).

: () { (Elements::Cell) -> void } -> void : () -> Enumerator[Elements::Cell, void]

Overloads:

  • #each_cellvoid

    This method returns an undefined value.

  • #each_cellEnumerator[Elements::Cell, void]

    Returns:

Yields:

  • (cell)

Yield Parameters:

Returns:

  • (Enumerator, void)


742
743
744
745
746
747
748
# File 'lib/xlsxrb.rb', line 742

def each_cell(&)
  return enum_for(:each_cell) unless block_given?

  each_row do |row|
    row.each_cell(&)
  end
end

#each_rowvoid #each_rowEnumerator[StreamRow | Elements::Row, void]

Iterate over rows in this streaming sheet (O(1) memory).

: () { (StreamRow | Elements::Row) -> void } -> void : () -> Enumerator[StreamRow | Elements::Row, void]

Overloads:

Yields:

  • (row)

Yield Parameters:

Returns:

  • (Enumerator, void)


722
723
724
725
726
727
728
729
730
731
732
# File 'lib/xlsxrb.rb', line 722

def each_row
  return enum_for(:each_row) unless block_given?

  Ooxml::WorksheetParser.each_row(@sheet_xml, shared_strings: @shared_strings) do |row|
    if row.is_a?(Elements::Row) || row.is_a?(StreamRow)
      yield row
    else
      yield Xlsxrb.send(:build_row_from_raw, row)
    end
  end
end

#loadElements::Worksheet Also known as: to_worksheet

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).

: () -> Elements::Worksheet

Returns:



769
770
771
# File 'lib/xlsxrb.rb', line 769

def load
  Xlsxrb.send(:build_worksheet, @name, @sheet_xml, @shared_strings, @styles)
end