NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
NanoXLSX.Cell Class Reference

Class representing a cell of a worksheet. More...

Inheritance diagram for NanoXLSX.Cell:

Public Types

enum  CellType {
  String , Number , Date , Time ,
  Bool , Formula , Empty , Default
}
 Enum defines the basic data types of a cell. More...
enum  AddressType { Default , FixedRow , FixedColumn , FixedRowAndColumn }
 Enum for the referencing style of the address. More...
enum  AddressScope { SingleAddress , Range , Invalid }
 Enum to define the scope of a passed address string (used in static context). More...

Public Member Functions

 Cell ()
 Default constructor. Cells created with this constructor do not have a link to a worksheet initially.
 Cell (object value, CellType type)
 Constructor with value and cell type. Cells created with this constructor do not have a link to a worksheet initially.
 Cell (object value, CellType type, string address)
 Constructor with value, cell type and address as string. The worksheet reference is set to null and must be assigned later.
 Cell (object value, CellType type, Address address)
 Constructor with value, cell type and address as struct. The worksheet reference is set to null and must be assigned later.
 Cell (object value, CellType type, int column, int row)
 Constructor with value, cell type, row number and column number.
int CompareTo (Cell other)
 Implemented CompareTo method.
override bool Equals (object obj)
 Compares two objects whether they are addresses and equal.
void RemoveStyle ()
 Removes the assigned style from the cell.
void ResolveCellType ()
 Method resets the Cell type and tries to find the actual type. This is used if a Cell was created with the CellType DEFAULT or automatically if a value was set by Value. CellType FORMULA will skip this method and EMPTY will discard the value of the cell.
void SetCellLockedState (bool isLocked, bool isHidden)
 Sets the lock state of the cell.
Style SetStyle (Style style, bool unmanaged=false)
 Sets the style of the cell.
override int GetHashCode ()
 Gets the hash code of the cell.

Static Public Member Functions

static bool operator== (Cell left, Cell right)
 Determines whether two Cell instances are equal.
static bool operator!= (Cell left, Cell right)
 Determines whether two Cell instances are not equal.
static bool operator< (Cell left, Cell right)
 Determines whether the first instance of a Cell is less/smaller as the second.
static bool operator<= (Cell left, Cell right)
 Determines whether the first instance of a Cell is less/smaller or equal as the second.
static bool operator> (Cell left, Cell right)
 Determines whether the first instance of a Cell is greater/larger as the second.
static bool operator>= (Cell left, Cell right)
 Determines whether the first instance of a Cell is greater/larger or equal as the second.
static IEnumerable< CellConvertArray< T > (IEnumerable< T > list)
 Converts a List of supported objects into a list of cells.
static IEnumerable< AddressGetCellRange (string range)
 Gets a list of cell addresses from a cell range (format A1:B3 or AAD556:AAD1000).
static IEnumerable< AddressGetCellRange (string startAddress, string endAddress)
 Get a list of cell addresses from a cell range.
static IEnumerable< AddressGetCellRange (int startColumn, int startRow, int endColumn, int endRow)
 Get a list of cell addresses from a cell range.
static IEnumerable< AddressGetCellRange (Address startAddress, Address endAddress)
 Get a list of cell addresses from a cell range.
static string ResolveCellAddress (int column, int row, AddressType type=AddressType.Default)
 Gets the address of a cell by the column and row number (zero based).
static Address ResolveCellCoordinate (string address)
 Gets the column and row number (zero based) of a cell by the address.
static void ResolveCellCoordinate (string address, out int column, out int row)
 Gets the column and row number (zero based) of a cell by the address.
static void ResolveCellCoordinate (string address, out int column, out int row, out AddressType addressType)
 Gets the column and row number (zero based) of a cell by the address.
static Range ResolveCellRange (string range)
 Resolves a cell range from the format like A1:B3 or AAD556:AAD1000.
static int ResolveColumn (string columnAddress)
 Gets the column number from the column address (A - XFD).
static string ResolveColumnAddress (int columnNumber)
 Gets the column address (A - XFD).
static AddressScope GetAddressScope (string addressExpression)
 Gets the scope of the passed address (string expression). Scope means either single cell address or range.
static void ValidateColumnNumber (int column)
 Validates the passed (zero-based) column number. An exception will be thrown if the column is invalid.
static void ValidateRowNumber (int row)
 Validates the passed (zero-based) row number. An exception will be thrown if the row is invalid.

Properties

string CellAddress [get, set]
 Gets or sets the combined cell Address as string in the format A1 - XFD1048576. The address may contain a Cell.AddressType modifier (e.g. C$50).
Address CellAddress2 [get, set]
 Gets or sets the combined cell Address as Address object.
Style CellStyle [get]
 Gets the assigned style of the cell.
int ColumnNumber [get, set]
 Gets or sets the number of the column (zero-based).
CellType DataType [get, set]
 Gets or sets the type of the cell.
int RowNumber [get, set]
 Gets or sets the number of the row (zero-based).
AddressType CellAddressType [get, set]
 Gets or sets the optional address type that can be part of the cell address.
object Value [get, set]
 Gets or sets the value of the cell (generic object type). When setting a value, the DataType is automatically resolved.

Detailed Description

Class representing a cell of a worksheet.

Definition at line 23 of file Cell.cs.

Member Enumeration Documentation

◆ AddressScope

Enum to define the scope of a passed address string (used in static context).

Enumerator
SingleAddress 

The address represents a single cell.

Range 

The address represents a range of cells.

Invalid 

The address expression is invalid.

Definition at line 74 of file Cell.cs.

◆ AddressType

Enum for the referencing style of the address.

Enumerator
Default 

Default behavior (e.g. 'C3').

FixedRow 

Row of the address is fixed (e.g. 'C$3').

FixedColumn 

Column of the address is fixed (e.g. '$C3').

FixedRowAndColumn 

Row and column of the address is fixed (e.g. '$C$3').

Definition at line 59 of file Cell.cs.

◆ CellType

Enum defines the basic data types of a cell.

Enumerator
String 

Type for single characters and strings.

Number 

Type for all numeric types (long, integer, float, double, short, byte and decimal; signed and unsigned, if available).

Date 

Type for dates (Note: Dates before 1900-01-01 and after 9999-12-31 are not allowed).

Time 

Type for times (Note: Internally handled as OAdate, represented by TimeSpan).

Bool 

Type for boolean.

Formula 

Type for Formulas (The cell will be handled differently).

Empty 

Type for empty cells. This type is only used for merged cells (all cells except the first of the cell range).

Default 

Default Type, not specified.

Definition at line 34 of file Cell.cs.

Constructor & Destructor Documentation

◆ Cell() [1/5]

NanoXLSX.Cell.Cell ( )

Default constructor. Cells created with this constructor do not have a link to a worksheet initially.

Definition at line 179 of file Cell.cs.

◆ Cell() [2/5]

NanoXLSX.Cell.Cell ( object value,
CellType type )

Constructor with value and cell type. Cells created with this constructor do not have a link to a worksheet initially.

Parameters
valueValue of the cell
typeType of the cell
Remarks
If the DataType is defined as CellType.Empty any passed value will be set to null

Definition at line 190 of file Cell.cs.

◆ Cell() [3/5]

NanoXLSX.Cell.Cell ( object value,
CellType type,
string address )

Constructor with value, cell type and address as string. The worksheet reference is set to null and must be assigned later.

Parameters
valueValue of the cell
typeType of the cell
addressAddress of the cell
Remarks
If the DataType is defined as CellType.Empty any passed value will be set to null

Definition at line 214 of file Cell.cs.

◆ Cell() [4/5]

NanoXLSX.Cell.Cell ( object value,
CellType type,
Address address )

Constructor with value, cell type and address as struct. The worksheet reference is set to null and must be assigned later.

Parameters
valueValue of the cell
typeType of the cell
addressAddress struct of the cell
Remarks
If the DataType is defined as CellType.Empty any passed value will be set to null

Definition at line 239 of file Cell.cs.

◆ Cell() [5/5]

NanoXLSX.Cell.Cell ( object value,
CellType type,
int column,
int row )

Constructor with value, cell type, row number and column number.

Parameters
valueValue of the cell
typeType of the cell
columnColumn number of the cell (zero-based)
rowRow number of the cell (zero-based)

Definition at line 266 of file Cell.cs.

Member Function Documentation

◆ CompareTo()

int NanoXLSX.Cell.CompareTo ( Cell other)

Implemented CompareTo method.

Parameters
otherObject to compare
Returns
0 if values are the same, -1 if this object is smaller, 1 if it is bigger
Remarks
Note that this method only compares the row and column numbers, since the values or styles may be completely different types, and therefore hard to compare at all.
The Equals(object) method considers values and style, though.

Definition at line 287 of file Cell.cs.

◆ ConvertArray< T >()

IEnumerable< Cell > NanoXLSX.Cell.ConvertArray< T > ( IEnumerable< T > list)
static

Converts a List of supported objects into a list of cells.

Template Parameters
TGeneric data type
Parameters
listList of generic objects
Returns
List of cells

Definition at line 554 of file Cell.cs.

◆ Equals()

override bool NanoXLSX.Cell.Equals ( object obj)

Compares two objects whether they are addresses and equal.

Parameters
objOther address
Returns
True if not null, of the same type and equal

Definition at line 306 of file Cell.cs.

◆ GetAddressScope()

AddressScope NanoXLSX.Cell.GetAddressScope ( string addressExpression)
static

Gets the scope of the passed address (string expression). Scope means either single cell address or range.

Parameters
addressExpressionAddress expression
Returns
Scope of the address expression

Definition at line 887 of file Cell.cs.

◆ GetCellRange() [1/4]

IEnumerable< Address > NanoXLSX.Cell.GetCellRange ( Address startAddress,
Address endAddress )
static

Get a list of cell addresses from a cell range.

Parameters
startAddressStart address
endAddressEnd address
Returns
List of cell addresses
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if a part of the passed addresses is malformed
RangeExceptionThrows a RangeException if the value of one passed address is out of range (A-XFD and 1 to 1048576)

Definition at line 673 of file Cell.cs.

◆ GetCellRange() [2/4]

IEnumerable< Address > NanoXLSX.Cell.GetCellRange ( int startColumn,
int startRow,
int endColumn,
int endRow )
static

Get a list of cell addresses from a cell range.

Parameters
startColumnStart column (zero based)
startRowStart row (zero based)
endColumnEnd column (zero based)
endRowEnd row (zero based)
Returns
List of cell addresses
Exceptions
RangeExceptionThrows a RangeException if the value of one passed address parts is out of range (A-XFD and 1 to 1048576)

Definition at line 658 of file Cell.cs.

◆ GetCellRange() [3/4]

IEnumerable< Address > NanoXLSX.Cell.GetCellRange ( string range)
static

Gets a list of cell addresses from a cell range (format A1:B3 or AAD556:AAD1000).

Parameters
rangeRange to process
Returns
List of cell addresses
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if a part of the passed range is malformed
RangeExceptionThrows a RangeException if the range is out of range (A-XFD and 1 to 1048576)

Definition at line 628 of file Cell.cs.

◆ GetCellRange() [4/4]

IEnumerable< Address > NanoXLSX.Cell.GetCellRange ( string startAddress,
string endAddress )
static

Get a list of cell addresses from a cell range.

Parameters
startAddressStart address as string in the format A1 - XFD1048576
endAddressEnd address as string in the format A1 - XFD1048576
Returns
List of cell addresses
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if a part of the passed range is malformed
RangeExceptionThrows a RangeException if the range is out of range (A-XFD and 1 to 1048576)

Definition at line 642 of file Cell.cs.

◆ GetHashCode()

override int NanoXLSX.Cell.GetHashCode ( )

Gets the hash code of the cell.

Returns
Hash code of the cell

Definition at line 447 of file Cell.cs.

◆ operator!=()

bool NanoXLSX.Cell.operator!= ( Cell left,
Cell right )
static

Determines whether two Cell instances are not equal.

Parameters
leftThe first Cell instance to compare.
rightThe second Cell instance to compare.
Returns
true if the specified Cell instances are not equal; otherwise, false.

Definition at line 484 of file Cell.cs.

◆ operator<()

bool NanoXLSX.Cell.operator< ( Cell left,
Cell right )
static

Determines whether the first instance of a Cell is less/smaller as the second.

Parameters
leftThe left Cell instance to compare.
rightThe second Cell instance to compare.
Returns
true if the left Cell instances is less/smaller; otherwise, false.
Remarks
Note that this method only compares the row and column numbers, since the values or styles may be completely different types, and therefore hard to compare at all.
The Equals(object) method considers values and style, though.

Definition at line 498 of file Cell.cs.

◆ operator<=()

bool NanoXLSX.Cell.operator<= ( Cell left,
Cell right )
static

Determines whether the first instance of a Cell is less/smaller or equal as the second.

Parameters
leftThe left Cell instance to compare.
rightThe second Cell instance to compare.
Returns
true if the left Cell instances is less/smaller, or equal; otherwise, false.
Remarks
Note that this method only compares the row and column numbers, since the values or styles may be completely different types, and therefore hard to compare at all.
The Equals(object) method considers values and style, though.

Definition at line 512 of file Cell.cs.

◆ operator==()

bool NanoXLSX.Cell.operator== ( Cell left,
Cell right )
static

Determines whether two Cell instances are equal.

Parameters
leftThe first Cell instance to compare.
rightThe second Cell instance to compare.
Returns
true if the specified Cell instances are equal; otherwise, false.

Definition at line 468 of file Cell.cs.

◆ operator>()

bool NanoXLSX.Cell.operator> ( Cell left,
Cell right )
static

Determines whether the first instance of a Cell is greater/larger as the second.

Parameters
leftThe left Cell instance to compare.
rightThe second Cell instance to compare.
Returns
true if the left Cell instances is greater/larger; otherwise, false.
Remarks
Note that this method only compares the row and column numbers, since the values or styles may be completely different types, and therefore hard to compare at all.
The Equals(object) method considers values and style, though.

Definition at line 526 of file Cell.cs.

◆ operator>=()

bool NanoXLSX.Cell.operator>= ( Cell left,
Cell right )
static

Determines whether the first instance of a Cell is greater/larger or equal as the second.

Parameters
leftThe left Cell instance to compare.
rightThe second Cell instance to compare.
Returns
true if the left Cell instances is greater/larger or equal; otherwise, false.
Remarks
Note that this method only compares the row and column numbers, since the values or styles may be completely different types, and therefore hard to compare at all.
The Equals(object) method considers values and style, though.

Definition at line 540 of file Cell.cs.

◆ RemoveStyle()

void NanoXLSX.Cell.RemoveStyle ( )

Removes the assigned style from the cell.

Definition at line 335 of file Cell.cs.

◆ ResolveCellAddress()

string NanoXLSX.Cell.ResolveCellAddress ( int column,
int row,
AddressType type = AddressType::Default )
static

Gets the address of a cell by the column and row number (zero based).

Parameters
columnColumn number of the cell (zero-based)
rowRow number of the cell (zero-based)
typeOptional referencing type of the address
Exceptions
RangeExceptionThrows a RangeException if the start or end address was out of range
Returns
Cell Address as string in the format A1 - XFD1048576. Depending on the type, Addresses like '$A55', 'B$2' or '$A$5' are possible outputs

Definition at line 718 of file Cell.cs.

◆ ResolveCellCoordinate() [1/3]

Address NanoXLSX.Cell.ResolveCellCoordinate ( string address)
static

Gets the column and row number (zero based) of a cell by the address.

Parameters
addressAddress as string in the format A1 - XFD1048576
Returns
Struct with row and column
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if the passed address is malformed
RangeExceptionThrows a RangeException if the value of the passed address is out of range (A-XFD and 1 to 1048576)

Definition at line 742 of file Cell.cs.

◆ ResolveCellCoordinate() [2/3]

void NanoXLSX.Cell.ResolveCellCoordinate ( string address,
out int column,
out int row )
static

Gets the column and row number (zero based) of a cell by the address.

Parameters
addressAddress as string in the format A1 - XFD1048576
columnColumn number of the cell (zero-based) as out parameter
rowRow number of the cell (zero-based) as out parameter
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if the range address was malformed
RangeExceptionThrows a RangeException if the row or column number was out of range

Definition at line 759 of file Cell.cs.

◆ ResolveCellCoordinate() [3/3]

void NanoXLSX.Cell.ResolveCellCoordinate ( string address,
out int column,
out int row,
out AddressType addressType )
static

Gets the column and row number (zero based) of a cell by the address.

Parameters
addressAddress as string in the format A1 - XFD1048576
columnColumn number of the cell (zero-based) as out parameter
rowRow number of the cell (zero-based) as out parameter
addressTypeAddress type of the cell (if defined as modifiers in the address string)
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if the range address was malformed
RangeExceptionThrows a RangeException if the row or column number was out of range

Definition at line 774 of file Cell.cs.

◆ ResolveCellRange()

Range NanoXLSX.Cell.ResolveCellRange ( string range)
static

Resolves a cell range from the format like A1:B3 or AAD556:AAD1000.

Parameters
rangeRange to process
Returns
Range object
Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if the start or end address was malformed
RangeExceptionThrows a RangeException if the range is out of range (A-XFD and 1 to 1048576)

Definition at line 816 of file Cell.cs.

◆ ResolveCellType()

void NanoXLSX.Cell.ResolveCellType ( )

Method resets the Cell type and tries to find the actual type. This is used if a Cell was created with the CellType DEFAULT or automatically if a value was set by Value. CellType FORMULA will skip this method and EMPTY will discard the value of the cell.

Definition at line 344 of file Cell.cs.

◆ ResolveColumn()

int NanoXLSX.Cell.ResolveColumn ( string columnAddress)
static

Gets the column number from the column address (A - XFD).

Parameters
columnAddressColumn address (A - XFD)
Returns
Column number (zero-based)
Exceptions
RangeExceptionThrows a RangeException if the passed address was out of range

Definition at line 840 of file Cell.cs.

◆ ResolveColumnAddress()

string NanoXLSX.Cell.ResolveColumnAddress ( int columnNumber)
static

Gets the column address (A - XFD).

Parameters
columnNumberColumn number (zero-based)
Returns
Column address (A - XFD)
Exceptions
RangeExceptionThrows a RangeException if the passed column number was out of range

Definition at line 867 of file Cell.cs.

◆ SetCellLockedState()

void NanoXLSX.Cell.SetCellLockedState ( bool isLocked,
bool isHidden )

Sets the lock state of the cell.

Parameters
isLockedIf true, the cell will be locked if the worksheet is protected
isHiddenIf true, the value of the cell will be invisible if the worksheet is protected
Exceptions
StyleExceptionThrows a StyleException if the style used to lock cells cannot be referenced
Remarks
The listed exception should never happen because the mentioned style is internally generated

Definition at line 392 of file Cell.cs.

◆ SetStyle()

Style NanoXLSX.Cell.SetStyle ( Style style,
bool unmanaged = false )

Sets the style of the cell.

Parameters
styleStyle to assign
unmanagedInternally used: If true, the style repository is not invoked and only the style object of the cell is updated. Do not use!
Returns
If the passed style already exists in the repository, the existing one will be returned, otherwise the passed one

Definition at line 414 of file Cell.cs.

◆ ValidateColumnNumber()

void NanoXLSX.Cell.ValidateColumnNumber ( int column)
static

Validates the passed (zero-based) column number. An exception will be thrown if the column is invalid.

Parameters
columnNumber to check
Exceptions
RangeExceptionThrown if the passed column number is out of range

Definition at line 914 of file Cell.cs.

◆ ValidateRowNumber()

void NanoXLSX.Cell.ValidateRowNumber ( int row)
static

Validates the passed (zero-based) row number. An exception will be thrown if the row is invalid.

Parameters
rowNumber to check
Exceptions
RangeExceptionThrown if the passed row number is out of range

Definition at line 928 of file Cell.cs.

Property Documentation

◆ CellAddress

string NanoXLSX.Cell.CellAddress
getset

Gets or sets the combined cell Address as string in the format A1 - XFD1048576. The address may contain a Cell.AddressType modifier (e.g. C$50).

Definition at line 98 of file Cell.cs.

◆ CellAddress2

Address NanoXLSX.Cell.CellAddress2
getset

Gets or sets the combined cell Address as Address object.

Definition at line 110 of file Cell.cs.

◆ CellAddressType

AddressType NanoXLSX.Cell.CellAddressType
getset

Gets or sets the optional address type that can be part of the cell address.

Remarks
The type has no influence on the behavior of the cell, though. It is preserved to avoid losing information on the address object of the cell

Definition at line 161 of file Cell.cs.

◆ CellStyle

Style NanoXLSX.Cell.CellStyle
get

Gets the assigned style of the cell.

Definition at line 124 of file Cell.cs.

◆ ColumnNumber

int NanoXLSX.Cell.ColumnNumber
getset

Gets or sets the number of the column (zero-based).


Exceptions
RangeExceptionThrows a RangeException if the column number is out of range

Definition at line 131 of file Cell.cs.

◆ DataType

CellType NanoXLSX.Cell.DataType
getset

Gets or sets the type of the cell.

Definition at line 142 of file Cell.cs.

◆ RowNumber

int NanoXLSX.Cell.RowNumber
getset

Gets or sets the number of the row (zero-based).

Exceptions
RangeExceptionThrows a RangeException if the row number is out of range

Definition at line 147 of file Cell.cs.

◆ Value

object NanoXLSX.Cell.Value
getset

Gets or sets the value of the cell (generic object type). When setting a value, the DataType is automatically resolved.

Definition at line 164 of file Cell.cs.


The documentation for this class was generated from the following file: