C# Class PicoXLSX.Workbook

Class representing a workbook
Mostra file Open project: rabanti-github/PicoXLSX Class Usage Examples

Public Methods

Method Description
AddStyle ( Style style, bool distinct ) : Style

Adds a style to the style sheet of the workbook

AddWorksheet ( string name ) : void

Adding a new Worksheet

RemoveStyle ( Style style ) : void

Removes the passed style from the style sheet

RemoveStyle ( Style style, bool onlyIfUnused ) : void

Removes the defined style from the style sheet of the workbook

RemoveStyle ( string styleName ) : void

Removes the defined style from the style sheet of the workbook

RemoveStyle ( string styleName, bool onlyIfUnused ) : void

Removes the defined style from the style sheet of the workbook

RemoveWorksheet ( string name ) : void

Removes the defined worksheet

ReorganizeStyles ( List &borders, List &fills, List &fonts, List &numberFormats, List &cellXfs ) : void

Method to prepare the styles before saving the workbook. Don't use the method otherwise. Styles will be reordered and probably removed from the style sheet

This method is for internal use but must be public. Otherwise it's not possible to access it from low level methods. Don't use it

ResolveMergedCells ( ) : void

Method to resolve all merged cells in all worksheets. Only the value of the very first cell of the locked cells range will be visible. The other values are still present (set to EMPTY) but will not be stored in the worksheet.

Save ( ) : void

Saves the workbook

SaveAs ( string filename ) : void

Saves the workbook with the defined name

SetCurrentWorksheet ( string name ) : Worksheet

Sets the current worksheet

SetSelectedWorksheet ( Worksheet worksheet ) : void

Sets the selected worksheet in the output workbook

This method does not set the current worksheet while design time. Use SetCurrentWorksheet instead for this

SetSelectedWorksheet ( int worksheetIndex ) : void

Sets the selected worksheet in the output workbook

This method does not set the current worksheet while design time. Use SetCurrentWorksheet instead for this

SetWorkbookProtection ( bool state, bool protectWindows, bool protectStructure, string password ) : void

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

Workbook ( bool createWorkSheet ) : System

Default Constructor with additional parameter to create a default worksheet

Workbook ( string filename, string sheetName ) : System

Constructor with filename ant the name of the first worksheet

Method Details

AddStyle() public method

Adds a style to the style sheet of the workbook
Throws an UndefinedStyleException if the style already exists and parameter 'distinct' is set to false
public AddStyle ( Style style, bool distinct ) : Style
style Style Style to add
distinct bool If true, the passed style will be replaced by an identical style if existing. Otherwise an exception will be thrown in case of a duplicate
return Style

AddWorksheet() public method

Adding a new Worksheet
Throws a WorksheetNameAlreadxExistsException if the name of the worksheet already exists Throws a FormatException if the name contains illegal characters or is out of range (length between 1 an 31 characters)
public AddWorksheet ( string name ) : void
name string Name of the new worksheet
return void

RemoveStyle() public method

Removes the passed style from the style sheet
Throws an UndefinedStyleException if the style was not found in the style collection (could not be referenced)
public RemoveStyle ( Style style ) : void
style Style Style to remove
return void

RemoveStyle() public method

Removes the defined style from the style sheet of the workbook
Throws an UndefinedStyleException if the style was not found in the style collection (could not be referenced)
public RemoveStyle ( Style style, bool onlyIfUnused ) : void
style Style Style to remove
onlyIfUnused bool If true, the style will only be removed if not used in any cell
return void

RemoveStyle() public method

Removes the defined style from the style sheet of the workbook
Throws an UndefinedStyleException if the style was not found in the style collection (could not be referenced)
public RemoveStyle ( string styleName ) : void
styleName string Name of the style to be removed
return void

RemoveStyle() public method

Removes the defined style from the style sheet of the workbook
Throws an UndefinedStyleException if the style was not found in the style collection (could not be referenced)
public RemoveStyle ( string styleName, bool onlyIfUnused ) : void
styleName string Name of the style to be removed
onlyIfUnused bool If true, the style will only be removed if not used in any cell
return void

RemoveWorksheet() public method

Removes the defined worksheet
Throws a UnknownWorksheetException if the name of the worksheet is unknown
public RemoveWorksheet ( string name ) : void
name string Name of the worksheet
return void

ReorganizeStyles() public method

Method to prepare the styles before saving the workbook. Don't use the method otherwise. Styles will be reordered and probably removed from the style sheet
This method is for internal use but must be public. Otherwise it's not possible to access it from low level methods. Don't use it
Throws an UndefinedStyleException if one of the passed style components cannot be referenced or is null
public ReorganizeStyles ( List &borders, List &fills, List &fonts, List &numberFormats, List &cellXfs ) : void
borders List Out parameter for a sorted list of Style.Border objects
fills List Out parameter for a sorted list of Style.Fill objects
fonts List Out parameter for a sorted list of Style.Font objects
numberFormats List Out parameter for a sorted list of Style.NumberFormat objects
cellXfs List Out parameter for a sorted list of Style.CellXf objects
return void

ResolveMergedCells() public method

Method to resolve all merged cells in all worksheets. Only the value of the very first cell of the locked cells range will be visible. The other values are still present (set to EMPTY) but will not be stored in the worksheet.
Throws an UndefinedStyleException if one of the styles of the merged cells cannot be referenced or is null
public ResolveMergedCells ( ) : void
return void

Save() public method

Saves the workbook
Throws IOException in case of an error Throws an OutOfRangeException if the start or end address of a handled cell range was out of range Throws a FormatException if a handled date cannot be translated to (Excel internal) OADate Throws an UndefinedStyleException if one of the styles of the workbook cannot be referenced or is null
public Save ( ) : void
return void

SaveAs() public method

Saves the workbook with the defined name
Throws IOException in case of an error Throws an OutOfRangeException if the start or end address of a handled cell range was out of range Throws a FormatException if a handled date cannot be translated to (Excel internal) OADate Throws an UndefinedStyleException if one of the styles of the workbook cannot be referenced or is null
public SaveAs ( string filename ) : void
filename string filename of the saved workbook
return void

SetCurrentWorksheet() public method

Sets the current worksheet
Throws a UnknownWorksheetException if the name of the worksheet is unknown
public SetCurrentWorksheet ( string name ) : Worksheet
name string Name of the worksheet
return Worksheet

SetSelectedWorksheet() public method

Sets the selected worksheet in the output workbook
This method does not set the current worksheet while design time. Use SetCurrentWorksheet instead for this
Throws a UnknownWorksheetException if the worksheet was not found in the worksheet collection
public SetSelectedWorksheet ( Worksheet worksheet ) : void
worksheet Worksheet Worksheet object (must be in the collection of worksheets)
return void

SetSelectedWorksheet() public method

Sets the selected worksheet in the output workbook
This method does not set the current worksheet while design time. Use SetCurrentWorksheet instead for this
Throws a OutOfRangeException if the index of the worksheet is out of range
public SetSelectedWorksheet ( int worksheetIndex ) : void
worksheetIndex int Zero-based worksheet index
return void

SetWorkbookProtection() public method

Sets or removes the workbook protection. If protectWindows and protectStructure are both false, the workbook will not be protected
public SetWorkbookProtection ( bool state, bool protectWindows, bool protectStructure, string password ) : void
state bool If true, the workbook will be protected, otherwise not
protectWindows bool If true, the windows will be locked if the workbook is protected
protectStructure bool If true, the structure will be locked if the workbook is protected
password string Optional password. If null or empty, no password will be set in case of protection
return void

Workbook() public method

Default Constructor with additional parameter to create a default worksheet
public Workbook ( bool createWorkSheet ) : System
createWorkSheet bool If true, a default worksheet will be crated and set as default worksheet
return System

Workbook() public method

Constructor with filename ant the name of the first worksheet
public Workbook ( string filename, string sheetName ) : System
filename string Filename of the workbook
sheetName string Name of the first worksheet
return System