[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IWorkbook

IWorkbook Interface

Defines workbook-level APIs for working with spreadsheets.

This interface defines the workbook-level API for working with spreadsheets, including managing worksheets, accessing the active sheet, configuring workbook settings, handling workbook events, and performing operations such as calculation, opening, and saving.

The Workbook class is the known public implementation of this interface.

Namespace: GrapeCity.Documents.Excel
Assembly: DS.Documents.Excel.dll
Syntax
public interface IWorkbook
Public Interface IWorkbook
Examples
IWorkbook workbook = new Workbook();
workbook.BuiltInDocumentProperties.Title = "Quarterly Sales";
workbook.Options.Formulas.EnableIterativeCalculation = true;
workbook.ActiveSheet.Range["A1"].Value = "Revenue";
IWorksheet worksheet = workbook.Worksheets[0];

Properties

Name Description
ActiveSheet

Returns the active worksheet in the workbook.

Returns the worksheet that is currently active in the workbook. Returns null if no worksheet is active.

AllowDynamicArray

Gets or sets whether dynamic array formulas are allowed for compatibility with Formula.

This property is obsolete. Dynamic array formulas should be defined by using Formula2 instead. This property is retained for compatibility with earlier versions that enabled dynamic array behavior together with Formula.

AutoParse

Gets or sets whether string values are automatically parsed when assigned to a range.

When this property is true, string values assigned with Value may be interpreted as numbers, date/time values, boolean values, error values, or empty cell values instead of being kept as plain text.

AutoRoundValue

Gets or sets whether numeric values are rounded to 15 significant digits when they are retrieved.

Use this property to determine whether the workbook applies automatic rounding when reading numeric cell values.

BookView

Returns the view settings of this workbook.

BuiltInDocumentProperties

Returns the collection of built-in document properties in the workbook.

The returned IBuiltInDocumentPropertyCollection provides access to built-in metadata such as author, title, subject, company, and other standard document properties.

Culture

Gets or sets the culture information of the workbook.

The returned culture affects culture-related features such as localized formatting and formula behavior. If no culture has been explicitly set, use the thread's current culture.

CustomDocumentProperties

Gets the collection of custom document properties in the workbook.

Use the returned ICustomDocumentPropertyCollection to add, remove, and retrieve workbook metadata defined by the application, such as string, numeric, Boolean, date, or linked-content properties.

CustomViews

Returns the custom views of the workbook.

CustomXmlParts

Gets the collection of Custom XML parts in the workbook.

Use the returned ICustomXmlPartCollection to add, retrieve, enumerate, or remove workbook-level Custom XML parts. Custom XML parts are stored in the OpenXML package as raw XML payloads and are preserved when saving to OpenXML workbook formats such as XLSX and XLSM.

This API stores and returns the XML bytes only. It does not validate the XML against a schema.

DefaultTableStyle

Gets or sets the table style name applied by default to newly created tables in the workbook.

Use this property to get or set the table style name that new tables use by default in the workbook.

DeferUpdateDirtyState

Gets or sets whether updates to the dirty states of dependent formulas affected by cell value changes are deferred.

When a cell value changes, dirty-state propagation normally runs immediately along the formula dependency chain. In scenarios with complex dependencies and frequent bulk value updates, this repeated propagation can introduce additional performance overhead.

When this property is set to true, value changes are queued and the dirty states of dependent formulas are not updated immediately. When this property is set back to false, the workbook processes the queued changes and updates the affected dirty states in a batch. Therefore, true and false must be used in pairs: each time this property is set to true, it must be set back to false after bulk updates are complete. Otherwise, features that rely on cached or delayed refresh results, such as charts, might still return stale values before the queued changes are processed.

This property is intended for bulk cell value updates and can improve performance by reducing repeated dependency analysis and dirty-state propagation. It is not recommended when Value get and set operations are interleaved.

EnableCalculation

Gets or sets whether the calculation engine is enabled for the workbook.

When this property is false, formulas in the current workbook are no longer recalculated. If formula results are retrieved while calculation is disabled, the last calculated results from before calculation was disabled are returned.

This property is intended for large batch updates of values or formulas when updated calculation results are not needed until the batch is complete. Set this property to false before the batch to improve performance, and set it back to true when you need to calculate the workbook again.

FullName

Gets the workbook name, including its full path.

This property returns the full workbook name composed from the workbook name and path information associated with this workbook.

GraphicsInfo

Gets or sets the graphics information used by the workbook.

If no graphics information has been assigned, the workbook uses built-in graphics information.

Use this property to provide custom digit-width measurement logic for workbook rendering and layout calculations. Set the property to null to use the built-in graphics information.

Name

Gets or sets the name of the workbook.

Names

Gets the collection of workbook-defined names.

Options

Returns the workbook options.

Path

Gets or sets the path of the workbook file represented by this workbook object.

Use this property to retrieve the path information associated with the current workbook. To get the workbook name together with its path, use FullName.

PivotCaches

Returns the IPivotCaches collection that contains all IPivotTable caches in the workbook.

Use this property to access existing PivotTable caches or create a new cache from source data before adding a PivotTable.

ProtectStructure

Returns a value indicating whether the workbook structure is protected.

When the workbook structure is protected, the order of worksheets cannot be changed until the protection is removed by using Unprotect(string).

ProtectWindows

Returns a value indicating whether the workbook windows are protected.

This property reflects the workbook window protection state set by Protect(bool, bool). When workbook windows are protected, the window layout cannot be modified until the protection is removed.

ReferenceStyle

Gets or sets the reference style used by the workbook.

The reference style determines how cell references are represented in formulas and addresses, such as A1 style references like A1 or R1C1 style references like R1C1.

ResetAdjacentRangeBorder

Gets or sets whether adjacent range borders are reset when a border is applied to a range.

The default value is true.

SelectedSheets

Returns the collection of selected worksheets in the workbook.

The returned IWorksheets object represents all worksheets that are currently selected.

SheetTabs

Returns the collection of sheet tabs contained in the workbook.

ShowPivotTableFieldList

Gets or sets a value indicating whether the PivotTable field list can be shown.

Use this property to determine whether users can display the PivotTable field list for PivotTables in the workbook. The default value is true.

Signatures

Returns the collection of digital signatures attached to the workbook.

The returned ISignatureSet provides access to the signatures in the document, including signature lines and non-visible signatures.

SlicerCaches

Returns the ISlicerCaches collection associated with the workbook.

Use this collection to access existing slicer caches in the workbook or to add new ones for supported data sources such as tables and PivotTables.

Styles

Returns the collection of styles in the current workbook.

This property returns an IStyleCollection that provides access to the built-in and custom styles available in the workbook.

TableStyles

Returns the ITableStyleCollection for the current workbook.

This collection contains the table styles available in the workbook, including built-in styles and any custom table styles added to it.

Theme

Gets or sets the theme associated with the workbook.

Worksheets

Returns the IWorksheets collection that represents all worksheets in the workbook.

This property returns the workbook-level worksheets collection. The property has a read-only getter; use the returned collection to access worksheets by index or name, and to manage worksheets in the workbook.

WriteProtection

Returns the workbook write protection options.

Methods

Name Description
AddDataSource(string, object)

Adds a data source for template processing.

Calculate()

Calculates formulas in the workbook as needed.

This method recalculates workbook formulas that require calculation. If iterative calculation is enabled, all formulas in the workbook are marked for recalculation before the calculation is performed.

ConvertBarcodeToPicture(ImageType)

Converts calculated barcode formulas to pictures.

The converted pictures are placed at the original barcode positions, and the original barcode formulas are cleared after the conversion.

Dirty()

Marks all formulas in the workbook as dirty so they are recalculated the next time calculation runs.

Use this method to invalidate cached formula results for the entire workbook. After calling this method, invoke Calculate(), or retrieve formula results while calculation is enabled, to trigger recalculation.

FromJson(Stream, DeserializationOptions)

Loads workbook content from a SpreadJS JSON (SSJSON) stream into this workbook.

Use this method to control deserialization behavior with a DeserializationOptions instance. The returned list contains any JsonError objects found during deserialization.

FromJson(string, DeserializationOptions)

Loads workbook content from a SpreadJS JSON (SSJSON) string into this workbook.

Use this method to control deserialization behavior with a DeserializationOptions instance. The returned list contains any JsonError objects found during deserialization.

FromSjsJson(Stream)

Generates a workbook from a JSON stream containing .sjs file content.

FromSjsJson(Stream, SjsOpenOptions)

Generates a workbook from a JSON stream containing .sjs file content.

FromSjsJson(string)

Generates a workbook from a JSON string containing .sjs file content.

FromSjsJson(string, SjsOpenOptions)

Generates a workbook from a JSON string containing .sjs file content.

GenerateReport()

Processes the template and returns a new report workbook instance.

Unlike ProcessTemplate(), this method generates the report in a new IWorkbook so the current template workbook can be retained for further use.

GenerateReport(params IWorksheet[])

Processes the template and returns a new report workbook that includes only the specified worksheets.

Use this method to generate a new IWorkbook from the current template workbook while limiting report generation to the provided worksheets.

GetExcelLinkSources()

Gets the names of linked Excel documents in the workbook.

GetUsedFonts()

Gets all font information used in the workbook.

This method returns a collection of FontInfo objects that describe the fonts currently used by workbook content and styles.

IsEncryptedFile(Stream)

Determines whether the specified file stream is password protected.

Use this method before opening a workbook stream to decide whether a password should be supplied to Open(Stream, string, OpenOptions).

IsEncryptedFile(string)

Determines whether the specified file is password protected.

Use this method to check whether a workbook file requires a password before opening it. If the file is encrypted, open it with Open(string, string, OpenOptions).

Open(Stream)

Opens the specified Excel file stream.

Use this method to load workbook data from a Stream.

Open(Stream, OpenFileFormat)

Opens the specified format file stream.

Open(Stream, OpenOptionsBase)

Opens the stream with specified options.

Open(Stream, string, OpenOptions)

Opens the specified excel file stream.

Open(string)

Opens a workbook file.

This method opens the specified file by using the default open options. The file type is inferred from the file name extension.

The fileName value is used directly as a file system path. Pass only validated paths from trusted sources.

Open(string, DeserializationOptions)

Opens the specified JSON file using the provided deserialization options.

Uses the provided DeserializationOptions to control how the JSON content is deserialized into the workbook.

Open(string, OpenFileFormat)

Opens a file using the specified file format.

Use this overload when the file format should be provided explicitly instead of being inferred from the file name.

Open(string, OpenOptionsBase)

Opens a file with the specified open options.

Use this overload to control how the workbook is loaded for supported file formats.

Open(string, string, OpenOptions)

Opens the specified Excel file with an optional password and open options.

Use this overload to open a password-protected workbook from the specified file path. You can also provide OpenOptions to control how the workbook is loaded.

This method is obsolete. Use Open(string, OpenOptionsBase) instead.

PrintOut(PrintOutOptions)

Prints the workbook.

ProcessTemplate()

Processes the workbook as a template by evaluating template fields and replacing them with data from the workbook's data sources.

Call this method after adding one or more data sources with AddDataSource(string, object).

ProcessTemplate(CancellationToken)

Processes the workbook as a template and observes cancellation requests through the specified cancellation token.

Use this method to process template data in the current workbook while allowing the operation to be canceled through a CancellationToken.

Protect(bool, bool)

Protects the workbook structure without a password by default.

When called without arguments, structure uses the default value true and windows uses the default value false, so workbook window protection is not enabled. This protection restricts workbook structure operations, such as adding, moving, deleting, hiding, unhiding, or renaming worksheets, in supported spreadsheet applications. It does not encrypt the workbook, provide content access control, or prevent changes made through the object model before saving.

Protect(string, bool, bool)

Protects a workbook so that it cannot be modified.

This protection only restricts workbook structure and window operations in supported spreadsheet applications. It does not encrypt workbook contents and should not be used as a confidentiality or access-control mechanism. To protect sensitive data, use file encryption such as password-protected XlsxSaveOptions or other access-control measures, and avoid storing unencrypted sensitive data in hidden worksheets.

Save(Stream)

Saves the workbook to the specified stream.

Save(Stream, SaveFileFormat)

Saves the workbook to a stream in the specified file format.

Save(Stream, SaveOptionsBase)

Saves workbook to stream with specified options.

Save(Stream, string, SaveOptions)

Saves the workbook to the specified stream.

Save(string)

Saves the workbook to disk.

Save(string, SaveFileFormat)

Saves the workbook to a file in the specified file format.

Save(string, SaveOptionsBase)

Saves the workbook to a file with the specified save options.

Save(string, string, SaveOptions)

Saves the workbook to the specified Excel file.

ToJson(SerializationOptions)

Generates a JSON string from the workbook by using the specified serialization options.

ToJson(Stream, SerializationOptions)

Serializes the workbook to JSON and writes the content to the specified stream.

ToSjsJson()

Generates a single JSON payload that represents the workbook in SpreadJS .sjs format.

ToSjsJson(SjsSaveOptions)

Generates a single JSON payload that represents the workbook in SpreadJS .sjs format, using the specified save options.

ToSjsJson(Stream)

Writes a JSON string that combines all JSON parts of the SpreadJS .sjs content for this workbook to the specified stream.

Use this method to export the workbook as a single SJS JSON payload through a Stream.

ToSjsJson(Stream, SjsSaveOptions)

Integrates all JSON files in the SpreadJS .sjs format into a single string and writes it to the specified stream.

Use SjsSaveOptions to control how workbook content is included when generating the SJS JSON output.

Unprotect(string)

Removes protection from the workbook.

Use this method to remove protection that was applied with Protect(string, bool, bool) or another non-password overload of protect. If the workbook was protected with a password, use Unprotect(string) with the correct password instead.

Updates the Excel link with the specified name.

Use this method to refresh a linked workbook reference identified by name. To obtain available link names, use GetExcelLinkSources().

Updates the specified Excel link by using the content from another workbook.

The name value should match the linked workbook name used in the external reference.

Updates all Excel links in the workbook.

Use this method to refresh the caches of external workbook links used by cross-workbook formulas.

WaitForCalculationToFinish()

Waits for all calculations in the workbook to finish.

This method blocks the current thread until all pending calculations, including asynchronous calculations, have completed. Call this method before performing operations that depend on calculated results.

Events

Name Description
AfterSave

Occurs after the workbook is saved.

BeforeSave

Occurs before the workbook is saved.

NewSheet

Occurs when a new sheet is created in the workbook.

Opened

Occurs when the workbook is opened.

SheetActivate

Occurs when a sheet is activate.

SheetBeforeDelete

Occurs before a sheet is deleted.

SheetChange

Occurs when something changes in the cells of a sheet.

SheetDeactivate

Occurs when a sheet is deactivated.

SheetSelectionChange

Occurs when the selection changes on a sheet.