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

Class representing a workbook. More...

Public Member Functions

 Workbook ()
 Default constructor. No initial worksheet is created. Use AddWorksheet(string) (or overloads) to add one.
 Workbook (bool createWorkSheet)
 Constructor with additional parameter to create a default worksheet. This constructor can be used to define a workbook that is saved as stream.
 Workbook (string sheetName)
 Constructor with additional parameter to create a default worksheet with the specified name. This constructor can be used to define a workbook that is saved as stream.
 Workbook (string filename, string sheetName)
 Constructor with filename ant the name of the first worksheet.
 Workbook (string filename, string sheetName, bool sanitizeSheetName)
 Constructor with filename ant the name of the first worksheet.
void AddMruColor (string color)
 Adds a color value (HEX; 6-digit RGB or 8-digit ARGB) to the MRU list.
IReadOnlyList< string > GetMruColors ()
 Gets the MRU color list.
void ClearMruColors ()
 Clears the MRU color list.
void AddWorksheet (string name)
 Adding a new Worksheet. The new worksheet will be defined as current worksheet.
void AddWorksheet (string name, bool sanitizeSheetName)
 Adding a new Worksheet with a sanitizing option. The new worksheet will be defined as current worksheet.
void AddWorksheet (Worksheet worksheet)
 Adding a new Worksheet. The new worksheet will be defined as current worksheet.
void AddWorksheet (Worksheet worksheet, bool sanitizeSheetName)
 Adding a new Worksheet. The new worksheet will be defined as current worksheet.
void RemoveWorksheet (string name)
 Removes the defined worksheet based on its name. If the worksheet is the current or selected worksheet, the current and / or the selected worksheet will be set to the last worksheet of the workbook. If the last worksheet is removed, the selected worksheet will be set to 0 and the current worksheet to null.
void RemoveWorksheet (int index)
 Removes the defined worksheet based on its index. If the worksheet is the current or selected worksheet, the current and / or the selected worksheet will be set to the last worksheet of the workbook. If the last worksheet is removed, the selected worksheet will be set to 0 and the current worksheet to null.
Worksheet SetCurrentWorksheet (string name)
 Sets the current worksheet.
Worksheet SetCurrentWorksheet (int worksheetIndex)
 Sets the current worksheet.
void SetCurrentWorksheet (Worksheet worksheet)
 Sets the current worksheet.
void SetSelectedWorksheet (string name)
 Sets the selected worksheet in the output workbook.
void SetSelectedWorksheet (int worksheetIndex)
 Sets the selected worksheet in the output workbook.
void SetSelectedWorksheet (Worksheet worksheet)
 Sets the selected worksheet in the output workbook.
Worksheet GetWorksheet (string name)
 Gets a worksheet from this workbook by name.
Worksheet GetWorksheet (int index)
 Gets a worksheet from this workbook by index.
void SetWorkbookProtection (bool state, bool protectWindows, bool protectStructure, string password)
 Sets or removes the workbook protection. If protectWindows and protectStructure are both false, the workbook will not be protected.
Worksheet CopyWorksheetIntoThis (string sourceWorksheetName, string newWorksheetName, bool sanitizeSheetName=true)
 Copies a worksheet of the current workbook by its name.
Worksheet CopyWorksheetIntoThis (int sourceWorksheetIndex, string newWorksheetName, bool sanitizeSheetName=true)
 Copies a worksheet of the current workbook by its index.
Worksheet CopyWorksheetIntoThis (Worksheet sourceWorksheet, string newWorksheetName, bool sanitizeSheetName=true)
 Copies a worksheet of any workbook into the current workbook.
Worksheet CopyWorksheetTo (string sourceWorksheetName, string newWorksheetName, Workbook targetWorkbook, bool sanitizeSheetName=true)
 Copies a worksheet of the current workbook by its name into another workbook.
Worksheet CopyWorksheetTo (int sourceWorksheetIndex, string newWorksheetName, Workbook targetWorkbook, bool sanitizeSheetName=true)
 Copies a worksheet of the current workbook by its index into another workbook.

Static Public Member Functions

static Worksheet CopyWorksheetTo (Worksheet sourceWorksheet, string newWorksheetName, Workbook targetWorkbook, bool sanitizeSheetName=true)
 Copies a worksheet of any workbook into the another workbook.

Properties

Shortener WS [get]
 Gets the shortener object for the current worksheet.
Worksheet CurrentWorksheet [get]
 Gets the current worksheet.
string Filename [get, set]
 Gets or sets the filename of the workbook.
bool LockStructureIfProtected [get]
 Gets whether the structure are locked if workbook is protected. See also SetWorkbookProtection.
bool LockWindowsIfProtected [get]
 Gets whether the windows are locked if workbook is protected. See also SetWorkbookProtection.
Metadata WorkbookMetadata [get, set]
 Meta data object of the workbook.
int SelectedWorksheet [get]
 Gets the selected worksheet. The selected worksheet is not the current worksheet while design time but the selected sheet in the output file.
bool UseWorkbookProtection [get, set]
 Gets or sets whether the workbook is protected.
virtual IPassword WorkbookProtectionPassword [get, set]
 Password instance of the protected workbook. If a password was set, the pain text representation and the hash can be read from the instance.
List< WorksheetWorksheets [get]
 Gets the list of worksheets in the workbook.
bool Hidden [get, set]
 Gets or sets whether the whole workbook is hidden.
Theme WorkbookTheme = Theme.GetDefaultTheme() [get, set]
 Gets or sets the theme of the workbook. The default is defined by Theme.GetDefaultTheme. However, the theme can be nullified.

Detailed Description

Class representing a workbook.

Definition at line 22 of file Workbook.cs.

Constructor & Destructor Documentation

◆ Workbook() [1/5]

NanoXLSX.Workbook.Workbook ( )

Default constructor. No initial worksheet is created. Use AddWorksheet(string) (or overloads) to add one.

Definition at line 152 of file Workbook.cs.

◆ Workbook() [2/5]

NanoXLSX.Workbook.Workbook ( bool createWorkSheet)

Constructor with additional parameter to create a default worksheet. This constructor can be used to define a workbook that is saved as stream.

Parameters
createWorkSheetIf true, a default worksheet with the name 'Sheet1' will be crated and set as current worksheet

Definition at line 161 of file Workbook.cs.

◆ Workbook() [3/5]

NanoXLSX.Workbook.Workbook ( string sheetName)

Constructor with additional parameter to create a default worksheet with the specified name. This constructor can be used to define a workbook that is saved as stream.

Parameters
sheetNameFilename of the workbook. The name will be sanitized automatically according to the specifications of Excel

Definition at line 174 of file Workbook.cs.

◆ Workbook() [4/5]

NanoXLSX.Workbook.Workbook ( string filename,
string sheetName )

Constructor with filename ant the name of the first worksheet.

Parameters
filenameFilename of the workbook. The name will be sanitized automatically according to the specifications of Excel
sheetNameName of the first worksheet. The name will be sanitized automatically according to the specifications of Excel

Definition at line 185 of file Workbook.cs.

◆ Workbook() [5/5]

NanoXLSX.Workbook.Workbook ( string filename,
string sheetName,
bool sanitizeSheetName )

Constructor with filename ant the name of the first worksheet.

Parameters
filenameFilename of the workbook
sheetNameName of the first worksheet
sanitizeSheetNameIf true, the name of the worksheet will be sanitized automatically according to the specifications of Excel

Definition at line 198 of file Workbook.cs.

Member Function Documentation

◆ AddMruColor()

void NanoXLSX.Workbook.AddMruColor ( string color)

Adds a color value (HEX; 6-digit RGB or 8-digit ARGB) to the MRU list.

Parameters
colorRGB code in hex format (either 6 characters, e.g. FF00AC or 8 characters with leading alpha value). Alpha will be set to full opacity (FF) in case of 6 characters

Definition at line 220 of file Workbook.cs.

◆ AddWorksheet() [1/4]

void NanoXLSX.Workbook.AddWorksheet ( string name)

Adding a new Worksheet. The new worksheet will be defined as current worksheet.

Parameters
nameName of the new worksheet
Exceptions
WorksheetExceptionThrows a WorksheetException if the name of the worksheet already exists
NanoXLSX.Exceptions.FormatExceptionThrows a FormatException if the name contains illegal characters or is out of range (length between 1 an 31 characters)

Definition at line 253 of file Workbook.cs.

◆ AddWorksheet() [2/4]

void NanoXLSX.Workbook.AddWorksheet ( string name,
bool sanitizeSheetName )

Adding a new Worksheet with a sanitizing option. The new worksheet will be defined as current worksheet.

Parameters
nameName of the new worksheet
sanitizeSheetNameIf true, the name of the worksheet will be sanitized automatically according to the specifications of Excel
Exceptions
WorksheetExceptionWorksheetException is thrown if the name of the worksheet already exists and sanitizeSheetName is false
NanoXLSX.Exceptions.FormatExceptionFormatException is thrown if the worksheet name contains illegal characters or is out of range (length between 1 an 31) and sanitizeSheetName is false

Definition at line 276 of file Workbook.cs.

◆ AddWorksheet() [3/4]

void NanoXLSX.Workbook.AddWorksheet ( Worksheet worksheet)

Adding a new Worksheet. The new worksheet will be defined as current worksheet.

Parameters
worksheetPrepared worksheet object
Exceptions
WorksheetExceptionWorksheetException is thrown if the name of the worksheet already exists
NanoXLSX.Exceptions.FormatExceptionFormatException is thrown if the worksheet name contains illegal characters or is out of range (length between 1 an 31)

Definition at line 295 of file Workbook.cs.

◆ AddWorksheet() [4/4]

void NanoXLSX.Workbook.AddWorksheet ( Worksheet worksheet,
bool sanitizeSheetName )

Adding a new Worksheet. The new worksheet will be defined as current worksheet.

Parameters
worksheetPrepared worksheet object
sanitizeSheetNameIf true, the name of the worksheet will be sanitized automatically according to the specifications of Excel


Exceptions
WorksheetExceptionWorksheetException is thrown if the name of the worksheet already exists, when sanitation is false
NanoXLSX.Exceptions.FormatExceptionFormatException is thrown if the worksheet name contains illegal characters or is out of range (length between 1 an 31) and sanitation is false

Definition at line 307 of file Workbook.cs.

◆ ClearMruColors()

void NanoXLSX.Workbook.ClearMruColors ( )

Clears the MRU color list.

Definition at line 242 of file Workbook.cs.

◆ CopyWorksheetIntoThis() [1/3]

Worksheet NanoXLSX.Workbook.CopyWorksheetIntoThis ( int sourceWorksheetIndex,
string newWorksheetName,
bool sanitizeSheetName = true )

Copies a worksheet of the current workbook by its index.

Parameters
sourceWorksheetIndexIndex of the worksheet to copy, originated in this workbook
newWorksheetNameName of the new worksheet (copy)
sanitizeSheetNameIf true, the new name will be automatically sanitized if a name collision occurs
Remarks
The copy is not set as current worksheet. The existing one is kept
Returns
Copied worksheet

Definition at line 547 of file Workbook.cs.

◆ CopyWorksheetIntoThis() [2/3]

Worksheet NanoXLSX.Workbook.CopyWorksheetIntoThis ( string sourceWorksheetName,
string newWorksheetName,
bool sanitizeSheetName = true )

Copies a worksheet of the current workbook by its name.

Parameters
sourceWorksheetNameName of the worksheet to copy, originated in this workbook
newWorksheetNameName of the new worksheet (copy)
sanitizeSheetNameIf true, the new name will be automatically sanitized if a name collision occurs
Remarks
The copy is not set as current worksheet. The existing one is kept
Returns
Copied worksheet

Definition at line 533 of file Workbook.cs.

◆ CopyWorksheetIntoThis() [3/3]

Worksheet NanoXLSX.Workbook.CopyWorksheetIntoThis ( Worksheet sourceWorksheet,
string newWorksheetName,
bool sanitizeSheetName = true )

Copies a worksheet of any workbook into the current workbook.

Parameters
sourceWorksheetWorksheet to copy
newWorksheetNameName of the new worksheet (copy)
sanitizeSheetNameIf true, the new name will be automatically sanitized if a name collision occurs
Remarks
The copy is not set as current worksheet. The existing one is kept. The source worksheet can originate from any workbook
Returns
Copied worksheet

Definition at line 561 of file Workbook.cs.

◆ CopyWorksheetTo() [1/3]

Worksheet NanoXLSX.Workbook.CopyWorksheetTo ( int sourceWorksheetIndex,
string newWorksheetName,
Workbook targetWorkbook,
bool sanitizeSheetName = true )

Copies a worksheet of the current workbook by its index into another workbook.

Parameters
sourceWorksheetIndexIndex of the worksheet to copy, originated in this workbook
newWorksheetNameName of the new worksheet (copy)
targetWorkbookWorkbook to copy the worksheet into
sanitizeSheetNameIf true, the new name will be automatically sanitized if a name collision occurs
Remarks
The copy is not set as current worksheet. The existing one is kept
Returns
Copied worksheet

Definition at line 590 of file Workbook.cs.

◆ CopyWorksheetTo() [2/3]

Worksheet NanoXLSX.Workbook.CopyWorksheetTo ( string sourceWorksheetName,
string newWorksheetName,
Workbook targetWorkbook,
bool sanitizeSheetName = true )

Copies a worksheet of the current workbook by its name into another workbook.

Parameters
sourceWorksheetNameName of the worksheet to copy, originated in this workbook
newWorksheetNameName of the new worksheet (copy)
targetWorkbookWorkbook to copy the worksheet into
sanitizeSheetNameIf true, the new name will be automatically sanitized if a name collision occurs
Remarks
The copy is not set as current worksheet. The existing one is kept
Returns
Copied worksheet

Definition at line 575 of file Workbook.cs.

◆ CopyWorksheetTo() [3/3]

Worksheet NanoXLSX.Workbook.CopyWorksheetTo ( Worksheet sourceWorksheet,
string newWorksheetName,
Workbook targetWorkbook,
bool sanitizeSheetName = true )
static

Copies a worksheet of any workbook into the another workbook.

Parameters
sourceWorksheetWorksheet to copy
newWorksheetNameName of the new worksheet (copy)
targetWorkbookWorkbook to copy the worksheet into
sanitizeSheetNameIf true, the new name will be automatically sanitized if a name collision occurs
Remarks
The copy is not set as current worksheet. The existing one is kept
Returns
Copied worksheet

Definition at line 606 of file Workbook.cs.

◆ GetMruColors()

IReadOnlyList< string > NanoXLSX.Workbook.GetMruColors ( )

Gets the MRU color list.

Returns
Immutable list of color values

Definition at line 234 of file Workbook.cs.

◆ GetWorksheet() [1/2]

Worksheet NanoXLSX.Workbook.GetWorksheet ( int index)

Gets a worksheet from this workbook by index.

Parameters
indexIndex of the worksheet
Returns
Worksheet with the passed index
Exceptions
WorksheetExceptionThrows a RangeException if the worksheet was not found in the worksheet collection

Definition at line 494 of file Workbook.cs.

◆ GetWorksheet() [2/2]

Worksheet NanoXLSX.Workbook.GetWorksheet ( string name)

Gets a worksheet from this workbook by name.

Parameters
nameName of the worksheet
Returns
Worksheet with the passed name
Exceptions
WorksheetExceptionThrows a WorksheetException if the worksheet was not found in the worksheet collection

Definition at line 478 of file Workbook.cs.

◆ RemoveWorksheet() [1/2]

void NanoXLSX.Workbook.RemoveWorksheet ( int index)

Removes the defined worksheet based on its index. If the worksheet is the current or selected worksheet, the current and / or the selected worksheet will be set to the last worksheet of the workbook. If the last worksheet is removed, the selected worksheet will be set to 0 and the current worksheet to null.

Parameters
indexIndex within the worksheets list
Exceptions
WorksheetExceptionThrows a WorksheetException if the index is out of range

Definition at line 359 of file Workbook.cs.

◆ RemoveWorksheet() [2/2]

void NanoXLSX.Workbook.RemoveWorksheet ( string name)

Removes the defined worksheet based on its name. If the worksheet is the current or selected worksheet, the current and / or the selected worksheet will be set to the last worksheet of the workbook. If the last worksheet is removed, the selected worksheet will be set to 0 and the current worksheet to null.

Parameters
nameName of the worksheet
Exceptions
WorksheetExceptionThrows a WorksheetException if the name of the worksheet is unknown

Definition at line 340 of file Workbook.cs.

◆ SetCurrentWorksheet() [1/3]

Worksheet NanoXLSX.Workbook.SetCurrentWorksheet ( int worksheetIndex)

Sets the current worksheet.

Parameters
worksheetIndexZero-based worksheet index
Returns
Returns the current worksheet
Exceptions
WorksheetExceptionThrows a WorksheetException if the name of the worksheet is unknown

Definition at line 401 of file Workbook.cs.

◆ SetCurrentWorksheet() [2/3]

Worksheet NanoXLSX.Workbook.SetCurrentWorksheet ( string name)

Sets the current worksheet.

Parameters
nameName of the worksheet
Returns
Returns the current worksheet
Exceptions
WorksheetExceptionThrows a WorksheetException if the name of the worksheet is unknown

Definition at line 388 of file Workbook.cs.

◆ SetCurrentWorksheet() [3/3]

void NanoXLSX.Workbook.SetCurrentWorksheet ( Worksheet worksheet)

Sets the current worksheet.

Parameters
worksheetWorksheet object (must be in the collection of worksheets)
Exceptions
WorksheetExceptionThrows a WorksheetException if the worksheet was not found in the worksheet collection

Definition at line 413 of file Workbook.cs.

◆ SetSelectedWorksheet() [1/3]

void NanoXLSX.Workbook.SetSelectedWorksheet ( int worksheetIndex)

Sets the selected worksheet in the output workbook.

Remarks
This method does not set the current worksheet while design time. Use SetCurrentWorksheet instead for this
Parameters
worksheetIndexZero-based worksheet index
Exceptions
RangeExceptionThrows a RangeException if the index of the worksheet is out of range
WorksheetExceptionThrows a WorksheetException if the worksheet to be set selected is hidden

Definition at line 446 of file Workbook.cs.

◆ SetSelectedWorksheet() [2/3]

void NanoXLSX.Workbook.SetSelectedWorksheet ( string name)

Sets the selected worksheet in the output workbook.

Parameters
nameName of the worksheet
Exceptions
WorksheetExceptionThrows a WorksheetException if the name of the worksheet is unknown

Definition at line 429 of file Workbook.cs.

◆ SetSelectedWorksheet() [3/3]

void NanoXLSX.Workbook.SetSelectedWorksheet ( Worksheet worksheet)

Sets the selected worksheet in the output workbook.

Remarks
This method does not set the current worksheet while design time. Use SetCurrentWorksheet instead for this
Parameters
worksheetWorksheet object (must be in the collection of worksheets)
Exceptions
WorksheetExceptionThrows a WorksheetException if the worksheet was not found in the worksheet collection or if it is hidden

Definition at line 462 of file Workbook.cs.

◆ SetWorkbookProtection()

void NanoXLSX.Workbook.SetWorkbookProtection ( bool state,
bool protectWindows,
bool protectStructure,
string password )

Sets or removes the workbook protection. If protectWindows and protectStructure are both false, the workbook will not be protected.

Parameters
stateIf true, the workbook will be protected, otherwise not
protectWindowsIf true, the windows will be locked if the workbook is protected
protectStructureIf true, the structure will be locked if the workbook is protected
passwordOptional password. If null or empty, no password will be set in case of protection

Definition at line 510 of file Workbook.cs.

Property Documentation

◆ CurrentWorksheet

Worksheet NanoXLSX.Workbook.CurrentWorksheet
get

Gets the current worksheet.

Definition at line 63 of file Workbook.cs.

◆ Filename

string NanoXLSX.Workbook.Filename
getset

Gets or sets the filename of the workbook.

Remarks
Note that the file name is not sanitized. If a filename is set that is not compliant to the file system, saving of the workbook may fail

Definition at line 74 of file Workbook.cs.

◆ Hidden

bool NanoXLSX.Workbook.Hidden
getset

Gets or sets whether the whole workbook is hidden.

Remarks
A hidden workbook can only be made visible, using another, already visible Excel window

Definition at line 138 of file Workbook.cs.

◆ LockStructureIfProtected

bool NanoXLSX.Workbook.LockStructureIfProtected
get

Gets whether the structure are locked if workbook is protected. See also SetWorkbookProtection.

Definition at line 83 of file Workbook.cs.

◆ LockWindowsIfProtected

bool NanoXLSX.Workbook.LockWindowsIfProtected
get

Gets whether the windows are locked if workbook is protected. See also SetWorkbookProtection.

Definition at line 91 of file Workbook.cs.

◆ SelectedWorksheet

int NanoXLSX.Workbook.SelectedWorksheet
get

Gets the selected worksheet. The selected worksheet is not the current worksheet while design time but the selected sheet in the output file.

Definition at line 108 of file Workbook.cs.

◆ UseWorkbookProtection

bool NanoXLSX.Workbook.UseWorkbookProtection
getset

Gets or sets whether the workbook is protected.

Definition at line 116 of file Workbook.cs.

◆ WorkbookMetadata

Metadata NanoXLSX.Workbook.WorkbookMetadata
getset

Meta data object of the workbook.

Definition at line 99 of file Workbook.cs.

◆ WorkbookProtectionPassword

virtual IPassword NanoXLSX.Workbook.WorkbookProtectionPassword
getset

Password instance of the protected workbook. If a password was set, the pain text representation and the hash can be read from the instance.

Remarks
The password of this property is stored in plain text at runtime but not stored to a workbook. The plain text password cannot be recovered when loading a workbook. The hash is retrieved and can be reused, if no changes are made in the area of workbook protection (SetWorkbookProtection(bool, bool, bool, string))

Definition at line 123 of file Workbook.cs.

◆ WorkbookTheme

Theme NanoXLSX.Workbook.WorkbookTheme = Theme.GetDefaultTheme()
getset

Gets or sets the theme of the workbook. The default is defined by Theme.GetDefaultTheme. However, the theme can be nullified.

Definition at line 143 of file Workbook.cs.

◆ Worksheets

List<Worksheet> NanoXLSX.Workbook.Worksheets
get

Gets the list of worksheets in the workbook.

Definition at line 128 of file Workbook.cs.

◆ WS

Shortener NanoXLSX.Workbook.WS
get

Gets the shortener object for the current worksheet.

Definition at line 54 of file Workbook.cs.


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