Workbook

Inheritance: java.lang.Object

public class Workbook

Represents a root object to create an Excel spreadsheet.

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.

Example

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.getSettings().setHScrollBarVisible(false);
         workbook.getSettings().setVScrollBarVisible(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");

Constructors

ConstructorDescription
Workbook()Initializes a new instance of the Workbook class.
Workbook(int fileFormatType)Initializes a new instance of the Workbook class.
Workbook(String file)Initializes a new instance of the Workbook class and open a file.
Workbook(InputStream stream)Initializes a new instance of the Workbook class and open a stream.
Workbook(String file, LoadOptions loadOptions)Initializes a new instance of the Workbook class and open a file.
Workbook(InputStream stream, LoadOptions loadOptions)Initializes a new instance of the Workbook class and open stream.

Methods

MethodDescription
acceptAllRevisions()Accepts all tracked changes in the workbook.
addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
calculateFormula()Calculates the result of formulas.
calculateFormula(boolean ignoreError)Calculates the result of formulas.
calculateFormula(CalculationOptions options)Calculating formulas in this workbook.
changePalette(Color color, int index)Changes the palette for the spreadsheet in the specified index.
closeAccessCache(int opts)Closes the session that uses caches to access data.
combine(Workbook secondWorkbook)Combines another Workbook object.
copy(Workbook source)Copies data from a source Workbook object.
copy(Workbook source, CopyOptions copyOptions)Copies another Workbook object.
copyTheme(Workbook source)Copies the theme from another workbook.
createBuiltinStyle(int type)Creates built-in style by given type.
createCellsColor()Creates a CellsColor object.
createStyle()Creates a new style.
customTheme(String themeName, Color[] colors)Customs the theme.
dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
equals(Object arg0)
exportXml(String mapName, OutputStream stream)Export XML data linked by the specified XML map.
exportXml(String mapName, String path)Export XML data linked by the specified XML map.
getAbsolutePath()Gets the absolute path of the file.
getBuiltInDocumentProperties()Returns a DocumentProperty collection that represents all the built-in document properties of the spreadsheet.
getCellsDataTableFactory()Gets the factory for building ICellsDataTable from custom objects
getClass()
getColors()Returns colors in the palette for the spreadsheet.
getContentTypeProperties()Gets the list of ContentTypeProperty objects in the workbook.
getCountOfStylesInPool()Gets number of the styles in the style pool.
getCustomDocumentProperties()Returns a DocumentProperty collection that represents all the custom document properties of the spreadsheet.
getCustomXmlParts()Represents a Custom XML Data Storage Part (custom XML data within a package).
getDataConnections()Gets the ExternalConnection collection.
getDataMashup()Gets mashup data.
getDataSorter()Gets a DataSorter object to sort data.
getDefaultStyle()Gets the default Style object of the workbook.
getDigitalSignature()Gets digital signature from file.
getFileFormat()Gets the file format.
getFileName()Gets the current file name.
getFonts()Gets all fonts in the style pool.
getInterruptMonitor()Gets the interrupt monitor.
getMatchingColor(Color rawColor)Find best matching Color in current palette.
getNamedStyle(String name)Gets the named style in the style pool.
getRibbonXml()Gets the XML file that defines the Ribbon UI.
getSettings()Represents the workbook settings.
getStyleInPool(int index)Gets the style in the style pool.
getTheme()Gets the theme name.
getThemeColor(int type)Gets theme color.
getVbaProject()Gets the getVbaProject() in a spreadsheet.
getWorksheets()Gets the WorksheetCollection collection in the spreadsheet.
hasExernalLinks()Indicates whether this workbook contains external links to other data sources.
hasMacro()Indicates if this spreadsheet contains macro/VBA.
hasRevisions()Gets if the workbook has any tracked changes
hashCode()
importXml(InputStream stream, String sheetName, int row, int col)Imports/Updates an XML data file into the workbook.
importXml(String url, String sheetName, int row, int col)Imports/Updates an XML data file into the workbook.
isColorInPalette(Color color)Checks if a color is in the palette for the spreadsheet.
isDigitallySigned()Indicates if this spreadsheet is digitally signed.
isLicensed()Indicates whether license is set.
isWorkbookProtectedWithPassword()Indicates whether structure or window is protected with password.
notify()
notifyAll()
parseFormulas(boolean ignoreError)Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.
protect(int protectionType, String password)Protects a workbook.
protectSharedWorkbook(String password)Protects a shared workbook.
refreshDynamicArrayFormulas(boolean calculate)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(boolean calculate, CalculationOptions copts)Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data)
removeDigitalSignature()Removes digital signature from this spreadsheet.
removeExternalLinks()Removes all external links in the workbook.
removeMacro()Removes VBA/macro from this spreadsheet.
removePersonalInformation()Removes personal information.
removeUnusedStyles()Remove all unused styles.
replace(boolean boolValue, Object newValue)Replaces cells’ values with new data.
replace(int intValue, Object newValue)Replaces cells’ values with new data.
replace(String placeHolder, double newValue)Replaces a cell’s value with a new double.
replace(String placeHolder, double[] newValues, boolean isVertical)Replaces cells’ values with a double array.
replace(String placeHolder, int newValue)Replaces a cell’s value with a new integer.
replace(String placeHolder, int[] newValues, boolean isVertical)Replaces cells’ values with an integer array.
replace(String placeHolder, String newValue)Replaces a cell’s value with a new string.
replace(String placeHolder, String newValue, ReplaceOptions options)Replaces a cell’s value with a new string.
replace(String placeHolder, String[] newValues, boolean isVertical)Replaces a cell’s value with a new string array.
save(OutputStream stream, SaveOptions saveOptions)Save the workbook to the stream.
save(OutputStream stream, int saveFormat)Save the workbook to the stream.
save(String fileName)Save the workbook to the disk.
save(String fileName, SaveOptions saveOptions)Saves the workbook to the disk.
save(String fileName, int saveFormat)Saves the workbook to the disk.
setAbsolutePath(String value)Sets the absolute path of the file.
setDefaultStyle(Style value)Sets the default Style object of the workbook.
setDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)Sets digital signature to an spreadsheet file (Excel2007 and later).
setEncryptionOptions(int encryptionType, int keyLength)Set Encryption Options.
setFileFormat(int value)Sets the file format.
setFileName(String value)Sets the current file name.
setInterruptMonitor(AbstractInterruptMonitor value)Sets the interrupt monitor.
setRibbonXml(String value)Sets the XML file that defines the Ribbon UI.
setThemeColor(int type, Color color)Sets the theme color
startAccessCache(int opts)Starts the session that uses caches to access data.
toString()
unprotect(String password)Unprotects a workbook.
unprotectSharedWorkbook(String password)Unprotects a shared workbook.
updateCustomFunctionDefinition(CustomFunctionDefinition definition)Updates definition of custom functions.
updateLinkedDataSource(Workbook[] externalWorkbooks)If this workbook contains external links to other data source, Aspose.Cells will attempt to retrieve the latest data from give sources.
wait()
wait(long arg0)
wait(long arg0, int arg1)

Workbook()

public Workbook()

Initializes a new instance of the Workbook class.

Remarks

The default file format type is Xlsx. If you want to create other types of files, please use Workbook(FileFormatType).

Example

The following code shows how to use the Workbook constructor to create and initialize a new instance of the class.

         Workbook workbook = new Workbook();

Workbook(int fileFormatType)

public Workbook(int fileFormatType)

Initializes a new instance of the Workbook class.

Remarks

The default file format type is Excel97To2003.

Example

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);

Parameters:

ParameterTypeDescription
fileFormatTypeintFileFormatType. The new file format.

Workbook(String file)

public Workbook(String file)

Initializes a new instance of the Workbook class and open a file.

Parameters:

ParameterTypeDescription
filejava.lang.StringThe file name.

Workbook(InputStream stream)

public Workbook(InputStream stream)

Initializes a new instance of the Workbook class and open a stream.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream.

Workbook(String file, LoadOptions loadOptions)

public Workbook(String file, LoadOptions loadOptions)

Initializes a new instance of the Workbook class and open a file.

Parameters:

ParameterTypeDescription
filejava.lang.StringThe file name.
loadOptionsLoadOptionsThe load options

Workbook(InputStream stream, LoadOptions loadOptions)

public Workbook(InputStream stream, LoadOptions loadOptions)

Initializes a new instance of the Workbook class and open stream.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamThe stream.
loadOptionsLoadOptionsThe load options

acceptAllRevisions()

public void acceptAllRevisions()

Accepts all tracked changes in the workbook.

addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)

public void addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)

Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).

Remarks

Only support adding Xmldsig Digital Signature to an OOXML spreadsheet file

Parameters:

ParameterTypeDescription
digitalSignatureCollectionDigitalSignatureCollection

calculateFormula()

public void calculateFormula()

Calculates the result of formulas.

Remarks

For all supported formulas, please see the list at https://docs.aspose.com/display/cellsnet/Supported+Formula+Functions

calculateFormula(boolean ignoreError)

public void calculateFormula(boolean ignoreError)

Calculates the result of formulas.

Parameters:

ParameterTypeDescription
ignoreErrorbooleanIndicates if hide the error in calculating formulas. The error may be unsupported function, external links, etc.

calculateFormula(CalculationOptions options)

public void calculateFormula(CalculationOptions options)

Calculating formulas in this workbook.

Parameters:

ParameterTypeDescription
optionsCalculationOptionsOptions for calculation

changePalette(Color color, int index)

public void changePalette(Color color, int index)

Changes the palette for the spreadsheet in the specified index.

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.

ColorRedGreenBlue
Black000
White255255255
Red25500
Lime02550
Blue00255
Yellow2552550
Magenta2550255
Cyan0255255
Maroon12800
Green01280
Navy00128
Olive1281280
Purple1280128
Teal0128128
Silver192192192
Gray128128128
Color17153153255
Color1815351102
Color19255255204
Color20204255255
Color211020102
Color22255128128
Color230102204
Color24204204255
Color2500128
Color262550255
Color272552550
Color280255255
Color291280128
Color3012800
Color310128128
Color3200255
Color330204255
Color34204255255
Color35204255204
Color36255255153
Color37153204255
Color38255153204
Color39204153255
Color40255204153
Color4151102255
Color4251204204
Color431532040
Color442552040
Color452551530
Color462551020
Color47102102153
Color48150150150
Color49051102
Color5051153102
Color510510
Color5251510
Color53153510
Color5415351102
Color555151153
Color56515151

Parameters:

ParameterTypeDescription
colorColorColor structure.
indexintPalette index, 0 - 55.

closeAccessCache(int opts)

public void closeAccessCache(int opts)

Closes the session that uses caches to access data.

Parameters:

ParameterTypeDescription
optsintAccessCacheOptions. options of data access

combine(Workbook secondWorkbook)

public void combine(Workbook secondWorkbook)

Combines another Workbook object.

Remarks

Merge Excel, ODS , CSV and other files to one file.

Parameters:

ParameterTypeDescription
secondWorkbookWorkbookAnother Workbook object.

copy(Workbook source)

public void copy(Workbook source)

Copies data from a source Workbook object.

Parameters:

ParameterTypeDescription
sourceWorkbookSource Workbook object.

copy(Workbook source, CopyOptions copyOptions)

public void copy(Workbook source, CopyOptions copyOptions)

Copies another Workbook object.

Remarks

It’s very simple to clone an Excel file.

Parameters:

ParameterTypeDescription
sourceWorkbookSource Workbook object.
copyOptionsCopyOptionsThe options of copying other workbook.

copyTheme(Workbook source)

public void copyTheme(Workbook source)

Copies the theme from another workbook.

Parameters:

ParameterTypeDescription
sourceWorkbookSource workbook.

createBuiltinStyle(int type)

public Style createBuiltinStyle(int type)

Creates built-in style by given type.

Parameters:

ParameterTypeDescription
typeintBuiltinStyleType. The builtin style stype.

Returns: Style - Style object

createCellsColor()

public CellsColor createCellsColor()

Creates a CellsColor object.

Returns: CellsColor - Returns a CellsColor object.

createStyle()

public Style createStyle()

Creates a new style.

Returns: Style - Returns a style object.

customTheme(String themeName, Color[] colors)

public void customTheme(String themeName, Color[] colors)

Customs the theme.

Remarks

The length of colors should be 12.

Array indexTheme type
0Backgournd1
1Text1
2Backgournd2
3Text2
4Accent1
5Accent2
6Accent3
7Accent4
8Accent5
9Accent6
10Hyperlink
11Followed Hyperlink

Parameters:

ParameterTypeDescription
themeNamejava.lang.StringThe theme name
colorsColor[]The theme colors

dispose()

public void dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

equals(Object arg0)

public boolean equals(Object arg0)

Parameters:

ParameterTypeDescription
arg0java.lang.Object

Returns: boolean

exportXml(String mapName, OutputStream stream)

public void exportXml(String mapName, OutputStream stream)

Export XML data linked by the specified XML map.

Parameters:

ParameterTypeDescription
mapNamejava.lang.Stringname of the XML map that need to be exported
streamjava.io.OutputStreamthe export stream

exportXml(String mapName, String path)

public void exportXml(String mapName, String path)

Export XML data linked by the specified XML map.

Example

The following code exported the data linked by the first XmlMap.

         Workbook wb = new Workbook("Book1.xlsx");
 
         //Make sure that the source xlsx file contains a XmlMap.
         XmlMap xmlMap = wb.getWorksheets().getXmlMaps().get(0);
 
         wb.exportXml(xmlMap.getName(), "output.xml");

Parameters:

ParameterTypeDescription
mapNamejava.lang.Stringname of the XML map that need to be exported
pathjava.lang.Stringthe export path

getAbsolutePath()

public String getAbsolutePath()

Gets the absolute path of the file.

Remarks

Only used for external links.

Returns: java.lang.String

getBuiltInDocumentProperties()

public BuiltInDocumentPropertyCollection getBuiltInDocumentProperties()

Returns a DocumentProperty collection that represents all the built-in document properties of the spreadsheet.

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

Example

         Workbook workbook = new Workbook();
         DocumentProperty doc = workbook.getBuiltInDocumentProperties().get("Author");
         doc.setValue("John Smith");

Returns: BuiltInDocumentPropertyCollection

getCellsDataTableFactory()

public CellsDataTableFactory getCellsDataTableFactory()

Gets the factory for building ICellsDataTable from custom objects

Returns: CellsDataTableFactory

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getColors()

public Color[] getColors()

Returns colors in the palette for the spreadsheet.

Remarks

The palette has 56 entries, each represented by an RGB value.

Returns: com.aspose.cells.Color[]

getContentTypeProperties()

public ContentTypePropertyCollection getContentTypeProperties()

Gets the list of ContentTypeProperty objects in the workbook.

Returns: ContentTypePropertyCollection

getCountOfStylesInPool()

public int getCountOfStylesInPool()

Gets number of the styles in the style pool.

Returns: int

getCustomDocumentProperties()

public CustomDocumentPropertyCollection getCustomDocumentProperties()

Returns a DocumentProperty collection that represents all the custom document properties of the spreadsheet.

Example

         Workbook excel = new Workbook();
         excel.getCustomDocumentProperties().add("Checked by", "Jane");

Returns: CustomDocumentPropertyCollection

getCustomXmlParts()

public CustomXmlPartCollection getCustomXmlParts()

Represents a Custom XML Data Storage Part (custom XML data within a package).

Returns: CustomXmlPartCollection

getDataConnections()

public ExternalConnectionCollection getDataConnections()

Gets the ExternalConnection collection.

Returns: ExternalConnectionCollection

getDataMashup()

public DataMashup getDataMashup()

Gets mashup data.

Returns: DataMashup

getDataSorter()

public DataSorter getDataSorter()

Gets a DataSorter object to sort data.

Returns: DataSorter

getDefaultStyle()

public Style getDefaultStyle()

Gets the default Style object of the workbook.

Remarks

The DefaultStyle property is useful to implement a Style for the whole Workbook.

Example

The following code creates and instantiates a new Workbook and sets a default Style to it.

         Workbook workbook = new Workbook();
         Style defaultStyle = workbook.getDefaultStyle();
         defaultStyle.getFont().setName("Tahoma");
         workbook.setDefaultStyle(defaultStyle);

Returns: Style

getDigitalSignature()

public DigitalSignatureCollection getDigitalSignature()

Gets digital signature from file.

Returns: DigitalSignatureCollection

getFileFormat()

public int getFileFormat()

Gets the file format.

See FileFormatType.

Returns: int

getFileName()

public String getFileName()

Gets the current file name.

Remarks

If the file is opened by stream and there are some external formula references, please set the file name.

Returns: java.lang.String

getFonts()

public Font[] getFonts()

Gets all fonts in the style pool.

Returns: com.aspose.cells.Font[]

getInterruptMonitor()

public AbstractInterruptMonitor getInterruptMonitor()

Gets the interrupt monitor.

Returns: AbstractInterruptMonitor

getMatchingColor(Color rawColor)

public Color getMatchingColor(Color rawColor)

Find best matching Color in current palette.

Parameters:

ParameterTypeDescription
rawColorColorRaw color.

Returns: Color - Best matching color.

getNamedStyle(String name)

public Style getNamedStyle(String name)

Gets the named style in the style pool.

Parameters:

ParameterTypeDescription
namejava.lang.Stringname of the style

Returns: Style - named style, maybe null.

getRibbonXml()

public String getRibbonXml()

Gets the XML file that defines the Ribbon UI.

Returns: java.lang.String

getSettings()

public WorkbookSettings getSettings()

Represents the workbook settings.

Returns: WorkbookSettings

getStyleInPool(int index)

public Style getStyleInPool(int index)

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.

Remarks

If the returned style is changed, the style of all cells(which refers to this style) will be changed.

Parameters:

ParameterTypeDescription
indexintThe index.

Returns: Style - The style in the pool corresponds to given index, may be null.

getTheme()

public String getTheme()

Gets the theme name.

Returns: java.lang.String

getThemeColor(int type)

public Color getThemeColor(int type)

Gets theme color.

Parameters:

ParameterTypeDescription
typeintThemeColorType. The theme color type.

Returns: Color - The theme color.

getVbaProject()

public VbaProject getVbaProject()

Gets the getVbaProject() in a spreadsheet.

Returns: VbaProject

getWorksheets()

public WorksheetCollection getWorksheets()

Gets the WorksheetCollection collection in the spreadsheet.

Returns: WorksheetCollection - WorksheetCollection collection

public boolean hasExernalLinks()

Indicates whether this workbook contains external links to other data sources.

Remarks

NOTE: This member is now obsolete. Instead, please use ExternalLinkCollection.Count to check whether there are external links in this workbook. This method will be removed 12 months later since December 2021. Aspose apologizes for any inconvenience you may have experienced.

Returns: boolean - Whether this workbook contains external links to other data sources.

hasMacro()

public boolean hasMacro()

Indicates if this spreadsheet contains macro/VBA.

Returns: boolean

hasRevisions()

public boolean hasRevisions()

Gets if the workbook has any tracked changes

Returns: boolean

hashCode()

public native int hashCode()

Returns: int

importXml(InputStream stream, String sheetName, int row, int col)

public void importXml(InputStream stream, String sheetName, int row, int col)

Imports/Updates an XML data file into the workbook.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamthe xml file stream.
sheetNamejava.lang.Stringthe destination sheet name.
rowintthe destination row.
colintthe destination column.

importXml(String url, String sheetName, int row, int col)

public void importXml(String url, String sheetName, int row, int col)

Imports/Updates an XML data file into the workbook.

Example

The following code imports xml data into worksheet ‘Sheet 1’ at Cell A1.

         Workbook wb = new Workbook("Book1.xlsx");
 
         wb.importXml("xml.xml", "Sheet1", 0, 0);
 
         wb.save("output.xlsx");

Parameters:

ParameterTypeDescription
urljava.lang.Stringthe url/path of the xml file.
sheetNamejava.lang.Stringthe destination sheet name.
rowintthe destination row
colintthe destination column

isColorInPalette(Color color)

public boolean isColorInPalette(Color color)

Checks if a color is in the palette for the spreadsheet.

Parameters:

ParameterTypeDescription
colorColorColor structure.

Returns: boolean - Returns true if this color is in the palette. Otherwise, returns false

isDigitallySigned()

public boolean isDigitallySigned()

Indicates if this spreadsheet is digitally signed.

Returns: boolean

isLicensed()

public boolean isLicensed()

Indicates whether license is set.

Returns: boolean

isWorkbookProtectedWithPassword()

public boolean isWorkbookProtectedWithPassword()

Indicates whether structure or window is protected with password.

Returns: boolean

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

parseFormulas(boolean ignoreError)

public void parseFormulas(boolean ignoreError)

Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.

Parameters:

ParameterTypeDescription
ignoreErrorbooleanWhether 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(int protectionType, String password)

public void protect(int protectionType, String password)

Protects a workbook.

Parameters:

ParameterTypeDescription
protectionTypeintProtectionType. Protection type.
passwordjava.lang.StringPassword to protect the workbook.

protectSharedWorkbook(String password)

public void protectSharedWorkbook(String password)

Protects a shared workbook.

Parameters:

ParameterTypeDescription
passwordjava.lang.StringPassword to protect the workbook.

refreshDynamicArrayFormulas(boolean calculate)

public void refreshDynamicArrayFormulas(boolean calculate)

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.

Parameters:

ParameterTypeDescription
calculatebooleanWhether calculates and updates cell values for those dynamic array formulas

refreshDynamicArrayFormulas(boolean calculate, CalculationOptions copts)

public void refreshDynamicArrayFormulas(boolean calculate, CalculationOptions copts)

Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data)

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 calculateFormula(CalculationOptions)), then using false vlaue for “calculate” flag may avoid the duplicated calculation for the benefit of performance.

Parameters:

ParameterTypeDescription
calculatebooleanWhether calculates and updates cell values for those dynamic array formulas
coptsCalculationOptionsThe options for calculating formulas

removeDigitalSignature()

public void removeDigitalSignature()

Removes digital signature from this spreadsheet.

public void removeExternalLinks()

Removes all external links in the workbook.

Remarks

NOTE: This member is now obsolete. Instead, please use ExternalLinkCollection.Clear() method. This method will be removed 12 months later since December 2021. Aspose apologizes for any inconvenience you may have experienced.

removeMacro()

public void removeMacro()

Removes VBA/macro from this spreadsheet.

removePersonalInformation()

public void removePersonalInformation()

Removes personal information.

removeUnusedStyles()

public void removeUnusedStyles()

Remove all unused styles.

replace(boolean boolValue, Object newValue)

public int replace(boolean boolValue, Object newValue)

Replaces cells’ values with new data.

Parameters:

ParameterTypeDescription
boolValuebooleanThe boolean value to be replaced.
newValuejava.lang.ObjectNew value. Can be string, integer, double or DateTime value.

Returns: int

replace(int intValue, Object newValue)

public int replace(int intValue, Object newValue)

Replaces cells’ values with new data.

Parameters:

ParameterTypeDescription
intValueintThe integer value to be replaced.
newValuejava.lang.ObjectNew value. Can be string, integer, double or DateTime value.

Returns: int

replace(String placeHolder, double newValue)

public int replace(String placeHolder, double newValue)

Replaces a cell’s value with a new double.

Example

         Workbook workbook = new Workbook();
         //......
         double newValue = 100.0;
         workbook.replace("AnOldValue", newValue);

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValuedoubleDouble value to replace

Returns: int

replace(String placeHolder, double[] newValues, boolean isVertical)

public int replace(String placeHolder, double[] newValues, boolean isVertical)

Replaces cells’ values with a double array.

Example

         Workbook workbook = new Workbook();
         //......
         double[] newValues = new double[]{1.23, 2.56, 3.14159};
         workbook.replace("AnOldValue", newValues, true);

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValuesdouble[]Double array to replace
isVerticalbooleanTrue - Vertical, False - Horizontal

Returns: int

replace(String placeHolder, int newValue)

public int replace(String placeHolder, int newValue)

Replaces a cell’s value with a new integer.

Example

         Workbook workbook = new Workbook();
         //......
         int newValue = 100;
         workbook.replace("AnOldValue", newValue);

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValueintInteger value to replace

Returns: int

replace(String placeHolder, int[] newValues, boolean isVertical)

public int replace(String placeHolder, int[] newValues, boolean isVertical)

Replaces cells’ values with an integer array.

Example

         Workbook workbook = new Workbook();
         //......
         int[] newValues = new int[]{1, 2, 3};
         workbook.replace("AnOldValue", newValues, true);

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValuesint[]Integer array to replace
isVerticalbooleanTrue - Vertical, False - Horizontal

Returns: int

replace(String placeHolder, String newValue)

public int replace(String placeHolder, String newValue)

Replaces a cell’s value with a new string.

Example

         Workbook workbook = new Workbook();
         //......
         workbook.replace("AnOldValue", "NewValue");

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValuejava.lang.StringString value to replace

Returns: int

replace(String placeHolder, String newValue, ReplaceOptions options)

public int replace(String placeHolder, String newValue, ReplaceOptions options)

Replaces a cell’s value with a new string.

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValuejava.lang.StringString value to replace
optionsReplaceOptionsThe replace options

Returns: int

replace(String placeHolder, String[] newValues, boolean isVertical)

public int replace(String placeHolder, String[] newValues, boolean isVertical)

Replaces a cell’s value with a new string array.

Example

         Workbook workbook = new Workbook();
         //......
         String[] newValues = new String[]{"Tom", "Alice", "Jerry"};
         workbook.replace("AnOldValue", newValues, true);

Parameters:

ParameterTypeDescription
placeHolderjava.lang.StringCell placeholder
newValuesjava.lang.String[]String array to replace
isVerticalbooleanTrue - Vertical, False - Horizontal

Returns: int

save(OutputStream stream, SaveOptions saveOptions)

public void save(OutputStream stream, SaveOptions saveOptions)

Save the workbook to the stream.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamThe file stream.
saveOptionsSaveOptionsThe save options.

save(OutputStream stream, int saveFormat)

public void save(OutputStream stream, int saveFormat)

Save the workbook to the stream.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamThe file stream.
saveFormatintSaveFormat. The save file format type.

save(String fileName)

public void save(String fileName)

Save the workbook to the disk.

Parameters:

ParameterTypeDescription
fileNamejava.lang.String

save(String fileName, SaveOptions saveOptions)

public void save(String fileName, SaveOptions saveOptions)

Saves the workbook to the disk.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringThe file name.
saveOptionsSaveOptionsThe save options.

save(String fileName, int saveFormat)

public void save(String fileName, int saveFormat)

Saves the workbook to the disk.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringThe file name.
saveFormatintSaveFormat. The save format type.

setAbsolutePath(String value)

public void setAbsolutePath(String value)

Sets the absolute path of the file.

Remarks

Only used for external links.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setDefaultStyle(Style value)

public void setDefaultStyle(Style value)

Sets the default Style object of the workbook.

Remarks

The DefaultStyle property is useful to implement a Style for the whole Workbook.

Parameters:

ParameterTypeDescription
valueStyle

setDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)

public void setDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)

Sets digital signature to an spreadsheet file (Excel2007 and later).

Remarks

Only support adding Xmldsig Digital Signature

Parameters:

ParameterTypeDescription
digitalSignatureCollectionDigitalSignatureCollection

setEncryptionOptions(int encryptionType, int keyLength)

public void setEncryptionOptions(int encryptionType, int keyLength)

Set Encryption Options.

Parameters:

ParameterTypeDescription
encryptionTypeintEncryptionType. The encryption type.
keyLengthintThe key length.

setFileFormat(int value)

public void setFileFormat(int value)

Sets the file format.

See FileFormatType.

Parameters:

ParameterTypeDescription
valueint

setFileName(String value)

public void setFileName(String value)

Sets the current file name.

Remarks

If the file is opened by stream and there are some external formula references, please set the file name.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setInterruptMonitor(AbstractInterruptMonitor value)

public void setInterruptMonitor(AbstractInterruptMonitor value)

Sets the interrupt monitor.

Parameters:

ParameterTypeDescription
valueAbstractInterruptMonitor

setRibbonXml(String value)

public void setRibbonXml(String value)

Sets the XML file that defines the Ribbon UI.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setThemeColor(int type, Color color)

public void setThemeColor(int type, Color color)

Sets the theme color

Parameters:

ParameterTypeDescription
typeintThemeColorType. The theme color type.
colorColorthe theme color

startAccessCache(int opts)

public void startAccessCache(int opts)

Starts the session that uses caches to access data.

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, closeAccessCache(int) should be invoked with same options to clear all caches and recover normal access mode.

Parameters:

ParameterTypeDescription
optsintAccessCacheOptions. options of data access

toString()

public String toString()

Returns: java.lang.String

unprotect(String password)

public void unprotect(String password)

Unprotects a workbook.

Parameters:

ParameterTypeDescription
passwordjava.lang.StringPassword to unprotect the workbook.

unprotectSharedWorkbook(String password)

public void unprotectSharedWorkbook(String password)

Unprotects a shared workbook.

Parameters:

ParameterTypeDescription
passwordjava.lang.StringPassword to unprotect the workbook.

updateCustomFunctionDefinition(CustomFunctionDefinition definition)

public void updateCustomFunctionDefinition(CustomFunctionDefinition definition)

Updates definition of custom functions.

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 CustomFunctionDefinition.getArrayModeParameters(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.

Parameters:

ParameterTypeDescription
definitionCustomFunctionDefinitionSpecial definition of custom functions for user’s special requirement.

updateLinkedDataSource(Workbook[] externalWorkbooks)

public void updateLinkedDataSource(Workbook[] externalWorkbooks)

If this workbook contains external links to other data source, Aspose.Cells will attempt to retrieve the latest data from give sources.

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.

Parameters:

ParameterTypeDescription
externalWorkbooksWorkbook[]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 getFileName() and ExternalLink.getDataSource(). So please make sure getFileName() has been specified with the proper value for every workbook so they can be linked to corresponding external link.

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int