xlsxrb 0.1.6 → 0.1.8

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.
@@ -3,7 +3,16 @@
3
3
  module Xlsxrb
4
4
  module Elements
5
5
  # Represents a single cell in a worksheet.
6
- # All indices are 0-based.
6
+ # All row and column indices are 0-based.
7
+ #
8
+ # @example Access cell properties
9
+ # cell = sheet["A1"]
10
+ # cell.value # raw value
11
+ # cell.ref # "A1"
12
+ # cell.to_i # integer value
13
+ # cell.to_date # Date value
14
+ #
15
+ # @api public
7
16
  class Cell < Data
8
17
  attr_reader row_index(): untyped
9
18
 
@@ -4,6 +4,11 @@ module Xlsxrb
4
4
  module Elements
5
5
  # Represents column formatting in a worksheet.
6
6
  # index is 0-based.
7
+ #
8
+ # @example
9
+ # col = Elements::Column.new(index: 0, width: 25.0)
10
+ #
11
+ # @api public
7
12
  class Column < Data
8
13
  attr_reader index(): untyped
9
14
 
@@ -0,0 +1,70 @@
1
+ # Generated from lib/xlsxrb/elements/coordinate_access.rb with RBS::Inline
2
+
3
+ module Xlsxrb
4
+ module Elements
5
+ # Mixin providing coordinate-based and random-access cell/row lookups
6
+ # for in-memory worksheet structures.
7
+ #
8
+ # Expects the including class to provide a `#rows` method returning an `Array<Elements::Row>`.
9
+ #
10
+ # @api public
11
+ module CoordinateAccess
12
+ # Returns a Hash mapping Excel cell references (e.g. "A1") to Cell objects.
13
+ #
14
+ # @return [Hash<String, Elements::Cell>]
15
+ # : () -> Hash[String, Elements::Cell]
16
+ def cells_hash: () -> Hash[String, Elements::Cell]
17
+
18
+ # Returns all cells ordered by row and column index.
19
+ #
20
+ # @return [Array<Elements::Cell>]
21
+ # @api public
22
+ # : () -> Array[Elements::Cell]
23
+ def cells: () -> Array[Elements::Cell]
24
+
25
+ # Access a cell by its Excel-style reference (e.g. "A1").
26
+ #
27
+ # @example
28
+ # sheet["A1"] #=> #<Elements::Cell value="Hello">
29
+ #
30
+ # @param ref [String, Symbol] Cell reference (e.g. "A1" or :A1).
31
+ # @return [Elements::Cell, nil]
32
+ # @api public
33
+ # : (String | Symbol ref) -> Elements::Cell?
34
+ def []: (String | Symbol ref) -> Elements::Cell?
35
+
36
+ # Returns the row at the given 0-based index, or nil.
37
+ #
38
+ # @param index [Integer] 0-based row index.
39
+ # @return [Elements::Row, nil]
40
+ # @api public
41
+ # : (Integer index) -> Elements::Row?
42
+ def row_at: (Integer index) -> Elements::Row?
43
+
44
+ # Returns the first row in the sheet, or nil.
45
+ #
46
+ # @return [Elements::Row, nil]
47
+ # @api public
48
+ # : () -> Elements::Row?
49
+ def first_row: () -> Elements::Row?
50
+
51
+ # Returns the last row in the sheet, or nil.
52
+ #
53
+ # @return [Elements::Row, nil]
54
+ # @api public
55
+ # : () -> Elements::Row?
56
+ def last_row: () -> Elements::Row?
57
+
58
+ # Returns the raw cell value at the given Excel-style reference (e.g. "A1").
59
+ #
60
+ # @example
61
+ # sheet.cell_value("A1") #=> "Sales Report"
62
+ #
63
+ # @param ref [String] Cell reference (e.g. "A1").
64
+ # @return [Object, nil]
65
+ # @api public
66
+ # : (String ref) -> untyped
67
+ def cell_value: (String ref) -> untyped
68
+ end
69
+ end
70
+ end
@@ -3,7 +3,14 @@
3
3
  module Xlsxrb
4
4
  module Elements
5
5
  # Represents a single row in a worksheet.
6
- # index is 0-based.
6
+ # All row and column indices are 0-based.
7
+ #
8
+ # @example Access cell by index or symbol
9
+ # row = sheet.row_at(0)
10
+ # cell = row[0] # cell at column 0
11
+ # row.to_a # array of cell values
12
+ #
13
+ # @api public
7
14
  class Row < Data
8
15
  attr_reader index(): untyped
9
16
 
@@ -8,8 +8,12 @@ module Xlsxrb
8
8
 
9
9
  EMPTY_CELLS: untyped
10
10
 
11
- # Represents a formula with an optional cached value.
12
- # Optional: type (:shared, :array), ref (range), shared_index (si for shared formulas)
11
+ # Represents an Excel formula with an optional cached value and calculation properties.
12
+ #
13
+ # @example Create a formula
14
+ # formula = Elements::Formula.new(expression: "SUM(A1:A10)")
15
+ #
16
+ # @api public
13
17
  class Formula < Data
14
18
  attr_reader expression(): untyped
15
19
 
@@ -44,6 +48,7 @@ module Xlsxrb
44
48
  end
45
49
 
46
50
  # Represents a cell error value (e.g. #N/A, #REF!, #DIV/0!).
51
+ # @api public
47
52
  VALID_ERROR_CODES: untyped
48
53
 
49
54
  class CellError < Data
@@ -57,9 +62,12 @@ module Xlsxrb
57
62
  def members: () -> [ :code ]
58
63
  end
59
64
 
60
- # Represents a rich text string with formatting runs.
61
- # runs: array of hashes, each with :text and optional :font (hash of font properties).
62
- # Font properties: :bold, :italic, :underline, :sz, :color, :name
65
+ # Represents a rich text string with multiple formatting runs.
66
+ #
67
+ # @example
68
+ # rt = Elements::RichText.new(runs: [{ text: "Hello ", font: { bold: true } }, { text: "World" }])
69
+ #
70
+ # @api public
63
71
  class RichText < Data
64
72
  attr_reader runs(): untyped
65
73
 
@@ -2,7 +2,14 @@
2
2
 
3
3
  module Xlsxrb
4
4
  module Elements
5
- # Represents an entire XLSX workbook.
5
+ # Represents an entire in-memory XLSX workbook.
6
+ #
7
+ # @example Access sheets
8
+ # workbook = Xlsxrb.read("report.xlsx")
9
+ # sheet = workbook.sheet(0) # or workbook["Sheet1"]
10
+ # workbook.each { |s| puts s.name }
11
+ #
12
+ # @api public
6
13
  class Workbook < Data
7
14
  attr_reader sheets(): untyped
8
15
 
@@ -2,26 +2,135 @@
2
2
 
3
3
  module Xlsxrb
4
4
  module Elements
5
- # Represents a single worksheet in a workbook.
6
- class Worksheet < Data
7
- attr_reader name(): untyped
5
+ # Represents a single fully parsed, in-memory worksheet in a workbook.
6
+ # Provides coordinate random access (sheet["A1"]), row lookups (row_at),
7
+ # and immutable cell updates (update_cell).
8
+ #
9
+ # @example Access cells and rows
10
+ # sheet = workbook.sheet(0).load
11
+ # cell = sheet["A1"]
12
+ # row = sheet.row_at(0)
13
+ #
14
+ # @api public
15
+ class Worksheet
16
+ attr_reader name: untyped
8
17
 
9
- attr_reader rows(): untyped
18
+ attr_reader rows: untyped
10
19
 
11
- attr_reader columns(): untyped
20
+ attr_reader columns: untyped
12
21
 
13
- attr_reader charts(): untyped
22
+ attr_reader charts: untyped
14
23
 
15
- attr_reader unmapped_data(): untyped
24
+ attr_reader unmapped_data: untyped
16
25
 
17
- attr_reader errors(): untyped
26
+ attr_reader errors: untyped
18
27
 
19
- def self.new: (untyped name, untyped rows, untyped columns, untyped charts, untyped unmapped_data, untyped errors) -> instance
20
- | (name: untyped, rows: untyped, columns: untyped, charts: untyped, unmapped_data: untyped, errors: untyped) -> instance
28
+ # @param name [String] The worksheet name (max 31 characters).
29
+ # @param rows [Array<Elements::Row>] Rows in the sheet.
30
+ # @param columns [Array<Elements::Column>] Column definitions.
31
+ # @param charts [Array<Hash>] Charts in the sheet.
32
+ # @param unmapped_data [Hash] Additional metadata for round-tripping.
33
+ # @param errors [Array<String>, nil] Validation errors.
34
+ # : (name: String, ?rows: Array[Elements::Row], ?columns: Array[Elements::Column], ?charts: Array[Hash[Symbol, untyped]], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?) -> void
35
+ def initialize: (name: String, ?rows: Array[Elements::Row], ?columns: Array[Elements::Column], ?charts: Array[Hash[Symbol, untyped]], ?unmapped_data: Hash[untyped, untyped], ?errors: Array[String]?) -> void
21
36
 
22
- def self.members: () -> [ :name, :rows, :columns, :charts, :unmapped_data, :errors ]
37
+ # Iterate over rows in the worksheet.
38
+ #
39
+ # @example
40
+ # sheet.each do |row|
41
+ # puts row.to_a.inspect
42
+ # end
43
+ #
44
+ # @yield [row]
45
+ # @yieldparam row [Elements::Row]
46
+ # @return [Enumerator, void]
47
+ # @api public
48
+ # : () { (Elements::Row) -> void } -> void
49
+ # : | () -> Enumerator[Elements::Row, void]
50
+ def each: () { (Elements::Row) -> void } -> void
23
51
 
24
- def members: () -> [ :name, :rows, :columns, :charts, :unmapped_data, :errors ]
52
+ # Iterate over rows in the worksheet.
53
+ #
54
+ # @example
55
+ # sheet.each_row do |row|
56
+ # puts "Row #{row.index}: #{row.to_a.inspect}"
57
+ # end
58
+ #
59
+ # @yield [row]
60
+ # @yieldparam row [Elements::Row]
61
+ # @return [Enumerator, void]
62
+ # @api public
63
+ # : () { (Elements::Row) -> void } -> void
64
+ # : | () -> Enumerator[Elements::Row, void]
65
+ def each_row: () { (Elements::Row) -> void } -> void
66
+
67
+ # Iterate over all cells across rows.
68
+ #
69
+ # @yield [cell]
70
+ # @yieldparam cell [Elements::Cell]
71
+ # @return [Enumerator, void]
72
+ # @api public
73
+ # : () { (Elements::Cell) -> void } -> void
74
+ # : | () -> Enumerator[Elements::Cell, void]
75
+ def each_cell: () { (Elements::Cell) -> void } -> void
76
+
77
+ # Returns whether the worksheet is valid according to OOXML specifications.
78
+ #
79
+ # @return [Boolean]
80
+ # : () -> bool
81
+ def valid?: () -> bool
82
+
83
+ # Returns a new Worksheet with the specified cell updated.
84
+ #
85
+ # @example
86
+ # new_sheet = sheet.update_cell("B1", value: "Updated")
87
+ #
88
+ # @param ref [String] The cell reference (e.g. "B1").
89
+ # @param value [Object] The new cell value.
90
+ # @param style_index [Integer, String, nil] Optional new style index.
91
+ # @param formula [Elements::Formula, nil] Optional new formula.
92
+ # @return [Worksheet] A new Worksheet instance.
93
+ # @api public
94
+ # : (String ref, ?value: untyped, ?style_index: Integer | String | nil, ?formula: Elements::Formula?) -> Elements::Worksheet
95
+ def update_cell: (String ref, ?value: untyped, ?style_index: Integer | String | nil, ?formula: Elements::Formula?) -> Elements::Worksheet
96
+
97
+ # Returns a new Worksheet with attributes replaced (Data-like behavior).
98
+ #
99
+ # @param changes [Hash]
100
+ # @return [Worksheet]
101
+ # @api public
102
+ # : (**untyped) -> Elements::Worksheet
103
+ def with: (**untyped) -> Elements::Worksheet
104
+
105
+ # Support pattern matching.
106
+ # : (Array[Symbol]?) -> Hash[Symbol, untyped]
107
+ def deconstruct_keys: (Array[Symbol]?) -> Hash[Symbol, untyped]
108
+
109
+ # Compare worksheets for equality.
110
+ # : (untyped other) -> bool
111
+ def ==: (untyped other) -> bool
112
+
113
+ alias eql? ==
114
+
115
+ # : () -> Integer
116
+ def hash: () -> Integer
117
+
118
+ # Returns self when load is called on an already in-memory Worksheet.
119
+ #
120
+ # @return [Elements::Worksheet]
121
+ # @api public
122
+ # : () -> Elements::Worksheet
123
+ def load: () -> Elements::Worksheet
124
+
125
+ alias to_worksheet load
126
+
127
+ # Validates worksheet name and rows against OOXML limits.
128
+ #
129
+ # @param name [String]
130
+ # @param rows [Array<Elements::Row>]
131
+ # @return [Array<String>] List of errors.
132
+ # : (untyped name, untyped rows) -> Array[String]
133
+ def self.validate: (untyped name, untyped rows) -> Array[String]
25
134
  end
26
135
  end
27
136
  end
@@ -62,6 +62,8 @@ module Xlsxrb
62
62
  def self.fast_scan_rows_direct: (untyped xml_src, untyped shared_strings, untyped part_name) ?{ (?) -> untyped } -> untyped
63
63
 
64
64
  def self.fast_parse_cells_direct: (untyped xml, untyped from, untyped to, untyped shared_strings, untyped row_source) -> untyped
65
+
66
+ def self.fast_scan_cells_direct: (untyped xml, untyped from, untyped to, untyped shared_strings, untyped row_source) ?{ (?) -> untyped } -> untyped
65
67
  end
66
68
  end
67
69
  end
@@ -0,0 +1,125 @@
1
+ # Generated from lib/xlsxrb/stream_row.rb with RBS::Inline
2
+
3
+ module Xlsxrb
4
+ # Streaming row implementation that parses cells on-demand / lazily.
5
+ # Provides O(1) memory consumption even for rows with tens of thousands of columns.
6
+ #
7
+ # @example Streaming cells one-by-one (O(1) memory)
8
+ # row.each_cell do |cell|
9
+ # puts "#{cell.ref}: #{cell.value}"
10
+ # end
11
+ #
12
+ # @example Random access or array conversion (cached on-demand)
13
+ # cell = row[0]
14
+ # values = row.to_a
15
+ #
16
+ # @api public
17
+ class StreamRow
18
+ attr_reader index: untyped
19
+
20
+ attr_reader height: untyped
21
+
22
+ attr_reader hidden: untyped
23
+
24
+ attr_reader custom_height: untyped
25
+
26
+ attr_reader outline_level: untyped
27
+
28
+ # @param index [Integer] 0-based row index.
29
+ # @param xml_bytes [String] Raw ASCII-8BIT XML bytes.
30
+ # @param from [Integer] Byte offset where cells start.
31
+ # @param to [Integer] Byte offset where cells end.
32
+ # @param shared_strings [Array<String>] Shared strings table.
33
+ # @param height [Float, Integer, nil] Row height in points.
34
+ # @param hidden [Boolean] Whether the row is hidden.
35
+ # @param custom_height [Boolean] Whether custom height is set.
36
+ # @param outline_level [Integer, nil] Grouping/outline level.
37
+ # : (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
38
+ def initialize: (index: Integer, xml_bytes: String, from: Integer, to: Integer, shared_strings: Array[String], ?height: Float | Integer | nil, ?hidden: bool, ?custom_height: bool, ?outline_level: Integer | nil) -> void
39
+
40
+ # Iterate over cells in this streaming row one by one.
41
+ #
42
+ # @yield [cell]
43
+ # @yieldparam cell [Elements::Cell]
44
+ # @return [Enumerator, void]
45
+ # @api public
46
+ # : () { (Elements::Cell) -> void } -> void
47
+ # : | () -> Enumerator[Elements::Cell, void]
48
+ def each_cell: () { (Elements::Cell) -> void } -> void
49
+
50
+ # Iterate over cells in this streaming row.
51
+ #
52
+ # @yield [cell]
53
+ # @yieldparam cell [Elements::Cell]
54
+ # @return [Enumerator, void]
55
+ # @api public
56
+ # : () { (Elements::Cell) -> void } -> void
57
+ # : | () -> Enumerator[Elements::Cell, void]
58
+ def each: () { (Elements::Cell) -> void } -> void
59
+
60
+ # Returns all cells as an Array. Cached on first access.
61
+ #
62
+ # @return [Array<Elements::Cell>]
63
+ # @api public
64
+ # : () -> Array[Elements::Cell]
65
+ def cells: () -> Array[Elements::Cell]
66
+
67
+ # Access a cell by 0-based column index, or access row attributes via Symbol.
68
+ #
69
+ # @param col_index [Integer, Symbol] Column index or attribute symbol.
70
+ # @return [Elements::Cell, Object, nil]
71
+ # @api public
72
+ # : (Integer | Symbol col_index) -> untyped
73
+ def []: (Integer | Symbol col_index) -> untyped
74
+
75
+ # Access a cell by 0-based column index.
76
+ #
77
+ # @param col_index [Integer] 0-based column index.
78
+ # @return [Elements::Cell, nil]
79
+ # @api public
80
+ # : (Integer col_index) -> Elements::Cell?
81
+ def cell_at: (Integer col_index) -> Elements::Cell?
82
+
83
+ # Convert row cells to an Array of raw values (sparse columns get nil).
84
+ #
85
+ # @return [Array<Object>]
86
+ # @api public
87
+ # : () -> Array[untyped]
88
+ def to_a: () -> Array[untyped]
89
+
90
+ # Returns cell values as an Array.
91
+ #
92
+ # @return [Array<Object>]
93
+ # @api public
94
+ # : () -> Array[untyped]
95
+ def values: () -> Array[untyped]
96
+
97
+ # Returns whether the row is valid according to OOXML specifications.
98
+ #
99
+ # @return [Boolean]
100
+ # @api public
101
+ # : () -> bool
102
+ def valid?: () -> bool
103
+
104
+ # Unmapped metadata for compatibility with Elements::Row.
105
+ #
106
+ # @return [Hash]
107
+ # @api public
108
+ # : () -> Hash[untyped, untyped]
109
+ def unmapped_data: () -> Hash[untyped, untyped]
110
+
111
+ # Validation errors for compatibility with Elements::Row.
112
+ #
113
+ # @return [Array<String>]
114
+ # @api public
115
+ # : () -> Array[String]
116
+ def errors: () -> Array[String]
117
+
118
+ # Human-readable representation.
119
+ #
120
+ # @return [String]
121
+ # @api public
122
+ # : () -> String
123
+ def inspect: () -> String
124
+ end
125
+ end