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

Class representing a NumberFormat entry. The NumberFormat entry is used to define cell formats like currency or date. More...

Inheritance diagram for NanoXLSX.Styles.NumberFormat:

Public Types

enum  FormatNumber {
  None = 0 , Format1 = 1 , Format2 = 2 , Format3 = 3 ,
  Format4 = 4 , Format5 = 5 , Format6 = 6 , Format7 = 7 ,
  Format8 = 8 , Format9 = 9 , Format10 = 10 , Format11 = 11 ,
  Format12 = 12 , Format13 = 13 , Format14 = 14 , Format15 = 15 ,
  Format16 = 16 , Format17 = 17 , Format18 = 18 , Format19 = 19 ,
  Format20 = 20 , Format21 = 21 , Format22 = 22 , Format37 = 37 ,
  Format38 = 38 , Format39 = 39 , Format40 = 40 , Format45 = 45 ,
  Format46 = 46 , Format47 = 47 , Format48 = 48 , Format49 = 49 ,
  Custom = 164
}
 Enum for predefined number formats, used by implementations of the NumberFormat class. More...
enum  FormatRange { DefinedFormat , CustomFormat , Invalid , Undefined }
 Range or validity of the format number, used by the NumberFormat class. More...

Public Member Functions

 NumberFormat ()
 Default constructor.
override string ToString ()
 Override toString method.
override AbstractStyle Copy ()
 Method to copy the current object to a new one without casting.
NumberFormat CopyNumberFormat ()
 Method to copy the current object to a new one with casting.
override int GetHashCode ()
 Returns a hash code for this instance.
override bool Equals (object obj)
 Returns whether two instances are the same.
Public Member Functions inherited from NanoXLSX.Styles.AbstractStyle
AbstractStyle Copy ()
 Abstract method to copy a component (dereferencing).
int CompareTo (AbstractStyle other)
 Method to compare two objects for sorting purpose.
bool Equals (AbstractStyle other)
 Method to compare two objects for sorting purpose.

Static Public Member Functions

static bool IsDateFormat (FormatNumber number)
 Determines whether a defined style format number represents a date (or date and time).
static bool IsTimeFormat (FormatNumber number)
 Determines whether a defined style format number represents a time).
static FormatRange TryParseFormatNumber (int number, out FormatNumber formatNumber)
 Tries to parse registered format numbers. If the parsing fails, it is assumed that the number is a custom format number (164 or higher) and 'custom' is returned.

Static Public Attributes

static readonly int CustomFormatStartNumber = 164
 Start ID for custom number formats as constant (value 164).
static readonly FormatNumber DefaultNumber = FormatNumber.None
 Default format number as constant.

Properties

string CustomFormatCode [get, set]
 Gets or sets the raw custom format code in the notation of Excel. The code is not escaped or unescaped (on workbook loading).
int CustomFormatID [get, set]
 Gets or sets the format number of the custom format. Must be higher or equal then predefined custom number (164).
bool IsCustomFormat [get]
 Gets whether the number format is a custom format (higher or equals 164). If true, the format is custom.
FormatNumber Number [get, set]
 Gets or sets the format number. Set this to custom (164) in case of custom number formats.
Properties inherited from NanoXLSX.Styles.AbstractStyle
int? InternalID [get, set]
 Gets or sets the internal ID for sorting purpose in the Excel style document (nullable).

Detailed Description

Class representing a NumberFormat entry. The NumberFormat entry is used to define cell formats like currency or date.

Definition at line 17 of file NumberFormat.cs.

Member Enumeration Documentation

◆ FormatNumber

Enum for predefined number formats, used by implementations of the NumberFormat class.

Remarks
There are other predefined formats (e.g. 43 and 44) that are not listed. The declaration of such formats is done in the number formats section of the style document, whereas the officially listed ones are implicitly used and not declared in the style document
Enumerator
None 

No format / Default.

Format1 

Format: 0.

Format2 

Format: 0.00.

Format3 

Format: #,##0.

Format4 

Format: #,##0.00.

Format5 

Format: $#,##0_);($#,##0).

Format6 

Format: $#,##0_);Red.

Format7 

Format: $#,##0.00_);($#,##0.00).

Format8 

Format: $#,##0.00_);Red.

Format9 

Format: 0%.

Format10 

Format: 0.00%.

Format11 

Format: 0.00E+00.

Format12 

Format: # ?/?

.

Format13 

Format: # ??/??

.

Format14 

Format: m/d/yyyy.

Format15 

Format: d-mmm-yy.

Format16 

Format: d-mmm.

Format17 

Format: mmm-yy.

Format18 

Format: mm AM/PM.

Format19 

Format: h:mm:ss AM/PM.

Format20 

Format: h:mm.

Format21 

Format: h:mm:ss.

Format22 

Format: m/d/yyyy h:mm.

Format37 

Format: #,##0_);(#,##0).

Format38 

Format: #,##0_);Red.

Format39 

Format: #,##0.00_);(#,##0.00).

Format40 

Format: #,##0.00_);Red.

Format45 

Format: mm:ss.

Format46 

Format: [h]:mm:ss.

Format47 

Format: mm:ss.0.

Format48 

Format: ##0.0E+0.

Format49 

Format: #.

Custom 

Custom Format (ID 164 and higher).

Definition at line 38 of file NumberFormat.cs.

◆ FormatRange

Range or validity of the format number, used by the NumberFormat class.

Enumerator
DefinedFormat 

Format from 0 to 164 (with gaps).

CustomFormat 

Custom defined formats from 165 and higher. Although 164 is already custom, it is still defined as enum value.

Invalid 

Probably invalid format numbers (e.g. negative value).

Undefined 

Values between 0 and 164 that are not defined as enum value. This may be caused by changes of the OOXML specifications or Excel versions that have encoded loaded files.

Definition at line 111 of file NumberFormat.cs.

Constructor & Destructor Documentation

◆ NumberFormat()

NanoXLSX.Styles.NumberFormat.NumberFormat ( )

Default constructor.

Definition at line 198 of file NumberFormat.cs.

Member Function Documentation

◆ Copy()

override AbstractStyle NanoXLSX.Styles.NumberFormat.Copy ( )

Method to copy the current object to a new one without casting.

Returns
Copy of the current object without the internal ID

Definition at line 228 of file NumberFormat.cs.

◆ CopyNumberFormat()

NumberFormat NanoXLSX.Styles.NumberFormat.CopyNumberFormat ( )

Method to copy the current object to a new one with casting.

Returns
Copy of the current object without the internal ID

Definition at line 243 of file NumberFormat.cs.

◆ Equals()

override bool NanoXLSX.Styles.NumberFormat.Equals ( object obj)

Returns whether two instances are the same.

Parameters
objObject to compare
Returns
True if this instance and the other are the same

Definition at line 271 of file NumberFormat.cs.

◆ GetHashCode()

override int NanoXLSX.Styles.NumberFormat.GetHashCode ( )

Returns a hash code for this instance.

Returns
A hash code for this instance, suitable to be used in hashing algorithms and data structures like a hash table.

Definition at line 254 of file NumberFormat.cs.

◆ IsDateFormat()

bool NanoXLSX.Styles.NumberFormat.IsDateFormat ( FormatNumber number)
static

Determines whether a defined style format number represents a date (or date and time).

Parameters
numberFormat number to check
Returns
True if the format represents a date, otherwise false
Remarks
Custom number formats (higher than 164), as well as not officially defined numbers (below 164) are currently not considered during the check and will return false

Definition at line 289 of file NumberFormat.cs.

◆ IsTimeFormat()

bool NanoXLSX.Styles.NumberFormat.IsTimeFormat ( FormatNumber number)
static

Determines whether a defined style format number represents a time).

Parameters
numberFormat number to check
Returns
True if the format represents a time, otherwise false
Remarks
Custom number formats (higher than 164), as well as not officially defined numbers (below 164) are currently not considered during the check and will return false

Definition at line 310 of file NumberFormat.cs.

◆ ToString()

override string NanoXLSX.Styles.NumberFormat.ToString ( )

Override toString method.

Returns
String of a class

Definition at line 212 of file NumberFormat.cs.

◆ TryParseFormatNumber()

FormatRange NanoXLSX.Styles.NumberFormat.TryParseFormatNumber ( int number,
out FormatNumber formatNumber )
static

Tries to parse registered format numbers. If the parsing fails, it is assumed that the number is a custom format number (164 or higher) and 'custom' is returned.

Parameters
numberRaw number to parse
formatNumberOut parameter with the parsed format enum value. If parsing failed, 'custom' will be returned
Returns
Format range. Will return 'invalid' if out of any range (e.g. negative value)

Definition at line 333 of file NumberFormat.cs.

Member Data Documentation

◆ CustomFormatStartNumber

readonly int NanoXLSX.Styles.NumberFormat.CustomFormatStartNumber = 164
static

Start ID for custom number formats as constant (value 164).

Definition at line 23 of file NumberFormat.cs.

◆ DefaultNumber

readonly FormatNumber NanoXLSX.Styles.NumberFormat.DefaultNumber = FormatNumber.None
static

Default format number as constant.

Definition at line 27 of file NumberFormat.cs.

Property Documentation

◆ CustomFormatCode

string NanoXLSX.Styles.NumberFormat.CustomFormatCode
getset

Gets or sets the raw custom format code in the notation of Excel. The code is not escaped or unescaped (on workbook loading).

Exceptions
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if passed value is null or empty
Remarks
Currently, there is no auto-escaping applied to custom format strings. For instance, to add a white space, internally it is escaped by a backspace (\ ). To get a valid custom format code, this escaping must be applied manually, according to OOXML specs: Part 1 - Fundamentals And Markup Language Reference, Chapter 18.8.31

Definition at line 145 of file NumberFormat.cs.

◆ CustomFormatID

int NanoXLSX.Styles.NumberFormat.CustomFormatID
getset

Gets or sets the format number of the custom format. Must be higher or equal then predefined custom number (164).

Exceptions
NanoXLSX.Exceptions.StyleExceptionThrows a StyleException if the number is below the lowest possible custom number (164)

Definition at line 162 of file NumberFormat.cs.

◆ IsCustomFormat

bool NanoXLSX.Styles.NumberFormat.IsCustomFormat
get

Gets whether the number format is a custom format (higher or equals 164). If true, the format is custom.

Definition at line 178 of file NumberFormat.cs.

◆ Number

FormatNumber NanoXLSX.Styles.NumberFormat.Number
getset

Gets or sets the format number. Set this to custom (164) in case of custom number formats.

Definition at line 191 of file NumberFormat.cs.


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