Class Workbook
Contents
[
Hide
]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. |
DataModel { get; } | Gets data model in the workbook. |
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. |
HasCustomFunction { get; } | Detects whether there is custom function used in this workbook, such as in cell’s formula, in defined names… |
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. |
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 another 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. |
CreateStyle(bool) | 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. |
MergeNamedStyles(Workbook) | Merges named styles from the other Excel file. |
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 as an Excel97-2003 xls file 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. |
UpdateCustomFunctionDefinition(CustomFunctionDefinition) | Updates definition of custom functions. |
UpdateLinkedDataSource(Workbook[]) | If this workbook contains external links to other data source, Aspose.Cells will attempt to retrieve the latest data from give sources. |
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, converting Excel to PDF, rendering Excel to image and protecting the Excel spreadsheet.
Examples
namespace AsposeCellsExamples
{
using Aspose.Cells;
using System;
public class WorkbookDemo
{
public static void WorkbookExample()
{
// Create a new Workbook instance
Workbook workbook = new Workbook();
// Access the default worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Set some properties of the workbook
workbook.FileName = "ExampleWorkbook.xlsx";
workbook.DefaultStyle.Font.Name = "Tahoma";
// Add a new worksheet
int newSheetIndex = workbook.Worksheets.Add();
Worksheet newWorksheet = workbook.Worksheets[newSheetIndex];
newWorksheet.Name = "NewSheet";
// Add some data to the new worksheet
newWorksheet.Cells["A1"].PutValue("Hello, Aspose.Cells!");
// Set some document properties
workbook.BuiltInDocumentProperties["Author"].Value = "John Smith";
workbook.CustomDocumentProperties.Add("Checked by", "Jane");
// Save the workbook to a file
workbook.Save("WorkbookExample.xlsx");
// Display some properties
Console.WriteLine("Workbook File Name: " + workbook.FileName);
Console.WriteLine("Default Font: " + workbook.DefaultStyle.Font.Name);
Console.WriteLine("Author: " + workbook.BuiltInDocumentProperties["Author"].Value);
Console.WriteLine("Custom Property 'Checked by': " + workbook.CustomDocumentProperties["Checked by"].Value);
// Check if the workbook is licensed
Console.WriteLine("Is Licensed: " + workbook.IsLicensed);
// Check if the workbook is digitally signed
Console.WriteLine("Is Digitally Signed: " + workbook.IsDigitallySigned);
// Check if the workbook contains macros
Console.WriteLine("Has Macros: " + workbook.HasMacro);
// Check if the workbook has any tracked changes
Console.WriteLine("Has Revisions: " + workbook.HasRevisions);
// Check the number of styles in the style pool
Console.WriteLine("Number of Styles in Pool: " + workbook.CountOfStylesInPool);
// Check the theme name
Console.WriteLine("Theme: " + workbook.Theme);
// Check if the workbook is protected with a password
Console.WriteLine("Is Workbook Protected With Password: " + workbook.IsWorkbookProtectedWithPassword);
// Check if the workbook contains external links
Console.WriteLine("Has External Links: " + workbook.HasExernalLinks());
// Dispose the workbook
workbook.Dispose();
}
}
}
See Also
- namespace Aspose.Cells
- assembly Aspose.Cells