- 5 minutes to read
The Workbook class provides the means to create, load, edit, save and print spreadsheet documents in code. Add the DevExpress.Docs.v20.1.dll assembly to your project to use the workbook functionality.
The example below shows how to create a Workbook instance.
using DevExpress.Spreadsheet; // ... // Create a new workbook. Workbook workbook = new Workbook();
Performance Optimization Tips:
When you finish working with the document, call the Workbook.Dispose method to release all the resources used by the object. This action helps you avoid memory leaks and speed up system performance. You can also modify a Workbook within the using statement (Using block in Visual Basic).
Worksheets and Chart Sheets
A workbook consists of one or more worksheets stored in the Workbook.Worksheets collection. When you create a workbook, it contains an empty worksheet. Use the WorksheetCollection members to add a new worksheet, remove an existing worksheet, rename a worksheet, select an active worksheet, and so on.
The Workbook.Sheets collection stores all sheets (worksheets and chart sheets) in a workbook. Use this collection to obtain a sheet of any type.
Built-in and Custom Functions
You can include functions in your formulas to perform calculations. Use the Workbook.Functions property to access the WorkbookFunctions object that stores all built-in functions and allows you to override any function via the WorkbookFunctions.OverrideFunction method.
You can also create a custom function. To add a custom function to a workbook, define a class that implements the ICustomFunction interface and add its instance to the Workbook.CustomFunctions or Workbook.GlobalCustomFunctions collection.
Custom functions are not saved. To replace custom function definitions with calculated values when a workbook is saved, set the WorkbookExportOptions.CustomFunctionExportMode option to CalculatedValue.
Table and Pivot Table Styles
The Workbook.TableStyles collection stores styles you can apply to tables and pivot tables. You can select a built-in style or create a custom style.
Custom XML Parts
You can embed arbitrary XML data in workbooks in Excel file formats. This data is named custom XML parts and stored in the Workbook.CustomXmlParts collection. Use the collection's members to create and modify custom XML parts.
Operations with Workbooks
The following table lists operations you can perform on a workbook.
Create a new document
Load a workbook
Save a workbook
Protect a workbook
Encrypt a workbook
Print a workbook
Trace the history of changes
View and edit document properties
Use the Workbook.Options property to access various document options. They include:
Specifies options used to import documents in different file formats.
Specifies options used to export documents to different file formats.
Defines the file name and file format used when a workbook is saved.
Specifies options for worksheet cells.
Contains options that allow you to control copy operations.
Provides culture-specific settings.
Provides access to the WorkbookEventOptions.RaiseOnModificationsViaAPI option that enables you to raise events for changes performed via the API.
Specifies the calculation mode for a Workbook object. The default mode is Manual. Call the Workbook.Calculate, Worksheet.Calculate, or CellRange.Calculate method to calculate formulas in the document.
Specifies the computational model used to perform calculations in a workbook.
Provides access to options for real-time data (RTD) function calculation.
Provides access to the SpreadsheetDataSourceLoadingOptions.CustomAssemblyBehavior option that specifies whether to load a custom assembly with the Entity Framework data context during mail merge.
Provides access to the following compatibility settings:
Specifies whether to apply the WorksheetView.Zoom setting to all worksheet views or the current view only.
Other workbook settings are available from the Workbook.DocumentSettings property.
Provides access to formula calculation options.
Specifies whether a workbook should use the R1C1 reference style.
Provides access to document encryption options.
Specifies whether to show the Field List for pivot tables in a workbook.
Appends all worksheets from the specified workbooks to the current workbook.
Creates a workbook's copy.