Workbook Class
Represents a root object to create an Excel spreadsheet.
Inheritance Hierarchy
SystemObject
  Aspose.CellsWorkbook

Namespace: Aspose.Cells
Assembly: Aspose.Cells (in Aspose.Cells.dll) Version: 19.11.0.0 (19.11)
Syntax
public class Workbook : IDisposable

The Workbook type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleWorkbook
Initializes a new instance of the Workbook class.
Public methodWorkbook(Stream)
Initializes a new instance of the Workbook class and open a stream.
Public methodWorkbook(String)
Initializes a new instance of the Workbook class and open a file.
Public methodCode exampleWorkbook(FileFormatType)
Initializes a new instance of the Workbook class.
Public methodWorkbook(Stream, LoadOptions)
Initializes a new instance of the Workbook class and open stream.
Public methodWorkbook(String, LoadOptions)
Initializes a new instance of the Workbook class and open a file.
Properties
  NameDescription
Public propertyAbsolutePath
Gets and sets the absolute path of the file.
Public propertyCode exampleBuiltInDocumentProperties
Returns a DocumentProperties collection that represents all the built-in document properties of the spreadsheet.
Public propertyColors
Returns colors in the palette for the spreadsheet.
Public propertyContentTypeProperties
Gets the contenttypeproperties objects in the workbook.
Public propertyCountOfStylesInPool
Gets number of the styles in the style pool.
Public propertyCode exampleCustomDocumentProperties
Returns a DocumentProperties collection that represents all the custom document properties of the spreadsheet.
Public propertyCustomXmlParts
Represents a InnerCustom XML Data Storage Part (custom XML data within a package).
Public propertyDataConnections
Gets the ExternalConnection collection.
Public propertyDataMashup
Gets mashup data.
Public propertyDataSorter
Gets a DataSorter object to sort data.
Public propertyCode exampleDefaultStyle
Gets or sets the default Style object of the workbook.
Public propertyFileFormat
Gets and sets the file format.
Public propertyFileName
Gets and sets the current file name.
Public propertyHasMacro
Indicates if this spreadsheet contains macro/VBA.
Public propertyHasRevisions
Gets if the workbook has any tracked changes
Public propertyInterruptMonitor
Gets and sets the interrupt monitor.
Public propertyIsDigitallySigned
Indicates if this spreadsheet is digitally signed.
Public propertyIsLicensed
Indicates whether license is set.
Public propertyRibbonXml
Gets and sets the XML file that defines the Ribbon UI.
Public propertySettings
Represents the workbook settings.
Public propertyTheme
Gets the theme name.
Public propertyVbaProject
Gets the VbaProject in a spreadsheet.
Public propertyWorksheets
Gets the WorksheetCollection collection in the spreadsheet.
Methods
  NameDescription
Public methodAcceptAllRevisions
Accepts all tracked changes in the workbook.
Public methodAddDigitalSignature
Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
Public methodCalculateFormula
Calculates the result of formulas.
Public methodCalculateFormula(Boolean)
Calculates the result of formulas.
Public methodCalculateFormula(CalculationOptions)
Calcualting formulas in this workbook.
Public methodCalculateFormula(Boolean, ICustomFunction)
Calculates the result of formulas.
Public methodChangePalette
Changes the palette for the spreadsheet in the specified index.
Public methodCombine
Combines another Workbook object.
Public methodCopy
Copies data from a source Workbook object.
Public methodCopyTheme
Copies the theme from another workbook.
Public methodCreateBuiltinStyle
Creates built-in style by given type.
Public methodCreateCellsColor
Creates a CellsColor object.
Public methodCreateStyle
Creates a new style.
Public methodCustomTheme
Customs the theme.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodExportXml(String, Stream)
Export XML data.
Public methodExportXml(String, String)
Export XML data.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetDigitalSignature
Gets digital signature from file.
Public methodGetFonts
Gets all fonts in the style pool.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetMatchingColor
Find best matching Color in current palette.
Public methodGetNamedStyle
Gets the named style in the style pool.
Public methodGetStyleInPool
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.
Public methodGetThemeColor
Gets theme color.
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodHasExernalLinks
Indicates whether this workbook contains external links to other data sources.
Public methodImportXml(Stream, String, Int32, Int32)
Imports an xml file into the workbook.
Public methodImportXml(String, String, Int32, Int32)
Imports an xml file into the workbook.
Public methodIsColorInPalette
Checks if a color is in the palette for the spreadsheet.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProtect
Protects a workbook.
Public methodProtectSharedWorkbook
Protects a shared workbook.
Public methodRemoveDigitalSignature
Removes digital signature from this spreadsheet.
Public methodRemoveExternalLinks
Removes all external links in the workbook.
Public methodRemoveMacro
Removes VBA/macro from this spreadsheet.
Public methodRemoveUnusedStyles
Remove all unused styles.
Public methodReplace(Boolean, Object)
Replaces cells' values with new data.
Public methodReplace(Int32, Object)
Replaces cells' values with new data.
Public methodCode exampleReplace(String, DataTable)
Replaces cells' values with data from a DataTable.
Public methodCode exampleReplace(String, Double)
Replaces a cell's value with a new double.
Public methodCode exampleReplace(String, Int32)
Replaces a cell's value with a new integer.
Public methodCode exampleReplace(String, String)
Replaces a cell's value with a new string.
Public methodCode exampleReplace(String, Double, Boolean)
Replaces cells' values with a double array.
Public methodCode exampleReplace(String, Int32, Boolean)
Replaces cells' values with an integer array.
Public methodReplace(String, String, ReplaceOptions)
Replaces a cell's value with a new string.
Public methodCode exampleReplace(String, String, Boolean)
Replaces a cell's value with a new string array.
Public methodSave(String)
Save the workbook to the disk.
Public methodSave(Stream, SaveFormat)
Saves the workbook to the stream.
Public methodSave(Stream, SaveOptions)
Saves the workbook to the stream.
Public methodSave(String, SaveFormat)
Saves the workbook to the disk.
Public methodSave(String, SaveOptions)
Saves the workbook to the disk.
Public methodSave(HttpResponse, String, ContentDisposition, SaveOptions)
Creates the result spreadsheet and transfer it to the client then open it in the browser or MS Workbook.
Public methodSaveToStream
Saves Excel file to a MemoryStream object and returns it.
Public methodSetDigitalSignature
Sets digital signature to an spreadsheet file (Excel2007 and later).
Public methodSetEncryptionOptions
Set Encryption Options.
Public methodSetThemeColor
Sets the theme color
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodUnprotect
Unprotects a workbook.
Public methodUnprotectSharedWorkbook
Unprotects a shared workbook.
Public methodUpdateLinkedDataSource
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 creates a Workbook, opens a file named designer.xls in it 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 = MapPath("Designer") + "\\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);
XlsSaveOptions saveOptions = new XlsSaveOptions();
workbook.Save(Response, "result.xls", ContentDisposition.Inline, saveOptions);

[Visual Basic]



'Open a designer file
Dim designerFile as String = MapPath("Designer") + "\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)
Dim saveOptions as XlsSaveOptions  = new XlsSaveOptions()
workbook.Save(Response, "result.xls", ContentDisposition.Inline, saveOptions)
See Also