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
Constructor | Description |
---|---|
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
Method | Description |
---|---|
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. |
getDataModel() | Gets data model in the workbook. |
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:
Parameter | Type | Description |
---|---|---|
fileFormatType | int | FileFormatType. The new file format. |
Workbook(String file)
public Workbook(String file)
Initializes a new instance of the Workbook class and open a file.
Parameters:
Parameter | Type | Description |
---|---|---|
file | java.lang.String | The file name. |
Workbook(InputStream stream)
public Workbook(InputStream stream)
Initializes a new instance of the Workbook class and open a stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | The 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:
Parameter | Type | Description |
---|---|---|
file | java.lang.String | The file name. |
loadOptions | LoadOptions | The 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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | The stream. |
loadOptions | LoadOptions | The 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:
Parameter | Type | Description |
---|---|---|
digitalSignatureCollection | DigitalSignatureCollection |
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:
Parameter | Type | Description |
---|---|---|
ignoreError | boolean | Indicates 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:
Parameter | Type | Description |
---|---|---|
options | CalculationOptions | Options 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.
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 |
Parameters:
Parameter | Type | Description |
---|---|---|
color | Color | Color structure. |
index | int | Palette index, 0 - 55. |
closeAccessCache(int opts)
public void closeAccessCache(int opts)
Closes the session that uses caches to access data.
Parameters:
Parameter | Type | Description |
---|---|---|
opts | int | AccessCacheOptions. 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:
Parameter | Type | Description |
---|---|---|
secondWorkbook | Workbook | Another Workbook object. |
copy(Workbook source)
public void copy(Workbook source)
Copies data from a source Workbook object.
Parameters:
Parameter | Type | Description |
---|---|---|
source | Workbook | Source 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:
Parameter | Type | Description |
---|---|---|
source | Workbook | Source Workbook object. |
copyOptions | CopyOptions | The options of copying other workbook. |
copyTheme(Workbook source)
public void copyTheme(Workbook source)
Copies the theme from another workbook.
Parameters:
Parameter | Type | Description |
---|---|---|
source | Workbook | Source workbook. |
createBuiltinStyle(int type)
public Style createBuiltinStyle(int type)
Creates built-in style by given type.
Parameters:
Parameter | Type | Description |
---|---|---|
type | int | BuiltinStyleType. The builtin style stype. |
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 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 |
Parameters:
Parameter | Type | Description |
---|---|---|
themeName | java.lang.String | The theme name |
colors | Color[] | 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:
Parameter | Type | Description |
---|---|---|
arg0 | java.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:
Parameter | Type | Description |
---|---|---|
mapName | java.lang.String | name of the XML map that need to be exported |
stream | java.io.OutputStream | the 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:
Parameter | Type | Description |
---|---|---|
mapName | java.lang.String | name of the XML map that need to be exported |
path | java.lang.String | the 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
getDataModel()
public DataModel getDataModel()
Gets data model in the workbook.
Returns: DataModel
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:
Parameter | Type | Description |
---|---|---|
rawColor | Color | Raw color. |
Returns: Color - Best matching color.
getNamedStyle(String name)
public Style getNamedStyle(String name)
Gets the named style in the style pool.
Parameters:
Parameter | Type | Description |
---|---|---|
name | java.lang.String | name 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:
Parameter | Type | Description |
---|---|---|
index | int | The 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:
Parameter | Type | Description |
---|---|---|
type | int | ThemeColorType. 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
hasExernalLinks()
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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | the xml file stream. |
sheetName | java.lang.String | the destination sheet name. |
row | int | the destination row. |
col | int | the 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:
Parameter | Type | Description |
---|---|---|
url | java.lang.String | the url/path of the xml file. |
sheetName | java.lang.String | the destination sheet name. |
row | int | the destination row |
col | int | the destination column |
isColorInPalette(Color color)
public boolean isColorInPalette(Color color)
Checks if a color is in the palette for the spreadsheet.
Parameters:
Parameter | Type | Description |
---|---|---|
color | Color | Color 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:
Parameter | Type | Description |
---|---|---|
ignoreError | boolean | 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(int protectionType, String password)
public void protect(int protectionType, String password)
Protects a workbook.
Parameters:
Parameter | Type | Description |
---|---|---|
protectionType | int | ProtectionType. Protection type. |
password | java.lang.String | Password to protect the workbook. |
protectSharedWorkbook(String password)
public void protectSharedWorkbook(String password)
Protects a shared workbook.
Parameters:
Parameter | Type | Description |
---|---|---|
password | java.lang.String | Password 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:
Parameter | Type | Description |
---|---|---|
calculate | boolean | Whether 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:
Parameter | Type | Description |
---|---|---|
calculate | boolean | Whether calculates and updates cell values for those dynamic array formulas |
copts | CalculationOptions | The options for calculating formulas |
removeDigitalSignature()
public void removeDigitalSignature()
Removes digital signature from this spreadsheet.
removeExternalLinks()
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:
Parameter | Type | Description |
---|---|---|
boolValue | boolean | The boolean value to be replaced. |
newValue | java.lang.Object | New 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:
Parameter | Type | Description |
---|---|---|
intValue | int | The integer value to be replaced. |
newValue | java.lang.Object | New 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValue | double | Double 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValues | double[] | Double array to replace |
isVertical | boolean | True - 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValue | int | Integer 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValues | int[] | Integer array to replace |
isVertical | boolean | True - 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValue | java.lang.String | String 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValue | java.lang.String | String value to replace |
options | ReplaceOptions | The 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:
Parameter | Type | Description |
---|---|---|
placeHolder | java.lang.String | Cell placeholder |
newValues | java.lang.String[] | String array to replace |
isVertical | boolean | True - Vertical, False - Horizontal |
Returns: int
save(OutputStream stream, SaveOptions saveOptions)
public void save(OutputStream stream, SaveOptions saveOptions)
Save the workbook to the stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | The file stream. |
saveOptions | SaveOptions | The save options. |
save(OutputStream stream, int saveFormat)
public void save(OutputStream stream, int saveFormat)
Save the workbook to the stream.
Parameters:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | The file stream. |
saveFormat | int | SaveFormat. The save file format type. |
save(String fileName)
public void save(String fileName)
Save the workbook to the disk.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String |
save(String fileName, SaveOptions saveOptions)
public void save(String fileName, SaveOptions saveOptions)
Saves the workbook to the disk.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | The file name. |
saveOptions | SaveOptions | The save options. |
save(String fileName, int saveFormat)
public void save(String fileName, int saveFormat)
Saves the workbook to the disk.
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | The file name. |
saveFormat | int | SaveFormat. 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:
Parameter | Type | Description |
---|---|---|
value | java.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:
Parameter | Type | Description |
---|---|---|
value | Style |
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:
Parameter | Type | Description |
---|---|---|
digitalSignatureCollection | DigitalSignatureCollection |
setEncryptionOptions(int encryptionType, int keyLength)
public void setEncryptionOptions(int encryptionType, int keyLength)
Set Encryption Options.
Parameters:
Parameter | Type | Description |
---|---|---|
encryptionType | int | EncryptionType. The encryption type. |
keyLength | int | The key length. |
setFileFormat(int value)
public void setFileFormat(int value)
Sets the file format.
See FileFormatType.
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
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:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setInterruptMonitor(AbstractInterruptMonitor value)
public void setInterruptMonitor(AbstractInterruptMonitor value)
Sets the interrupt monitor.
Parameters:
Parameter | Type | Description |
---|---|---|
value | AbstractInterruptMonitor |
setRibbonXml(String value)
public void setRibbonXml(String value)
Sets the XML file that defines the Ribbon UI.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setThemeColor(int type, Color color)
public void setThemeColor(int type, Color color)
Sets the theme color
Parameters:
Parameter | Type | Description |
---|---|---|
type | int | ThemeColorType. The theme color type. |
color | Color | the 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:
Parameter | Type | Description |
---|---|---|
opts | int | AccessCacheOptions. options of data access |
toString()
public String toString()
Returns: java.lang.String
unprotect(String password)
public void unprotect(String password)
Unprotects a workbook.
Parameters:
Parameter | Type | Description |
---|---|---|
password | java.lang.String | Password to unprotect the workbook. |
unprotectSharedWorkbook(String password)
public void unprotectSharedWorkbook(String password)
Unprotects a shared workbook.
Parameters:
Parameter | Type | Description |
---|---|---|
password | java.lang.String | Password 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:
Parameter | Type | Description |
---|---|---|
definition | CustomFunctionDefinition | Special 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:
Parameter | Type | Description |
---|---|---|
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 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:
Parameter | Type | Description |
---|---|---|
arg0 | long |
wait(long arg0, int arg1)
public final void wait(long arg0, int arg1)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long | |
arg1 | int |