NanoXLSX.Core 3.2.1
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.
void AddMruColor (Color color)
 Adds a generic color value. This can be an RGB/ARGB color, Auto, Theme, Indexed or System color.
IReadOnlyList< ColorGetMruColors ()
 Gets the MRU color list.
void ClearMruColors ()
 Clears the MRU color list.
DefinedName AddDefinedNameCell (string name, Worksheet worksheet, string cellAddress, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a single cell, to the workbook.
DefinedName AddDefinedNameCell (string name, Worksheet worksheet, int column, int row, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a single cell, to the workbook.
DefinedName AddDefinedNameCell (string name, Worksheet worksheet, Address cellAddress, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a single cell, to the workbook.
DefinedName AddDefinedNameRange (string name, Worksheet worksheet, string rangeAddress, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a cell range, to the workbook.
DefinedName AddDefinedNameRange (string name, Worksheet worksheet, Address startAddress, Address endAddress, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a cell range, to the workbook.
DefinedName AddDefinedNameRange (string name, Worksheet worksheet, int startColumn, int startRow, int endColumn, int endRow, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a cell range, to the workbook.
DefinedName AddDefinedNameRange (string name, Worksheet worksheet, Range rangeAddress, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a cell range, to the workbook.
DefinedName AddDefinedNameConstant (string name, object value, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a constant value, to the workbook.
DefinedName AddDefinedNameFormula (string name, string formula, Worksheet localWorksheet=null, string comment=null)
 Adds a defined name, pointing to a formula expression, to the workbook. Do not add a leading equal sign (=) to the formula. For simple cell references (e.g. "A1") use AddDefinedNameCell(string, Worksheet, Address, Worksheet, string) or one of the overloaded methods. For cell range references (e.g. "A1:C3") use AddDefinedNameRange(string, Worksheet, Address, Address, Worksheet, string) or one of the overloaded methods.
bool RemoveDefinedName (string name, Worksheet localSheet=null)
 Removes the defined name with the supplied name and scope.
void ClearDefinedNames ()
 Removes all defined names of the workbook and removes their references from formula cells.
DefinedName GetDefinedName (string name, Worksheet localSheet=null)
 Gets the defined name with the supplied name and scope.
IReadOnlyList< DefinedNameGetDefinedNames ()
 Gets a read-only view of all defined names in this workbook in insertion order.
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 24 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 159 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 168 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 181 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 192 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 205 of file Workbook.cs.

Member Function Documentation

◆ AddDefinedNameCell() [1/3]

DefinedName NanoXLSX.Workbook.AddDefinedNameCell ( string name,
Worksheet worksheet,
Address cellAddress,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a single cell, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
cellAddressAddress object of the target cell
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or cell address is null
FormatExceptionThrown if the name of the defined name or the cell address is invalid

Definition at line 307 of file Workbook.cs.

◆ AddDefinedNameCell() [2/3]

DefinedName NanoXLSX.Workbook.AddDefinedNameCell ( string name,
Worksheet worksheet,
int column,
int row,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a single cell, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
columnColumn number (zero-based) of the target cell
rowRow number (zero-based) of the target cell
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or cell address is null
FormatExceptionThrown if the name of the defined name or the cell address is invalid

Definition at line 290 of file Workbook.cs.

◆ AddDefinedNameCell() [3/3]

DefinedName NanoXLSX.Workbook.AddDefinedNameCell ( string name,
Worksheet worksheet,
string cellAddress,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a single cell, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
cellAddressCell address as string (cannot be null)
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or cell address is null
FormatExceptionThrown if the name of the defined name or the cell address is invalid

Definition at line 272 of file Workbook.cs.

◆ AddDefinedNameConstant()

DefinedName NanoXLSX.Workbook.AddDefinedNameConstant ( string name,
object value,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a constant value, to the workbook.

Parameters
nameUnique name of defined name
valueConstant value
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the constant value is null
FormatExceptionThrown if the name of the defined name is invalid
Remarks
A constant should be one of the compatible types: string, int, uint, double, float, long, ulong, short, ushort, decimal, byte, sbyte, DateTime, TimeSpan, bool. Other types will be treated as string, using object.ToString().

Definition at line 404 of file Workbook.cs.

◆ AddDefinedNameFormula()

DefinedName NanoXLSX.Workbook.AddDefinedNameFormula ( string name,
string formula,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a formula expression, to the workbook. Do not add a leading equal sign (=) to the formula. For simple cell references (e.g. "A1") use AddDefinedNameCell(string, Worksheet, Address, Worksheet, string) or one of the overloaded methods. For cell range references (e.g. "A1:C3") use AddDefinedNameRange(string, Worksheet, Address, Address, Worksheet, string) or one of the overloaded methods.

Parameters
nameUnique name of defined name
formulaFormula value
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the formula value is null or empty
FormatExceptionThrown if the name of the defined name is invalid
Remarks
The formula is not evaluated. Also do not add references to external workbooks (will cause an exception on save), as longs no NanoXLSX extension is loaded that can handle external links.

Definition at line 426 of file Workbook.cs.

◆ AddDefinedNameRange() [1/4]

DefinedName NanoXLSX.Workbook.AddDefinedNameRange ( string name,
Worksheet worksheet,
Address startAddress,
Address endAddress,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a cell range, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
startAddressStart address object of the target range
endAddressEnd address object of the target range
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or range address is null
FormatExceptionThrown if the name of the defined name or the range address is invalid

Definition at line 349 of file Workbook.cs.

◆ AddDefinedNameRange() [2/4]

DefinedName NanoXLSX.Workbook.AddDefinedNameRange ( string name,
Worksheet worksheet,
int startColumn,
int startRow,
int endColumn,
int endRow,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a cell range, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
startColumnStart column number (zero-based) of the target range
startRowStart row number (zero-based) of the target range
endColumnEnd column number (zero-based) of the target range
endRowEnd row number (zero-based) of the target range
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or range address is null
FormatExceptionThrown if the name of the defined name or the range address is invalid

Definition at line 368 of file Workbook.cs.

◆ AddDefinedNameRange() [3/4]

DefinedName NanoXLSX.Workbook.AddDefinedNameRange ( string name,
Worksheet worksheet,
Range rangeAddress,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a cell range, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
rangeAddressRange object of the target range
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or range address is null
FormatExceptionThrown if the name of the defined name or the range address is invalid

Definition at line 384 of file Workbook.cs.

◆ AddDefinedNameRange() [4/4]

DefinedName NanoXLSX.Workbook.AddDefinedNameRange ( string name,
Worksheet worksheet,
string rangeAddress,
Worksheet localWorksheet = null,
string comment = null )

Adds a defined name, pointing to a cell range, to the workbook.

Parameters
nameUnique name of defined name
worksheetWorksheet that contains the target cell (cannot be null)
rangeAddressAddress of the target range as string
localWorksheetIf not null, the defined name will only be available on the given worksheet. The combination of 'name' and 'worksheet' must be unique
commentOptional comment of the defined name
Returns
Returns the added defined name object
Exceptions
WorksheetExceptionThrown if the worksheet or range address is null
FormatExceptionThrown if the name of the defined name or the range address is invalid
Remarks
The range string must contain an explicit start and end address, for example A1:B2. To define a name for one cell, use AddDefinedNameCell(string, Worksheet, string, Worksheet, string).

Definition at line 332 of file Workbook.cs.

◆ AddMruColor() [1/2]

void NanoXLSX.Workbook.AddMruColor ( Color color)

Adds a generic color value. This can be an RGB/ARGB color, Auto, Theme, Indexed or System color.

Parameters
colorColor instance

Definition at line 237 of file Workbook.cs.

◆ AddMruColor() [2/2]

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 227 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 564 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 588 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 607 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 619 of file Workbook.cs.

◆ ClearDefinedNames()

void NanoXLSX.Workbook.ClearDefinedNames ( )

Removes all defined names of the workbook and removes their references from formula cells.

Remarks
Important: Removing defined names may remove references in worksheets. If a workbook is saved in this state, it can lead to broken formula references, indicated by "#NAME?"

Definition at line 504 of file Workbook.cs.

◆ ClearMruColors()

void NanoXLSX.Workbook.ClearMruColors ( )

Clears the MRU color list.

Definition at line 254 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 860 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 846 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 874 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 903 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 888 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 919 of file Workbook.cs.

◆ GetDefinedName()

DefinedName NanoXLSX.Workbook.GetDefinedName ( string name,
Worksheet localSheet = null )

Gets the defined name with the supplied name and scope.

Parameters
nameName of the defined name.
localSheetWorksheet scope, or null for workbook scope.
Returns
The matching DefinedName instance, or null if no match was found.

Definition at line 521 of file Workbook.cs.

◆ GetDefinedNames()

IReadOnlyList< DefinedName > NanoXLSX.Workbook.GetDefinedNames ( )

Gets a read-only view of all defined names in this workbook in insertion order.

Returns
Read-only list of DefinedName instances.

Definition at line 531 of file Workbook.cs.

◆ GetMruColors()

IReadOnlyList< Color > NanoXLSX.Workbook.GetMruColors ( )

Gets the MRU color list.

Returns
Immutable list of color instances

Definition at line 246 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 807 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 791 of file Workbook.cs.

◆ RemoveDefinedName()

bool NanoXLSX.Workbook.RemoveDefinedName ( string name,
Worksheet localSheet = null )

Removes the defined name with the supplied name and scope.

Parameters
nameName of the defined name to remove.
localSheetWorksheet scope, or null for workbook scope.
Returns
True if a matching defined name was removed, false if no match was found.
Remarks
Important: Removing defined names may remove references in worksheets. If a workbook is saved in this state, it can lead to broken formula references, indicated by "#NAME?"

Definition at line 470 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 672 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 653 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 714 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 701 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 726 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 759 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 742 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 775 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 823 of file Workbook.cs.

Property Documentation

◆ CurrentWorksheet

Worksheet NanoXLSX.Workbook.CurrentWorksheet
get

Gets the current worksheet.

Definition at line 66 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 77 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 141 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 86 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 94 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 111 of file Workbook.cs.

◆ UseWorkbookProtection

bool NanoXLSX.Workbook.UseWorkbookProtection
getset

Gets or sets whether the workbook is protected.

Definition at line 119 of file Workbook.cs.

◆ WorkbookMetadata

Metadata NanoXLSX.Workbook.WorkbookMetadata
getset

Meta data object of the workbook.

Definition at line 102 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 126 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 146 of file Workbook.cs.

◆ Worksheets

List<Worksheet> NanoXLSX.Workbook.Worksheets
get

Gets the list of worksheets in the workbook.

Definition at line 131 of file Workbook.cs.

◆ WS

Shortener NanoXLSX.Workbook.WS
get

Gets the shortener object for the current worksheet.

Definition at line 57 of file Workbook.cs.


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