Workbook

Workbook class

Represents a root object to create an Excel spreadsheet.

public class Workbook : IDisposable

Constructors

Name Description
Workbook() Initializes a new instance of the Workbook class.
Workbook(FileFormatType) Initializes a new instance of the Workbook class.
Workbook(Stream) Initializes a new instance of the Workbook class and open a stream.
Workbook(string) Initializes a new instance of the Workbook class and open a file.
Workbook(Stream, LoadOptions) Initializes a new instance of the Workbook class and open stream.
Workbook(string, LoadOptions) Initializes a new instance of the Workbook class and open a file.

Properties

Name Description
AbsolutePath { get; set; } Gets and sets the absolute path of the file.
BuiltInDocumentProperties { get; } Returns a DocumentProperty collection that represents all the built-in document properties of the spreadsheet.
CellsDataTableFactory { get; } Gets the factory for building ICellsDataTable from custom objects
Colors { get; } Returns colors in the palette for the spreadsheet.
ContentTypeProperties { get; } Gets the list of ContentTypeProperty objects in the workbook.
CountOfStylesInPool { get; } Gets number of the styles in the style pool.
CustomDocumentProperties { get; } Returns a DocumentProperty collection that represents all the custom document properties of the spreadsheet.
CustomXmlParts { get; } Represents a Custom XML Data Storage Part (custom XML data within a package).
DataConnections { get; } Gets the ExternalConnection collection.
DataMashup { get; } Gets mashup data.
DataSorter { get; } Gets a DataSorter object to sort data.
DefaultStyle { get; set; } Gets or sets the default Style object of the workbook.
FileFormat { get; set; } Gets and sets the file format.
FileName { get; set; } Gets and sets the current file name.
HasMacro { get; } Indicates if this spreadsheet contains macro/VBA.
HasRevisions { get; } Gets if the workbook has any tracked changes
InterruptMonitor { get; set; } Gets and sets the interrupt monitor.
IsDigitallySigned { get; } Indicates if this spreadsheet is digitally signed.
IsLicensed { get; } Indicates whether license is set.
IsWorkbookProtectedWithPassword { get; } Indicates whether structure or window is protected with password.
RibbonXml { get; set; } Gets and sets the XML file that defines the Ribbon UI.
Settings { get; } Represents the workbook settings.
Theme { get; } Gets the theme name.
VbaProject { get; } Gets the VbaProject in a spreadsheet.
Worksheets { get; } Gets the WorksheetCollection collection in the spreadsheet.

Methods

Name Description
AcceptAllRevisions() Accepts all tracked changes in the workbook.
AddDigitalSignature(DigitalSignatureCollection) Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
CalculateFormula() Calculates the result of formulas.
CalculateFormula(bool) Calculates the result of formulas.
CalculateFormula(CalculationOptions) Calculating formulas in this workbook.
CalculateFormula(bool, ICustomFunction) (Obsolete.) Calculates the result of formulas.
ChangePalette(Color, int) Changes the palette for the spreadsheet in the specified index.
CloseAccessCache(AccessCacheOptions) Closes the session that uses caches to access data.
Combine(Workbook) Combines another Workbook object.
Copy(Workbook) Copies data from a source Workbook object.
Copy(Workbook, CopyOptions) Copies data from a source Workbook object.
CopyTheme(Workbook) Copies the theme from another workbook.
CreateBuiltinStyle(BuiltinStyleType) Creates built-in style by given type.
CreateCellsColor() Creates a CellsColor object.
CreateStyle() Creates a new style.
CustomTheme(string, Color[]) Customs the theme.
Dispose() Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
ExportXml(string, Stream) Export XML data.
ExportXml(string, string) Export XML data linked by the specified XML map.
GetDigitalSignature() Gets digital signature from file.
GetFonts() Gets all fonts in the style pool.
GetMatchingColor(Color) Find best matching Color in current palette.
GetNamedStyle(string) Gets the named style in the style pool.
GetStyleInPool(int) Gets the style in the style pool. All styles in the workbook will be gathered into a pool. There is only a simple reference index in the cells.
GetThemeColor(ThemeColorType) Gets theme color.
HasExernalLinks() (Obsolete.) Indicates whether this workbook contains external links to other data sources.
ImportXml(Stream, string, int, int) Imports/Updates an XML data file into the workbook.
ImportXml(string, string, int, int) Imports/Updates an XML data file into the workbook.
IsColorInPalette(Color) Checks if a color is in the palette for the spreadsheet.
ParseFormulas(bool) Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.
Protect(ProtectionType, string) Protects a workbook.
ProtectSharedWorkbook(string) Protects a shared workbook.
RefreshDynamicArrayFormulas(bool) Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data) Other formulas in the workbook will not be calculated recursively even if they were used by dynamic array formulas.
RefreshDynamicArrayFormulas(bool, CalculationOptions) Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data)
RemoveDigitalSignature() Removes digital signature from this spreadsheet.
RemoveExternalLinks() (Obsolete.) Removes all external links in the workbook.
RemoveMacro() Removes VBA/macro from this spreadsheet.
RemovePersonalInformation() Removes personal information.
RemoveUnusedStyles() Remove all unused styles.
Replace(bool, object) Replaces cells’ values with new data.
Replace(int, object) Replaces cells’ values with new data.
Replace(string, DataTable) Replaces cells’ values with data from a DataTable.
Replace(string, double) Replaces a cell’s value with a new double.
Replace(string, int) Replaces a cell’s value with a new integer.
Replace(string, string) Replaces a cell’s value with a new string.
Replace(string, double[], bool) Replaces cells’ values with a double array.
Replace(string, int[], bool) Replaces cells’ values with an integer array.
Replace(string, string, ReplaceOptions) Replaces a cell’s value with a new string.
Replace(string, string[], bool) Replaces a cell’s value with a new string array.
Save(string) Save the workbook to the disk.
Save(Stream, SaveFormat) Saves the workbook to the stream.
Save(Stream, SaveOptions) Saves the workbook to the stream.
Save(string, SaveFormat) Saves the workbook to the disk.
Save(string, SaveOptions) Saves the workbook to the disk.
Save(HttpResponse, string, ContentDisposition, SaveOptions) Creates the result spreadsheet and transfer it to the client then open it in the browser or MS Workbook.
Save(HttpResponse, string, ContentDisposition, SaveOptions, bool) Creates the result spreadsheet and transfer it to the client then open it in the browser or MS Workbook.
SaveToStream() Saves Excel file to a MemoryStream object and returns it.
SetDigitalSignature(DigitalSignatureCollection) Sets digital signature to an spreadsheet file (Excel2007 and later).
SetEncryptionOptions(EncryptionType, int) Set Encryption Options.
SetThemeColor(ThemeColorType, Color) Sets the theme color
StartAccessCache(AccessCacheOptions) Starts the session that uses caches to access data.
Unprotect(string) Unprotects a workbook.
UnprotectSharedWorkbook(string) Unprotects a shared workbook.
UpdateLinkedDataSource(Workbook[]) If this workbook contains external links to other data source, Aspose.Cells will attempt to retrieve the latest data.

Remarks

The Workbook class denotes an Excel spreadsheet. Each spreadsheet can contain multiple worksheets. The basic feature of the class is to open and save native excel files. The class has some advanced features like copying data from other Workbooks, combining two Workbooks and protecting the Excel spreadsheet.

Examples

The following example loads a Workbook from a file named designer.xls and makes the horizontal and vertical scroll bars invisible for the Workbook. It then replaces two string values with an Integer value and string value respectively within the spreadsheet and finally sends the updated file to the client browser.

[C#]

//Open a designer file
string designerFile = "designer.xls";
Workbook workbook = new Workbook(designerFile);

//Set scroll bars
workbook.Settings.IsHScrollBarVisible = false;
workbook.Settings.IsVScrollBarVisible = false;

//Replace the placeholder string with new values
int newInt = 100;
workbook.Replace("OldInt", newInt);

string newString = "Hello!";
workbook.Replace("OldString", newString);
workbook.Save("result.xls");

[Visual Basic]

'Open a designer file
Dim designerFile as String = "\designer.xls"
Dim workbook as Workbook = new Workbook(designerFile)

'Set scroll bars
workbook.IsHScrollBarVisible = False
workbook.IsVScrollBarVisible = False

'Replace the placeholder string with new values
Dim newInt as Integer = 100
workbook.Replace("OldInt", newInt)

Dim newString as String = "Hello!"
workbook.Replace("OldString", newString)
workbook.Save("result.xls")    

See Also