class
XlsxParser::Sheet
- XlsxParser::Sheet
- Reference
- Object
Overview
Represents a sheet in an Excel workbook.
The Sheet class provides methods to read data in a sheet.
Defined in:
xlsx-parser/sheet.crConstant Summary
-
FORMULA_TOKEN =
/"(?:[^"]|"")*" | '(?:[^']|'')*' | (?<![A-Za-z0-9_.$]) (\$?)([A-Z]{1,3}) (\$?)(\d+) (?![A-Za-z0-9_(!])/x -
Quoted string, quoted sheet name or cell reference ($A$1) not part of a name, function or sheet name
Constructors
-
.new(book : Book, path : String, name : String, state : String = "visible")
Initializes a new instance of the
Sheetclass, path is the sheet XML path inside the zip.
Class Method Summary
-
.column_index(ref : String) : Int32
Returns the 1-based column index of given cell reference ("AB12" => 28).
-
.column_name(index : Int32) : String
Returns the column name of given 1-based column index (28 => "AB").
Instance Method Summary
-
#cell(ref : String) : Type | Nil
Returns the value of the cell with given reference ("B3"), nil if empty or missing.
-
#formula(ref : String) : String | Nil
Returns the formula of the cell with given reference ("C2"), nil if the cell has no formula.
-
#formulas : Hash(String, String)
Returns the formulas of the sheet indexed by cell reference ({"C2" => "A2*B2"}).
-
#hidden? : Bool
Returns true if the sheet is hidden or very hidden.
-
#merged_cells : Array(String)
Returns the merged cell ranges of the sheet (e.g.
-
#name : String
The name of the sheet.
-
#rows : Iterator(Row)
Returns an iterator that yields a hash per row, including the cell ids and values.
-
#rows_with_headers : Iterator(Row)
Returns an iterator that yields a hash per row indexed by the first row values.
-
#state : String
The visibility state of the sheet: "visible", "hidden" or "veryHidden".
Constructor Detail
Initializes a new instance of the Sheet class, path is the sheet XML path inside the zip.
Class Method Detail
Returns the 1-based column index of given cell reference ("AB12" => 28).
Returns the column name of given 1-based column index (28 => "AB").
Instance Method Detail
Returns the value of the cell with given reference ("B3"), nil if empty or missing.
Returns the formula of the cell with given reference ("C2"), nil if the cell has no formula.
Each call reads the whole sheet, use #formulas to read several cells.
Returns the formulas of the sheet indexed by cell reference ({"C2" => "A2*B2"}).
Formulas are returned as stored in the file, without the leading "=". Shared formulas are expanded
to each cell of their range, array formulas are only returned for their first cell.
Computed values are returned by #rows (value cached by Excel when the file was saved).
Returns an iterator that yields a hash per row, including the cell ids and values.
Missing cells are padded with nil from column A up to the last cell of the row. Each call reads the sheet from the start.
Returns an iterator that yields a hash per row indexed by the first row values.
Columns without header are indexed by their column letter.