[]
Represents the workbook class.
public sealed class Workbook : IWorkbook
Creates the workbook.
public Workbook()
Creates the workbook.
public Workbook(WorkbookOptions options)
options
WorkbookOptionsThe workbook options.
Creates the workbook.
public Workbook(string licenseKey, WorkbookOptions options)
licenseKey
stringThe license key.
options
WorkbookOptionsThe workbook options.
Creates the workbook.
public Workbook(string licenseKey)
licenseKey
stringThe license key.
Gets the active sheet.
public IWorksheet ActiveSheet { get; }
This api is obsolete, please use Formula2 to get or set dynamic array formula.
[Obsolete]
public bool AllowDynamicArray { get; set; }
Gets or sets the author.
public string Author { get; set; }
Determines whether to parse automatically when setting range value to string value.
public bool AutoParse { get; set; }
Determines whether to round the number to 15 significant figures when getting the value.
public bool AutoRoundValue { get; set; }
Returns an object that represents the view settings of this workbook(read-only).
public IWorkbookView BookView { get; }
Gets a collection that represents all the built-in document properties of the workbook.
public IBuiltInDocumentPropertyCollection BuiltInDocumentProperties { get; }
[Init-only] Gets or sets culture for the workbook. The culture must contain both country/region and language.
public CultureInfo Culture { get; set; }
This property must be set within the initialization expression of the workbook instance.
Gets a collection that represents all the custom document properties of the workbook.
public ICustomDocumentPropertyCollection CustomDocumentProperties { get; }
Gets the custom views of the workbook.
public ICustomViews CustomViews { get; }
Specifies the table style that is used as the default TableStyle.
public string DefaultTableStyle { get; set; }
Gets or sets whether update the dirty state of the formula cells immediately when changing the value of a cell.
public bool DeferUpdateDirtyState { get; set; }
Specifies whether the calculation engine is working.
public bool EnableCalculation { get; set; }
Gets or sets the location of font files that will be used when exporting pdf.
public static string FontsFolderPath { get; set; }
Returns the name of the workbook, including its path on disk.
public string FullName { get; }
Provides graphics information. If this property doesn't have value, the workbook will use built-in graphic information.
public IGraphicsInfo GraphicsInfo { get; set; }
Filters data in a workbook based on a cell icon from the IconSets collection. This property is read-only.
public IIconSets IconSets { get; }
Gets or sets the logger factory shared by all workbooks.
public static ILoggerFactory LoggerFactory { get; set; }
If the value is null (Nothing), workbooks will not print logs. Otherwise, workbooks will print logs with the specified Microsoft.Extensions.Logging.ILoggerFactory.
Get or set a string value that represents the name of the workbook.
public string Name { get; set; }
Returns the INames collection that represents the workbook-specified names. The Names object is read-only.
public INames Names { get; }
Returns the IExcelOptions object that represents some settings to control workbook behavior.
public IExcelOptions Options { get; }
Gets or sets a string that represents the path to the workbook file that this workbook object represents.
public string Path { get; set; }
Gets a PivotCaches collection that represents all the PivotTable caches in the specified workbook.
public IPivotCaches PivotCaches { get; }
True if the order of the sheets in the workbook is protected. Read-only Boolean.
public bool ProtectStructure { get; }
True if the windows of the workbook are protected. Read-only Boolean.
public bool ProtectWindows { get; }
Gets or sets the reference style.
public ReferenceStyle ReferenceStyle { get; set; }
The ReferenceStyle style.
Determines whether to reset adjacent range's border when setting border for a range. The default value of this property is true.
public bool ResetAdjacentRangeBorder { get; set; }
Returns a IWorksheets collection that represents all the selected sheets in the specified workbook.
public IWorksheets SelectedSheets { get; }
Gets a collection of Signature objects that correspond to the digital signature attached to a document.
public ISignatureSet Signatures { get; }
Gets the ISlicerCaches object associated with the workbook.
public ISlicerCaches SlicerCaches { get; }
Provides access to the collection of cell styles in the current workbook.
public IStyleCollection Styles { get; }
The styles.
Gets the table styles used in the current workbook.
public ITableStyleCollection TableStyles { get; }
Gets or sets the json serializer/deserializer for custom type.
public static IJsonSerializer TagJsonSerializer { get; set; }
Returns an instance of ITheme which provides access to the theme associated with a workbook.
public ITheme Theme { get; set; }
The theme.
Gets or sets the json serializer/deserializer for custom cell values
public static IJsonSerializer ValueJsonSerializer { get; set; }
The IJsonSerializer which will be used in all workbooks.
Be aware of thread safety and JSON element injection problems when you are implementing the IJsonSerializer.
Gets or sets the singleton instance of the IWebRequestHandler implementation that will be used to handle web requests. This property provides a centralized way to access and set the web request handler for the application.
public static IWebRequestHandler WebRequestHandler { get; set; }
Gets a collection of worksheets contained in the workbook.
public IWorksheets Worksheets { get; }
The worksheet.
Returns a WriteProtection object that provides access to the workbook write protection options.
public WriteProtection WriteProtection { get; }
Add custom function into the function set.
public static void AddCustomFunction(CustomFunction func, bool canOverride = false)
func
CustomFunctionthe custom function instance.
canOverride
boolcan override the exist function.
Add data source for template.
public void AddDataSource(string name, object dataSource)
name
stringthe alias name of the data source.
dataSource
objectCan be object of DataSet, DataTable, Custom object and variable.
Calculates formulas in the workbook as needed.
public void Calculate()
Convert the calculated barcodes to pictures and place them in their respective positions.
The original barcode formulas will be cleared.
Not support EMF and WMF image types.
public void ConvertBarcodeToPicture(ImageType imageType = ImageType.SVG)
Designates all the formulas of the workbook to be recalculated when the next calculation occurs.
public void Dirty()
Generates a workbook from a json stream.
public IList<JsonError> FromJson(Stream stream, DeserializationOptions deserializationOptions = null)
stream
System.IO.Streamthe stream
deserializationOptions
DeserializationOptionsthe DeserializationOptions object
The errors in the json
Generates a workbook from a json string.
public IList<JsonError> FromJson(string json, DeserializationOptions deserializationOptions = null)
json
stringThe json.
deserializationOptions
DeserializationOptionsThe DeserializationOptions object.
The errors in the json.
Generates a workbook from a JSON stream containing the contents of .sjs file format.
public void FromSjsJson(Stream stream, SjsOpenOptions openOptions)
stream
System.IO.StreamThe JSON stream.
openOptions
SjsOpenOptionsThe open options for opening SpreadJS .sjs file.
Generates a workbook from a JSON stream containing the contents of .sjs file format.
public void FromSjsJson(Stream stream)
stream
System.IO.StreamThe JSON stream.
Generates a workbook from a JSON string containing the contents of .sjs file format.
public void FromSjsJson(string json, SjsOpenOptions openOptions)
json
stringThe JSON string.
openOptions
SjsOpenOptionsThe open options for opening SpreadJS .sjs file.
Generates a workbook from a JSON string containing the contents of .sjs file format.
public void FromSjsJson(string json)
json
stringThe JSON string.
Process the template and return the instance of report workbook.
public IWorkbook GenerateReport()
Process the template and return the instance of report workbook.
public IWorkbook GenerateReport(params IWorksheet[] worksheets)
worksheets
IWorksheet[]IWorksheet collection that need to be processed.
Returns the names of the linked excel documents.
public IEnumerable<string> GetExcelLinkSources()
An enumerable collection of strings representing the Excel link sources.
Gets all sheet names and tables names that will be used as the parameter source of ImportData.
If the name is a table name, the worksheet name is qualified before the table name, such as "Sheet1!Table1".
public static string[] GetNames(Stream fileStream)
fileStream
System.IO.StreamThe fileStream of a workbook.
An array of possible import names.
Gets all sheet names and tables names that will be used as the parameter source of ImportData.
If the name is a table name, the worksheet name is qualified before the table name, such as "Sheet1!Table1".
public static string[] GetNames(string fileName)
fileName
stringThe path and name for the file.
An array of possible import names.
Gets all fonts information that are used on workbook.
public IEnumerable<FontInfo> GetUsedFonts()
Import the data of a specified range from a fileStream.
public static object[,] ImportData(Stream fileStream, string worksheetName, int row, int column, int rowCount, int columnCount)
fileStream
System.IO.StreamThe fileStream of a workbook.
worksheetName
stringThe name of the worksheet.
row
intThe first row of the range.
column
intThe first column of the range.
rowCount
intThe count of the rows.
columnCount
intThe count of the columns.
An array for the data.
Import all the data of the specified source of the file.
public static object[,] ImportData(Stream fileStream, string sourceName)
fileStream
System.IO.StreamThe fileStream of a workbook.
sourceName
stringThe name of the data source. The source name could be:
worksheet "Sheet1"
table "Sheet1!Table1"
range "Sheet1!A1:C5"
An array for the data.
Import the data of a specified range from a file.
public static object[,] ImportData(string fileName, string worksheetName, int row, int column, int rowCount, int columnCount)
fileName
stringThe path and name for the file.
worksheetName
stringThe name of the worksheet.
row
intThe first row of the range.
column
intThe first column of the range.
rowCount
intThe count of the rows.
columnCount
intThe count of the columns.
An array for the data.
Import all the data of the specified source of the file.
public static object[,] ImportData(string fileName, string sourceName)
fileName
stringThe path and name for the file.
sourceName
stringThe name of the data source. The source name could be:
worksheet "Sheet1"
table "Sheet1!Table1"
range "Sheet1!A1:C5"
An array for the data.
Specifies whether the file is password protected.
public bool IsEncryptedFile(Stream fileStream)
fileStream
System.IO.StreamThe file stream.
True if the file is encrypted, false otherwise.
Specifies whether the file is password protected.
public bool IsEncryptedFile(string fileName)
fileName
stringThe file name.
True if the file is encrypted, false otherwise.
Opens the stream with specified file format.
public void Open(Stream fileStream, OpenFileFormat fileFormat)
fileStream
System.IO.StreamThe specified file stream.
fileFormat
OpenFileFormatThe format of the file stream.
Opens the stream with specified options.
public void Open(Stream fileStream, OpenOptionsBase options)
fileStream
System.IO.StreamThe file stream.
options
OpenOptionsBaseThe format of opening the file stream. Possible types:
Opens the specified excel file stream.
[Obsolete]
public void Open(Stream fileStream, string password = null, OpenOptions openOptions = null)
fileStream
System.IO.StreamThe file stream.
password
stringThe password of the file.
openOptions
OpenOptionsOptions for opening.
Opens the file stream.
public void Open(Stream fileStream)
fileStream
System.IO.StreamThe specified file stream.
Opens the json file.
public IList<JsonError> Open(string fileName, DeserializationOptions deserializationOptions)
fileName
stringThe specified json file.
deserializationOptions
DeserializationOptionsThe json deserialization options.
The error list of the JSON
Opens the file with specified file format.
public void Open(string fileName, OpenFileFormat fileFormat)
fileName
stringThe specified file.
fileFormat
OpenFileFormatThe format of the file.
Opens the file with specified options.
public void Open(string fileName, OpenOptionsBase options)
fileName
stringThe excel file.
options
OpenOptionsBaseThe options of opening the file. Possible types:
Opens the specified excel file
[Obsolete]
public void Open(string fileName, string password = null, OpenOptions openOptions = null)
fileName
stringThe excel file.
password
stringThe password of the file.
openOptions
OpenOptionsOptions for opening.
Opens the file with default options. The file type is inferred from file extension.
public void Open(string fileName)
fileName
stringThe specified file.
Prints the workbook.
public void PrintOut(PrintOutOptions options = null)
options
PrintOutOptionsOptions for printing the workbook.
Start to process the template with global options.
public void ProcessTemplate()
Start to process the template with global options and cancellation support.
public void ProcessTemplate(CancellationToken cancellationToken)
cancellationToken
System.Threading.CancellationTokenThe token to monitor for cancellation requests.
The caller must decide whether to accept the partially expanded template or revert to the previous state. If the caller needs to revert to the previous state, it must serialize the workbook before calling this method, then deserialize the workbook after canceling the operation.
Throws when the System.Threading.CancellationToken was canceled.
Protects a workbook so that it cannot be modified.
public void Protect(bool structure = true, bool windows = false)
structure
boolTrue to protect the structure of the workbook (To prevent other users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets, and renaming worksheets).
windows
boolTrue to prevent users from moving, resizing, or closing the workbook window, or hide/unhide windows. This option is available only in Excel 2007, Excel 2010, Excel for Mac 2011, and Excel 2016 for Mac.
Protects a workbook so that it cannot be modified.
public void Protect(string password, bool structure = true, bool windows = false)
password
stringPassword to protect the workbook.
structure
boolTrue to protect the structure of the workbook (To prevent other users from viewing hidden worksheets, adding, moving, deleting, or hiding worksheets, and renaming worksheets).
windows
boolTrue to prevent users from moving, resizing, or closing the workbook window, or hide/unhide windows. This option is available only in Excel 2007, Excel 2010, Excel for Mac 2011, and Excel 2016 for Mac.
Saves workbook to stream with specified file format.
public void Save(Stream fileStream, SaveFileFormat fileFormat)
fileStream
System.IO.StreamThe specified file stream.
fileFormat
SaveFileFormatThe format of the file stream.
Saves workbook to stream with specified options.
public void Save(Stream fileStream, SaveOptionsBase options)
fileStream
System.IO.StreamThe specified file stream.
options
SaveOptionsBaseThe options of saving the file stream. Possible types:
Saves workbook to the specified excel file stream.
[Obsolete]
public void Save(Stream fileStream, string password = null, SaveOptions saveOptions = null)
fileStream
System.IO.StreamThe file stream.
password
stringThe password of the file.
saveOptions
SaveOptionsOptions for saving
Saves the workbook to the stream.
public void Save(Stream fileStream)
fileStream
System.IO.StreamThe file stream.
Saves workbook to file with specified file format.
public void Save(string fileName, SaveFileFormat fileFormat)
fileName
stringThe specified file.
fileFormat
SaveFileFormatThe format of the file.
Saves workbook to file with specified options.
public void Save(string fileName, SaveOptionsBase options)
fileName
stringThe specified file.
options
SaveOptionsBaseThe options of saving the file. Possible types:
Saves data to the specified excel file.
[Obsolete]
public void Save(string fileName, string password = null, SaveOptions saveOptions = null)
fileName
stringThe excel file.
password
stringThe password of the file.
saveOptions
SaveOptionsOptions for saving
Saves the workbook to the disk.
public void Save(string fileName)
fileName
stringThe file name.
Set the license key of Documents for Excel.
public static void SetLicenseKey(string key)
key
stringThe license key.
Generates a json string from a workbook.
public string ToJson(SerializationOptions serializationOptions = null)
serializationOptions
SerializationOptionsThe SerializationOptions object.
The json string.
Generates a json stream from a workbook.
public void ToJson(Stream stream, SerializationOptions serializationOptions = null)
stream
System.IO.StreamThe json stream.
serializationOptions
SerializationOptionsThe SerializationOptions object.
Generates a JSON string from a workbook. It integrates all JSON files from the SpreadJS .sjs file into a single string.
public string ToSjsJson()
Json data.
Generates a JSON string from a workbook. It integrates all JSON files from the SpreadJS .sjs file into a single string.
public string ToSjsJson(SjsSaveOptions options)
options
SjsSaveOptionsOption for saving SpreadJS .sjs file.
Json data.
Integrates all JSON files from the SpreadJS .sjs file into a single string, then put the string into the stream.
public void ToSjsJson(Stream stream, SjsSaveOptions options)
stream
System.IO.StreamThe specified file stream.
options
SjsSaveOptionsOption for opening SpreadJS .sjs file.
Integrates all JSON files from the SpreadJS .sjs file into a single string, then put the string into the stream.
public void ToSjsJson(Stream stream)
stream
System.IO.StreamThe specified file stream.
Removes protection from the workbook.
public void Unprotect(string password = null)
password
stringPassword to protect the workbook.
Updates a excel link.
public void UpdateExcelLink(string name, IWorkbook sourceWorkbook)
name
stringthe link name
sourceWorkbook
IWorkbookthe workbook instance for the link
Updates a excel link.
public void UpdateExcelLink(string name)
name
stringUpdates all the excel links.
public void UpdateExcelLinks()
Waits for all calculation to complete, includes asynchronous calculations. This method blocks the current thread until all calculations have finished. Users can call this method to ensure that all necessary computations have been performed before proceeding with any other operations that depend on the calculation results.
public void WaitForCalculationToFinish()
Occurs after the workbook is saved.
public event EventHandler AfterSave
Occurs before the workbook is saved.
public event EventHandler BeforeSave
Occurs when a new sheet is created in the workbook.
public event EventHandler<SheetEventArgs> NewSheet
Occurs when the workbook is opened.
public event EventHandler Opened
Occurs when a sheet is active.
public event EventHandler<SheetEventArgs> SheetActivate
Occurs before a sheet is deleted.
public event EventHandler<SheetEventArgs> SheetBeforeDelete
Occurs when something changes in the cells of a sheet.
public event EventHandler<RangeEventArgs> SheetChange
Occurs when a sheet is deactivated.
public event EventHandler<SheetEventArgs> SheetDeactivate
Occurs when the selection changes on a sheet.
public event EventHandler<RangeEventArgs> SheetSelectionChange