class XlsxParser::Sheet

Overview

Represents a sheet in an Excel workbook.

The Sheet class provides methods to read data in a sheet.

Defined in:

xlsx-parser/sheet.cr

Constant 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

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(book : Book, path : String, name : String, state : String = "visible") #

Initializes a new instance of the Sheet class, path is the sheet XML path inside the zip.


[View source]

Class Method Detail

def self.column_index(ref : String) : Int32 #

Returns the 1-based column index of given cell reference ("AB12" => 28).


[View source]
def self.column_name(index : Int32) : String #

Returns the column name of given 1-based column index (28 => "AB").


[View source]

Instance Method Detail

def cell(ref : String) : Type | Nil #

Returns the value of the cell with given reference ("B3"), nil if empty or missing.


[View source]
def formula(ref : String) : String | Nil #

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.


[View source]
def formulas : Hash(String, String) #

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


[View source]
def hidden? : Bool #

Returns true if the sheet is hidden or very hidden.


[View source]
def merged_cells : Array(String) #

Returns the merged cell ranges of the sheet (e.g. ["A1:B2"]).


[View source]
def name : String #

The name of the sheet.


[View source]
def rows : Iterator(Row) #

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.


[View source]
def rows_with_headers : Iterator(Row) #

Returns an iterator that yields a hash per row indexed by the first row values.

Columns without header are indexed by their column letter.


[View source]
def state : String #

The visibility state of the sheet: "visible", "hidden" or "veryHidden".


[View source]