Class Workbook
Namespace: Aspose.Cells
Assembly: Aspose.Cells.dll (25.2.0)
Represents a root object to create an Excel spreadsheet.
public class Workbook : IDisposable
Inheritance
Implements
Inherited Members
object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Examples
The following example loads a Workbook from an Excel file named designer.xls and makes the horizontal and vertical scroll bars invisible. It then replaces two string values with an Integer value and string value respectively within the spreadsheet and finally save the workbook as Excel xlsx file.
//Open a designer file
string designerFile = "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);
workbook.Save("result.xlsx");
'Open a designer file
Dim designerFile as String = "\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)
workbook.Save("result.xlsx")
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.
Constructors
Workbook()
Initializes a new instance of the Aspose.Cells.Workbook class.
public Workbook()
Examples
The following code shows how to use the Workbook constructor to create and initialize a new instance of the class.
Workbook workbook = new Workbook();
Dim workbook as Workbook = new Workbook()
Remarks
The default file format type is Xlsx. If you want to create other types of files, please use Workbook(FileFormatType).
Workbook(FileFormatType)
Initializes a new instance of the Aspose.Cells.Workbook class.
public Workbook(FileFormatType fileFormatType)
Parameters
fileFormatType
FileFormatType
The new file format.
Examples
The following code shows how to use the Workbook constructor to create and initialize a new instance of the class with various file format type.
Workbook workbook = new Workbook(FileFormatType.Xlsx);
Dim workbook as Workbook = new Workbook(FileFormatType.Xlsx)
Remarks
The default file format type is Excel97To2003.
Workbook(string)
Initializes a new instance of the Aspose.Cells.Workbook class and open a file.
public Workbook(string file)
Parameters
file
string
The file name.
Workbook(Stream)
Initializes a new instance of the Aspose.Cells.Workbook class and open a stream.
public Workbook(Stream stream)
Parameters
stream
Stream
The stream.
Workbook(string, LoadOptions)
Initializes a new instance of the Aspose.Cells.Workbook class and open a file.
public Workbook(string file, LoadOptions loadOptions)
Parameters
file
string
The file name.
loadOptions
LoadOptions
The load options
Workbook(Stream, LoadOptions)
Initializes a new instance of the Aspose.Cells.Workbook class and open stream.
public Workbook(Stream stream, LoadOptions loadOptions)
Parameters
stream
Stream
The stream.
loadOptions
LoadOptions
The load options
Properties
AbsolutePath
Gets and sets the absolute path of the file.
public string AbsolutePath { get; set; }
Property Value
Remarks
Only used for external links.
BuiltInDocumentProperties
Returns a Aspose.Cells.Properties.DocumentProperty collection that represents all the built-in document properties of the spreadsheet.
public BuiltInDocumentPropertyCollection BuiltInDocumentProperties { get; }
Property Value
BuiltInDocumentPropertyCollection
Examples
Workbook workbook = new Workbook();
DocumentProperty doc = workbook.BuiltInDocumentProperties["Author"];
doc.Value = "John Smith";
Dim workbook as Workbook = New Workbook()
Dim doc as DocumentProperty = workbook.BuiltInDocumentProperties("Author")
doc.Value = "John Smith"
Remarks
A new property cannot be added to built-in document properties list. You can only get a built-in property and change its value. The following is the built-in properties name list:
Title
Subject
Author
Keywords
Comments
Template
Last Author
Revision Number
Application Name
Last Print Date
Creation Date
Last Save Time
Total Editing Time
Number of Pages
Number of Words
Number of Characters
Security
Category
Format
Manager
Company
Number of Bytes
Number of Lines
Number of Paragraphs
Number of Slides
Number of Notes
Number of Hidden Slides
Number of Multimedia Clips
CellsDataTableFactory
Gets the factory for building ICellsDataTable from custom objects
public CellsDataTableFactory CellsDataTableFactory { get; }
Property Value
Colors
Returns colors in the palette for the spreadsheet.
public Color[] Colors { get; }
Property Value
Color[]
Remarks
The palette has 56 entries, each represented by an RGB value.
ContentTypeProperties
Gets the list of Aspose.Cells.Properties.ContentTypeProperty objects in the workbook.
public ContentTypePropertyCollection ContentTypeProperties { get; }
Property Value
CountOfStylesInPool
Gets number of the styles in the style pool.
public int CountOfStylesInPool { get; }
Property Value
CustomDocumentProperties
Returns a Aspose.Cells.Properties.DocumentProperty collection that represents all the custom document properties of the spreadsheet.
public CustomDocumentPropertyCollection CustomDocumentProperties { get; }
Property Value
CustomDocumentPropertyCollection
Examples
Workbook excel = new Workbook();
excel.CustomDocumentProperties.Add("Checked by", "Jane");
Dim excel as Workbook = New Workbook()
excel.CustomDocumentProperties.Add("Checked by", "Jane")
CustomXmlParts
Represents a Custom XML Data Storage Part (custom XML data within a package).
public CustomXmlPartCollection CustomXmlParts { get; }
Property Value
DataConnections
Gets the Aspose.Cells.ExternalConnections.ExternalConnection collection.
public ExternalConnectionCollection DataConnections { get; }
Property Value
DataMashup
Gets mashup data.
public DataMashup DataMashup { get; }
Property Value
DataModel
Gets data model in the workbook.
public DataModel DataModel { get; }
Property Value
DataSorter
Gets a DataSorter object to sort data.
public DataSorter DataSorter { get; }
Property Value
DefaultStyle
Gets or sets the default Aspose.Cells.Style object of the workbook.
public Style DefaultStyle { get; set; }
Property Value
Examples
The following code creates and instantiates a new Workbook and sets a default Aspose.Cells.Style to it.
Workbook workbook = new Workbook();
Style defaultStyle = workbook.DefaultStyle;
defaultStyle.Font.Name = "Tahoma";
workbook.DefaultStyle = defaultStyle;
Dim workbook as Workbook = new Workbook()
Dim defaultStyle as Style = workbook.DefaultStyle
defaultStyle.Font.Name = "Tahoma"
workbook.DefaultStyle = defaultStyle
Remarks
The DefaultStyle property is useful to implement a Style for the whole Workbook.
FileFormat
Gets and sets the file format.
public FileFormatType FileFormat { get; set; }
Property Value
FileName
Gets and sets the current file name.
public string FileName { get; set; }
Property Value
Remarks
If the file is opened by stream and there are some external formula references, please set the file name.
HasMacro
Indicates if this spreadsheet contains macro/VBA.
public bool HasMacro { get; }
Property Value
HasRevisions
Gets if the workbook has any tracked changes
public bool HasRevisions { get; }
Property Value
InterruptMonitor
Gets and sets the interrupt monitor.
public AbstractInterruptMonitor InterruptMonitor { get; set; }
Property Value
IsDigitallySigned
Indicates if this spreadsheet is digitally signed.
public bool IsDigitallySigned { get; }
Property Value
IsLicensed
Indicates whether license is set.
public bool IsLicensed { get; }
Property Value
IsWorkbookProtectedWithPassword
Indicates whether structure or window is protected with password.
public bool IsWorkbookProtectedWithPassword { get; }
Property Value
RibbonXml
Gets and sets the XML file that defines the Ribbon UI.
public string RibbonXml { get; set; }
Property Value
Settings
Represents the workbook settings.
public WorkbookSettings Settings { get; }
Property Value
Theme
Gets the theme name.
public string Theme { get; }
Property Value
VbaProject
Gets the Aspose.Cells.Workbook.VbaProject in a spreadsheet.
public VbaProject VbaProject { get; }
Property Value
Worksheets
Gets the Aspose.Cells.WorksheetCollection collection in the spreadsheet.
public WorksheetCollection Worksheets { get; }
Property Value
Methods
AcceptAllRevisions()
Accepts all tracked changes in the workbook.
public void AcceptAllRevisions()
AddDigitalSignature(DigitalSignatureCollection)
Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
public void AddDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)
Parameters
digitalSignatureCollection
DigitalSignatureCollection
Remarks
Only support adding Xmldsig Digital Signature to an OOXML spreadsheet file
CalculateFormula()
Calculates the result of formulas.
public void CalculateFormula()
Remarks
For all supported formulas, please see the list at https://docs.aspose.com/display/cellsnet/Supported+Formula+Functions
CalculateFormula(bool)
Calculates the result of formulas.
public void CalculateFormula(bool ignoreError)
Parameters
ignoreError
bool
Indicates if hide the error in calculating formulas. The error may be unsupported function, external links, etc.
CalculateFormula(CalculationOptions)
Calculating formulas in this workbook.
public void CalculateFormula(CalculationOptions options)
Parameters
options
CalculationOptions
Options for calculation
ChangePalette(Color, int)
Changes the palette for the spreadsheet in the specified index.
public void ChangePalette(Color color, int index)
Parameters
color
Color
Color structure.
index
int
Palette index, 0 - 55.
Remarks
The palette has 56 entries, each represented by an RGB value.
If you set a color which is not in the palette, it will not take effect.
So if you want to set a custom color, please change the palette at first.
The following is the standard color palette.
Color | Red | Green | Blue |
---|---|---|---|
Black | 0 | 0 | 0 |
White | 255 | 255 | 255 |
Red | 255 | 0 | 0 |
Lime | 0 | 255 | 0 |
Blue | 0 | 0 | 255 |
Yellow | 255 | 255 | 0 |
Magenta | 255 | 0 | 255 |
Cyan | 0 | 255 | 255 |
Maroon | 128 | 0 | 0 |
Green | 0 | 128 | 0 |
Navy | 0 | 0 | 128 |
Olive | 128 | 128 | 0 |
Purple | 128 | 0 | 128 |
Teal | 0 | 128 | 128 |
Silver | 192 | 192 | 192 |
Gray | 128 | 128 | 128 |
Color17 | 153 | 153 | 255 |
Color18 | 153 | 51 | 102 |
Color19 | 255 | 255 | 204 |
Color20 | 204 | 255 | 255 |
Color21 | 102 | 0 | 102 |
Color22 | 255 | 128 | 128 |
Color23 | 0 | 102 | 204 |
Color24 | 204 | 204 | 255 |
Color25 | 0 | 0 | 128 |
Color26 | 255 | 0 | 255 |
Color27 | 255 | 255 | 0 |
Color28 | 0 | 255 | 255 |
Color29 | 128 | 0 | 128 |
Color30 | 128 | 0 | 0 |
Color31 | 0 | 128 | 128 |
Color32 | 0 | 0 | 255 |
Color33 | 0 | 204 | 255 |
Color34 | 204 | 255 | 255 |
Color35 | 204 | 255 | 204 |
Color36 | 255 | 255 | 153 |
Color37 | 153 | 204 | 255 |
Color38 | 255 | 153 | 204 |
Color39 | 204 | 153 | 255 |
Color40 | 255 | 204 | 153 |
Color41 | 51 | 102 | 255 |
Color42 | 51 | 204 | 204 |
Color43 | 153 | 204 | 0 |
Color44 | 255 | 204 | 0 |
Color45 | 255 | 153 | 0 |
Color46 | 255 | 102 | 0 |
Color47 | 102 | 102 | 153 |
Color48 | 150 | 150 | 150 |
Color49 | 0 | 51 | 102 |
Color50 | 51 | 153 | 102 |
Color51 | 0 | 51 | 0 |
Color52 | 51 | 51 | 0 |
Color53 | 153 | 51 | 0 |
Color54 | 153 | 51 | 102 |
Color55 | 51 | 51 | 153 |
Color56 | 51 | 51 | 51 |
CloseAccessCache(AccessCacheOptions)
Closes the session that uses caches to access data.
public void CloseAccessCache(AccessCacheOptions opts)
Parameters
opts
AccessCacheOptions
options of data access
Combine(Workbook)
Combines another Workbook object.
public void Combine(Workbook secondWorkbook)
Parameters
secondWorkbook
Workbook
Another Workbook object.
Remarks
Merge Excel, ODS , CSV and other files to one file.
Copy(Workbook, CopyOptions)
Copies another Workbook object.
public void Copy(Workbook source, CopyOptions copyOptions)
Parameters
source
Workbook
Source Workbook object.
copyOptions
CopyOptions
The options of copying other workbook.
Remarks
It’s very simple to clone an Excel file.
Copy(Workbook)
Copies data from a source Workbook object.
public void Copy(Workbook source)
Parameters
source
Workbook
Source Workbook object.
CopyTheme(Workbook)
Copies the theme from another workbook.
public void CopyTheme(Workbook source)
Parameters
source
Workbook
Source workbook.
CreateBuiltinStyle(BuiltinStyleType)
Creates built-in style by given type.
public Style CreateBuiltinStyle(BuiltinStyleType type)
Parameters
type
BuiltinStyleType
The builtin style stype.
Returns
Aspose.Cells.Style object
CreateCellsColor()
Creates a Aspose.Cells.CellsColor object.
public CellsColor CreateCellsColor()
Returns
Returns a Aspose.Cells.CellsColor object.
CreateStyle()
Creates a new style.
public Style CreateStyle()
Returns
Returns a style object.
CreateStyle(bool)
Creates a new style.
public Style CreateStyle(bool cloneDefaultStyle)
Parameters
cloneDefaultStyle
bool
Incidates whether clones the default style
Returns
Returns a style object.
CustomTheme(string, Color[])
Customs the theme.
public void CustomTheme(string themeName, Color[] colors)
Parameters
themeName
string
The theme name
colors
Color[]
The theme colors
Remarks
The length of colors should be 12.
Array index | Theme type |
---|---|
0 | Backgournd1 |
1 | Text1 |
2 | Backgournd2 |
3 | Text2 |
4 | Accent1 |
5 | Accent2 |
6 | Accent3 |
7 | Accent4 |
8 | Accent5 |
9 | Accent6 |
10 | Hyperlink |
11 | Followed Hyperlink |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
ExportXml(string, string)
Export XML data linked by the specified XML map.
public void ExportXml(string mapName, string path)
Parameters
mapName
string
name of the XML map that need to be exported
path
string
the export path
Examples
The following code exported the data linked by the first XmlMap.
csharp
Workbook wb = new Workbook("Book1.xlsx");
//Make sure that the source xlsx file contains a XmlMap.
XmlMap xmlMap = wb.Worksheets.XmlMaps[0];
wb.ExportXml(xmlMap.Name, "output.xml");
ExportXml(string, Stream)
Export XML data.
public void ExportXml(string mapName, Stream stream)
Parameters
mapName
string
name of the XML map that need to be exported
stream
Stream
the export stream
GetDigitalSignature()
Gets digital signature from file.
public DigitalSignatureCollection GetDigitalSignature()
Returns
GetFonts()
Gets all fonts in the style pool.
public Font[] GetFonts()
Returns
Font[]
GetMatchingColor(Color)
Find best matching Color in current palette.
public Color GetMatchingColor(Color rawColor)
Parameters
rawColor
Color
Raw color.
Returns
Best matching color.
GetNamedStyle(string)
Gets the named style in the style pool.
public Style GetNamedStyle(string name)
Parameters
name
string
name of the style
Returns
named style, maybe null.
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.
public Style GetStyleInPool(int index)
Parameters
index
int
The index.
Returns
The style in the pool corresponds to given index, may be null.
Remarks
If the returned style is changed, the style of all cells(which refers to this style) will be changed.
GetThemeColor(ThemeColorType)
Gets theme color.
public Color GetThemeColor(ThemeColorType type)
Parameters
type
ThemeColorType
The theme color type.
Returns
The theme color.
ImportXml(string, string, int, int)
Imports/Updates an XML data file into the workbook.
public void ImportXml(string url, string sheetName, int row, int col)
Parameters
url
string
the url/path of the xml file.
sheetName
string
the destination sheet name.
row
int
the destination row
col
int
the destination column
Examples
The following code imports xml data into worksheet ‘Sheet 1’ at Cell A1.
csharp
Workbook wb = new Workbook("Book1.xlsx");
wb.ImportXml("xml.xml", "Sheet1", 0, 0);
wb.Save("output.xlsx");
ImportXml(Stream, string, int, int)
Imports/Updates an XML data file into the workbook.
public void ImportXml(Stream stream, string sheetName, int row, int col)
Parameters
stream
Stream
the xml file stream.
sheetName
string
the destination sheet name.
row
int
the destination row.
col
int
the destination column.
IsColorInPalette(Color)
Checks if a color is in the palette for the spreadsheet.
public bool IsColorInPalette(Color color)
Parameters
color
Color
Color structure.
Returns
Returns true if this color is in the palette. Otherwise, returns false
ParseFormulas(bool)
Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.
public void ParseFormulas(bool ignoreError)
Parameters
ignoreError
bool
Whether ignore error for invalid formula. For one invalid formula, if ignore error then this formula will be ignored and the process will continue to parse other formulas, otherwise exception will be thrown.
Protect(ProtectionType, string)
Protects a workbook.
public void Protect(ProtectionType protectionType, string password)
Parameters
protectionType
ProtectionType
Protection type.
password
string
Password to protect the workbook.
ProtectSharedWorkbook(string)
Protects a shared workbook.
public void ProtectSharedWorkbook(string password)
Parameters
password
string
Password to protect the 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.
public void RefreshDynamicArrayFormulas(bool calculate)
Parameters
calculate
bool
Whether calculates and updates cell values for those dynamic array formulas
RefreshDynamicArrayFormulas(bool, CalculationOptions)
Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data)
public void RefreshDynamicArrayFormulas(bool calculate, CalculationOptions copts)
Parameters
calculate
bool
Whether calculates and updates cell values for those dynamic array formulas
copts
CalculationOptions
The options for calculating formulas
Remarks
For performance consideration, we do not refresh all dynamic array formulas automatically
when the formula itself or the data it references to changed.
So user need to call this method manually after those operations which may influence dynamic array formulas,
such as importing/setting cell values, inserting/deleting rows/columns/ranges, …etc.
For most formulas with functions, calculating the spill range also needs to calculating the formula,
so in general true value for “calculate” flag is preferred.
If the formula is simple, such as a range reference or array(for example “=C1:E5”, “={1,2;3,4}”, …),
simple function on a range or array(for example “=ABS(C1:E5)”, “=1+{1,2;3,4}”, …),
and all formulas will be calculated later(such as by Aspose.Cells.Workbook.CalculateFormula(Aspose.Cells.CalculationOptions)),
then using false vlaue for “calculate” flag may avoid the duplicated calculation for the benefit of performance.
RemoveDigitalSignature()
Removes digital signature from this spreadsheet.
public void RemoveDigitalSignature()
RemoveMacro()
Removes VBA/macro from this spreadsheet.
public void RemoveMacro()
RemovePersonalInformation()
Removes personal information.
public void RemovePersonalInformation()
RemoveUnusedStyles()
Remove all unused styles.
public void RemoveUnusedStyles()
Replace(string, string)
Replaces a cell’s value with a new string.
public int Replace(string placeHolder, string newValue)
Parameters
placeHolder
string
Cell placeholder
newValue
string
String value to replace
Returns
Examples
Workbook workbook = new Workbook();
//......
workbook.Replace("AnOldValue", "NewValue");
Dim workbook As Workbook = New Workbook()
'........
workbook.Replace("AnOldValue", "NewValue")
Replace(string, int)
Replaces a cell’s value with a new integer.
public int Replace(string placeHolder, int newValue)
Parameters
placeHolder
string
Cell placeholder
newValue
int
Integer value to replace
Returns
Examples
Workbook workbook = new Workbook();
//......
int newValue = 100;
workbook.Replace("AnOldValue", newValue);
Dim workbook As Workbook = New Workbook()
'.........
Dim NewValue As Integer = 100
workbook.Replace("AnOldValue", NewValue)
Replace(string, double)
Replaces a cell’s value with a new double.
public int Replace(string placeHolder, double newValue)
Parameters
placeHolder
string
Cell placeholder
newValue
double
Double value to replace
Returns
Examples
Workbook workbook = new Workbook();
//......
double newValue = 100.0;
workbook.Replace("AnOldValue", newValue);
Dim workbook As Workbook = New Workbook()
'.........
Dim NewValue As Double = 100.0
workbook.Replace("AnOldValue", NewValue)
Replace(string, string[], bool)
Replaces a cell’s value with a new string array.
public int Replace(string placeHolder, string[] newValues, bool isVertical)
Parameters
placeHolder
string
Cell placeholder
newValues
string[]
String array to replace
isVertical
bool
True - Vertical, False - Horizontal
Returns
Examples
Workbook workbook = new Workbook();
//......
string[] newValues = new string[]{"Tom", "Alice", "Jerry"};
workbook.Replace("AnOldValue", newValues, true);
Dim workbook As Workbook = New Workbook()
'.............
Dim NewValues() As String = New String() {"Tom", "Alice", "Jerry"}
workbook.Replace("AnOldValue", NewValues, True)
Replace(string, int[], bool)
Replaces cells’ values with an integer array.
public int Replace(string placeHolder, int[] newValues, bool isVertical)
Parameters
placeHolder
string
Cell placeholder
newValues
int[]
Integer array to replace
isVertical
bool
True - Vertical, False - Horizontal
Returns
Examples
Workbook workbook = new Workbook();
//......
int[] newValues = new int[]{1, 2, 3};
workbook.Replace("AnOldValue", newValues, true);
Dim workbook As Workbook = New Workbook()
'...........
Dim NewValues() As Integer = New Integer() {1, 2, 3}
workbook.Replace("AnOldValue", NewValues, True)
Replace(string, double[], bool)
Replaces cells’ values with a double array.
public int Replace(string placeHolder, double[] newValues, bool isVertical)
Parameters
placeHolder
string
Cell placeholder
newValues
double[]
Double array to replace
isVertical
bool
True - Vertical, False - Horizontal
Returns
Examples
Workbook workbook = new Workbook();
//......
double[] newValues = new double[]{1.23, 2.56, 3.14159};
workbook.Replace("AnOldValue", newValues, true);
Dim workbook As Workbook = New Workbook()
'...........
Dim NewValues() As Double = New Double() {1.23, 2.56, 3.14159}
workbook.Replace("AnOldValue", NewValues, True)
Replace(string, DataTable)
Replaces cells’ values with data from a System.Data.DataTable.
public int Replace(string placeHolder, DataTable insertTable)
Parameters
placeHolder
string
Cell placeholder
insertTable
DataTable
DataTable to replace
Returns
Examples
Workbook workbook = new Workbook();
DataTable myDataTable = new DataTable("Customers");
// Adds data to myDataTable
//........
workbook.Replace("AnOldValue", myDataTable);
Dim workbook As Workbook = New Workbook()
Dim myDataTable As DataTable = New DataTable("Customers")
' Adds data to myDataTable
'.............
workbook.Replace("AnOldValue", myDataTable)
Replace(bool, object)
Replaces cells’ values with new data.
public int Replace(bool boolValue, object newValue)
Parameters
boolValue
bool
The boolean value to be replaced.
newValue
object
New value. Can be string, integer, double or DateTime value.
Returns
Replace(int, object)
Replaces cells’ values with new data.
public int Replace(int intValue, object newValue)
Parameters
intValue
int
The integer value to be replaced.
newValue
object
New value. Can be string, integer, double or DateTime value.
Returns
Replace(string, string, ReplaceOptions)
Replaces a cell’s value with a new string.
public int Replace(string placeHolder, string newValue, ReplaceOptions options)
Parameters
placeHolder
string
Cell placeholder
newValue
string
String value to replace
options
ReplaceOptions
The replace options
Returns
Save(string, SaveFormat)
Saves the workbook to the disk.
public void Save(string fileName, SaveFormat saveFormat)
Parameters
fileName
string
The file name.
saveFormat
SaveFormat
The save format type.
Save(string)
Save the workbook to the disk.
public void Save(string fileName)
Parameters
fileName
string
Save(string, SaveOptions)
Saves the workbook to the disk.
public void Save(string fileName, SaveOptions saveOptions)
Parameters
fileName
string
The file name.
saveOptions
SaveOptions
The save options.
Save(Stream, SaveFormat)
Saves the workbook to the stream.
public void Save(Stream stream, SaveFormat saveFormat)
Parameters
stream
Stream
The file stream.
saveFormat
SaveFormat
The save file format type.
Save(Stream, SaveOptions)
Saves the workbook to the stream.
public void Save(Stream stream, SaveOptions saveOptions)
Parameters
stream
Stream
The file stream.
saveOptions
SaveOptions
The save options.
SaveToStream()
Saves Excel file to a MemoryStream object and returns it.
public MemoryStream SaveToStream()
Returns
MemoryStream object which contains an Excel file.
Remarks
This method provides same function as Save method and only save the workbook as Excel97-2003 xls file. It’s mainly for calling from COM clients.
SetDigitalSignature(DigitalSignatureCollection)
Sets digital signature to an spreadsheet file (Excel2007 and later).
public void SetDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)
Parameters
digitalSignatureCollection
DigitalSignatureCollection
Remarks
Only support adding Xmldsig Digital Signature
SetEncryptionOptions(EncryptionType, int)
Set Encryption Options.
public void SetEncryptionOptions(EncryptionType encryptionType, int keyLength)
Parameters
encryptionType
EncryptionType
The encryption type.
keyLength
int
The key length.
SetThemeColor(ThemeColorType, Color)
Sets the theme color
public void SetThemeColor(ThemeColorType type, Color color)
Parameters
type
ThemeColorType
The theme color type.
color
Color
the theme color
StartAccessCache(AccessCacheOptions)
Starts the session that uses caches to access data.
public void StartAccessCache(AccessCacheOptions opts)
Parameters
opts
AccessCacheOptions
options of data access
Remarks
If the cache of specified data access requires some data models in worksheet to be “read-only”,
then corresponding data models in every worksheet in this workbook will be taken as “read-only”
and user should not change any of them.
After finishing the access to the data, Aspose.Cells.Workbook.CloseAccessCache(Aspose.Cells.AccessCacheOptions) should
be invoked with same options to clear all caches and recover normal access mode.
Unprotect(string)
Unprotects a workbook.
public void Unprotect(string password)
Parameters
password
string
Password to unprotect the workbook.
UnprotectSharedWorkbook(string)
Unprotects a shared workbook.
public void UnprotectSharedWorkbook(string password)
Parameters
password
string
Password to unprotect the workbook.
UpdateCustomFunctionDefinition(CustomFunctionDefinition)
Updates definition of custom functions.
public void UpdateCustomFunctionDefinition(CustomFunctionDefinition definition)
Parameters
definition
CustomFunctionDefinition
Special definition of custom functions for user’s special requirement.
Remarks
This method can be used for some special scenarios. For example, if user needs some parameters of some custom functions be calculated in array mode, then user may provide their own definition with implemented Aspose.Cells.CustomFunctionDefinition.GetArrayModeParameters(System.String) for those functions. After the data of formulas being updated, those specified parameters will be calculated in array mode automatically when calculating corresponding 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.
public void UpdateLinkedDataSource(Workbook[] externalWorkbooks)
Parameters
externalWorkbooks
Workbook[]
Workbooks that will be used to update data of external links referenced by this workbook. The match of those workbooks with external links is determined by Aspose.Cells.Workbook.FileName and Aspose.Cells.ExternalLink.DataSource. So please make sure Aspose.Cells.Workbook.FileName has been specified with the proper value for every workbook so they can be linked to corresponding external link.
Remarks
If corresponding external link cannot be found for one workbook, then this workbook will be ignored. So when you set a formula later with one new external link which you intend to make the ignored workbook be linked to it, the link cannot be performed until you call this this method again with those workbooks.