public class Workbook
Example:
//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);
XlsSaveOptions saveOptions = new XlsSaveOptions();
workbook.save("result.xls", saveOptions);
Constructor Summary |
---|
Workbook(java.io.InputStreamstream)
Initializes a new instance of the |
Workbook(java.lang.Stringfile, LoadOptions loadOptions)
Initializes a new instance of the |
Workbook(java.io.InputStreamstream, LoadOptions loadOptions)
Initializes a new instance of the |
Property Getters/Setters Summary | ||
---|---|---|
java.lang.String | getAbsolutePath() | |
void | setAbsolutePath(java.lang.Stringvalue) | |
Gets and sets the absolute path of the file. | ||
BuiltInDocumentPropertyCollection | getBuiltInDocumentProperties() | |
Returns a DocumentProperties collection that represents all the built-in document properties of the spreadsheet.
|
||
com.aspose.cells.Color[] | getColors() | |
Returns colors in the palette for the spreadsheet.
|
||
ContentTypePropertyCollection | getContentTypeProperties() | |
Gets the contenttypeproperties objects in the workbook.
|
||
int | getCountOfStylesInPool() | |
Gets number of the styles in the style pool.
|
||
CustomDocumentPropertyCollection | getCustomDocumentProperties() | |
Returns a DocumentProperties collection that represents all the custom document properties of the spreadsheet.
|
||
CustomXmlPartCollection | getCustomXmlParts() | |
Represents a InnerCustom XML Data Storage Part (custom XML data within a package).
|
||
ExternalConnectionCollection | getDataConnections() | |
Gets the |
||
Aspose.Cells.QueryTables.DataMashup | getDataMashup() | |
Gets mashup data.
|
||
DataSorter | getDataSorter() | |
Gets a DataSorter object to sort data.
|
||
Style | getDefaultStyle() | |
void | setDefaultStyle(Style value) | |
Gets or sets the default |
||
int | getFileFormat() | |
void | setFileFormat(intvalue) | |
Gets and sets the file format. The value of the property is FileFormatType integer constant. | ||
java.lang.String | getFileName() | |
void | setFileName(java.lang.Stringvalue) | |
Gets and sets the current file name. | ||
boolean | hasMacro() | |
Indicates if this spreadsheet contains macro/VBA.
|
||
boolean | hasRevisions() | |
Gets if the workbook has any tracked changes
|
||
InterruptMonitor | getInterruptMonitor() | |
void | ||
Gets and sets the interrupt monitor. | ||
boolean | isDigitallySigned() | |
Indicates if this spreadsheet is digitally signed.
|
||
boolean | isLicensed() | |
Indicates whether license is set.
|
||
java.lang.String | getRibbonXml() | |
void | setRibbonXml(java.lang.Stringvalue) | |
Gets and sets the XML file that defines the Ribbon UI. | ||
WorkbookSettings | getSettings() | |
Represents the workbook settings.
|
||
java.lang.String | getTheme() | |
Gets the theme name.
|
||
VbaProject | getVbaProject() | |
Gets the |
||
WorksheetCollection | getWorksheets() | |
Gets the |
Method Summary | ||
---|---|---|
void | acceptAllRevisions() | |
Accepts all tracked changes in the workbook.
|
||
void | addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) | |
Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
|
||
void | calculateFormula() | |
Calculates the result of formulas.
|
||
void | calculateFormula(boolean ignoreError) | |
Calculates the result of formulas.
|
||
void | calculateFormula(boolean ignoreError, ICustomFunction customFunction) | |
Calculates the result of formulas.
|
||
void | calculateFormula(CalculationOptions options) | |
Calcualting formulas in this workbook.
|
||
void | changePalette(com.aspose.cells.Color color, int index) | |
Changes the palette for the spreadsheet in the specified index.
|
||
void | combine(Workbook secondWorkbook) | |
Combines another Workbook object.
|
||
void | copy(Workbook source0) | |
Copies data from a source Workbook object.
|
||
void | copyTheme(Workbook source) | |
Copies the theme from another workbook.
|
||
Style | createBuiltinStyle(int type) | |
Creates built-in style by given type.
|
||
CellsColor | createCellsColor() | |
Creates a |
||
Style | createStyle() | |
Creates a new style.
|
||
void | customTheme(java.lang.String themeName, com.aspose.cells.Color[] colors) | |
Customs the theme.
|
||
void | dispose() | |
Performs application-defined tasks associated with freeing, releasing, or
resetting unmanaged resources.
|
||
void | exportXml(java.lang.String mapName, java.io.OutputStream stream) | |
Export XML data.
|
||
void | exportXml(java.lang.String mapName, java.lang.String path) | |
Export XML data.
|
||
DigitalSignatureCollection | getDigitalSignature() | |
Gets digital signature from file.
|
||
com.aspose.cells.Font[] | getFonts() | |
Gets all fonts in the style pool.
|
||
com.aspose.cells.Color | getMatchingColor(com.aspose.cells.Color rawColor) | |
Find best matching Color in current palette.
|
||
Style | getNamedStyle(java.lang.String name) | |
Gets the named style in the style pool.
|
||
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.
|
||
com.aspose.cells.Color | getThemeColor(int type) | |
Gets theme color.
|
||
boolean | hasExernalLinks() | |
Indicates whether this workbook contains external links to other data sources.
|
||
void | importXml(java.io.InputStream stream, java.lang.String sheetName, int row, int col) | |
Imports an xml file into the workbook.
|
||
void | importXml(java.lang.String url, java.lang.String sheetName, int row, int col) | |
Imports an xml file into the workbook.
|
||
boolean | isColorInPalette(com.aspose.cells.Color color) | |
Checks if a color is in the palette for the spreadsheet.
|
||
void | parseFormulas(boolean ignoreError) | |
Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.
|
||
void | protect(int protectionType, java.lang.String password) | |
Protects a workbook.
|
||
void | protectSharedWorkbook(java.lang.String password) | |
Protects a shared workbook.
|
||
void | removeDigitalSignature() | |
Removes digital signature from this spreadsheet.
|
||
void | removeExternalLinks() | |
Removes all external links in the workbook.
|
||
void | removeMacro() | |
Removes VBA/macro from this spreadsheet.
|
||
void | removeUnusedStyles() | |
Remove all unused styles.
|
||
int | replace(boolean boolValue, java.lang.Object newValue) | |
Replaces cells' values with new data.
|
||
int | replace(int intValue, java.lang.Object newValue) | |
Replaces cells' values with new data.
|
||
int | replace(java.lang.String placeHolder, double newValue) | |
Replaces a cell's value with a new double.
|
||
int | replace(java.lang.String placeHolder, double[] newValues, boolean isVertical) | |
Replaces cells' values with a double array.
|
||
int | replace(java.lang.String placeHolder, int newValue) | |
Replaces a cell's value with a new integer.
|
||
int | replace(java.lang.String placeHolder, int[] newValues, boolean isVertical) | |
Replaces cells' values with an integer array.
|
||
int | replace(java.lang.String placeHolder, java.lang.String newValue) | |
Replaces a cell's value with a new string.
|
||
int | replace(java.lang.String placeHolder, java.lang.String newValue, ReplaceOptions options) | |
Replaces a cell's value with a new string.
|
||
int | replace(java.lang.String placeHolder, java.lang.String[] newValues, boolean isVertical) | |
Replaces a cell's value with a new string array.
|
||
void | save(java.io.OutputStream stream, SaveOptions saveOptions) | |
Save the workbook to the stream.
|
||
void | save(java.io.OutputStream stream, int saveFormat) | |
Save the workbook to the stream.
|
||
void | save(java.lang.String fileName) | |
Save the workbook to the disk.
|
||
void | save(java.lang.String fileName, SaveOptions saveOptions) | |
Saves the workbook to the disk.
|
||
void | save(java.lang.String fileName, int saveFormat) | |
Saves the workbook to the disk.
|
||
void | setDigitalSignature(DigitalSignatureCollection digitalSignatureCollection) | |
Sets digital signature to an spreadsheet file (Excel2007 and later).
|
||
void | setEncryptionOptions(int encryptionType, int keyLength) | |
Set Encryption Options.
|
||
void | setThemeColor(int type, com.aspose.cells.Color color) | |
Sets the theme color
|
||
void | unprotect(java.lang.String password) | |
Unprotects a workbook.
|
||
void | unprotectSharedWorkbook(java.lang.String password) | |
Unprotects a shared workbook.
|
||
void | updateLinkedDataSource(com.aspose.cells.Workbook[] exteralWorkbooks) | |
If this workbook contains external links to other data source,
Aspose.Cells will attempt to retrieve the latest data.
|
public Workbook()
public Workbook(int fileFormatType)
fileFormatType
- A 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(FileFormatType.XLSX);
public Workbook(java.lang.String file) throws java.lang.Exception
file
- The file name.public Workbook(java.io.InputStream stream) throws java.lang.Exception
stream
- The stream.public Workbook(java.lang.String file, LoadOptions loadOptions) throws java.lang.Exception
file
- The file name.loadOptions
- The load optionspublic Workbook(java.io.InputStream stream, LoadOptions loadOptions) throws java.lang.Exception
stream
- The stream.loadOptions
- The load optionspublic WorkbookSettings getSettings()
public WorksheetCollection getWorksheets()
public boolean isLicensed()
public com.aspose.cells.Color[] getColors()
public int getCountOfStylesInPool()
public Style getDefaultStyle() / public void setDefaultStyle(Style value)
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);
public boolean isDigitallySigned()
public VbaProject getVbaProject()
public boolean hasMacro()
public boolean hasRevisions()
public java.lang.String getFileName() / public void setFileName(java.lang.String value)
public DataSorter getDataSorter()
public java.lang.String getTheme()
public BuiltInDocumentPropertyCollection getBuiltInDocumentProperties()
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:
DocumentProperty doc = workbook.getBuiltInDocumentProperties().get("Author"); doc.setValue("John Smith");
public CustomDocumentPropertyCollection getCustomDocumentProperties()
Example:
excel.getCustomDocumentProperties().add("Checked by", "Jane");
public int getFileFormat() / public void setFileFormat(int value)
public InterruptMonitor getInterruptMonitor() / public void setInterruptMonitor(InterruptMonitor value)
public ContentTypePropertyCollection getContentTypeProperties()
public CustomXmlPartCollection getCustomXmlParts()
public Aspose.Cells.QueryTables.DataMashup getDataMashup()
public java.lang.String getRibbonXml() / public void setRibbonXml(java.lang.String value)
public java.lang.String getAbsolutePath() / public void setAbsolutePath(java.lang.String value)
public ExternalConnectionCollection getDataConnections()
public void parseFormulas(boolean ignoreError)
ignoreError
- 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.public void save(java.lang.String fileName, int saveFormat) throws java.lang.Exception
fileName
- The file name.saveFormat
- A Example:
Workbook workbook = new Workbook(); WorksheetCollection sheets = workbook.getWorksheets(); Cells cells = sheets.get(0).getCells(); cells.get("A1").putValue("Hello world!"); workbook.save("D:\\test.xls", SaveFormat.EXCEL_97_TO_2003);
public void save(java.lang.String fileName) throws java.lang.Exception
fileName
- public void save(java.lang.String fileName, SaveOptions saveOptions) throws java.lang.Exception
fileName
- The file name.saveOptions
- The save options.public void save(java.io.OutputStream stream, SaveOptions saveOptions) throws java.lang.Exception
stream
- The file stream.saveOptions
- The save options.public void save(java.io.OutputStream stream, int saveFormat) throws java.lang.Exception
stream
- The file stream.saveFormat
- A public void removeUnusedStyles()
public Style createStyle()
public Style createBuiltinStyle(int type)
type
- A public CellsColor createCellsColor()
public int replace(java.lang.String placeHolder, java.lang.String newValue)
placeHolder
- Cell placeholdernewValue
- String value to replaceExample:
Workbook workbook = new Workbook(); Cells cells = workbook.getWorksheets().get(0).getCells(); cells.get(0, 0).putValue("AnOldValue"); cells.get(0, 1).putValue("AnotherOldValue"); workbook.replace("AnOldValue", "NewValue");
public int replace(java.lang.String placeHolder, int newValue)
placeHolder
- Cell placeholdernewValue
- Integer value to replaceExample:
Workbook workbook = new Workbook(); int newValue = 100; workbook.replace("AnOldValue", newValue);
public int replace(java.lang.String placeHolder, double newValue)
placeHolder
- Cell placeholdernewValue
- Double value to replaceExample:
Workbook workbook = new Workbook(); double newValue = 100.0; workbook.replace("AnOldValue", newValue);
public int replace(java.lang.String placeHolder, java.lang.String[] newValues, boolean isVertical)
placeHolder
- Cell placeholdernewValues
- String array to replaceisVertical
- True - Vertical, False - HorizontalExample:
Workbook workbook = new Workbook(); String[] newValues = new String[]{"Tom", "Alice", "Jerry"}; workbook.replace("AnOldValue", newValues, true);
public int replace(java.lang.String placeHolder, int[] newValues, boolean isVertical)
placeHolder
- Cell placeholdernewValues
- Integer array to replaceisVertical
- True - Vertical, False - HorizontalExample:
Workbook workbook = new Workbook(); int[] newValues = new int[]{1, 2, 3}; workbook.replace("AnOldValue", newValues, true);
public int replace(java.lang.String placeHolder, double[] newValues, boolean isVertical)
placeHolder
- Cell placeholdernewValues
- Double array to replaceisVertical
- True - Vertical, False - HorizontalExample:
Workbook workbook = new Workbook(); double[] newValues = new double[]{1.23, 2.56, 3.14159}; workbook.replace("AnOldValue", newValues, true);
public int replace(boolean boolValue, java.lang.Object newValue)
boolValue
- The boolean value to be replaced.newValue
- New value. Can be string, integer, double or DateTime value.public int replace(int intValue, java.lang.Object newValue)
intValue
- The integer value to be replaced.newValue
- New value. Can be string, integer, double or DateTime value.public int replace(java.lang.String placeHolder, java.lang.String newValue, ReplaceOptions options)
placeHolder
- Cell placeholdernewValue
- String value to replaceoptions
- The replace optionspublic void copy(Workbook source0) throws java.lang.Exception
source0
- Source Workbook object.public void combine(Workbook secondWorkbook) throws java.lang.Exception
secondWorkbook
- Another Workbook object.public Style getStyleInPool(int index)
index
- The index.public com.aspose.cells.Font[] getFonts()
public Style getNamedStyle(java.lang.String name)
name
- name of the stylepublic void changePalette(com.aspose.cells.Color color, int index)
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¡¡ |
color
- Color structure.index
- Palette index, 0 - 55.public boolean isColorInPalette(com.aspose.cells.Color color)
color
- Color structure.public void calculateFormula()
public void calculateFormula(boolean ignoreError)
ignoreError
- Indicates if hide the error in calculating formulas. The error may be unsupported function, external links, etc.public void calculateFormula(boolean ignoreError, ICustomFunction customFunction)
ignoreError
- Indicates if hide the error in calculating formulas. The error may be unsupported function, external links, etc.customFunction
- The custom formula calculation functions to extend the calculation engine.public void calculateFormula(CalculationOptions options)
options
- Options for calculationpublic com.aspose.cells.Color getMatchingColor(com.aspose.cells.Color rawColor)
rawColor
- Raw color.public void setEncryptionOptions(int encryptionType, int keyLength)
encryptionType
- A keyLength
- The key length.public void protect(int protectionType, java.lang.String password)
protectionType
- A password
- Password to protect the workbook.public void protectSharedWorkbook(java.lang.String password)
password
- Password to protect the workbook.public void unprotect(java.lang.String password)
password
- Password to unprotect the workbook.public void unprotectSharedWorkbook(java.lang.String password)
password
- Password to unprotect the workbook.public void removeMacro()
public void removeDigitalSignature()
public void acceptAllRevisions()
public void removeExternalLinks()
public com.aspose.cells.Color getThemeColor(int type)
type
- A public void setThemeColor(int type, com.aspose.cells.Color color)
type
- A color
- the theme colorpublic void customTheme(java.lang.String themeName, com.aspose.cells.Color[] colors)
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¡¡ |
themeName
- The theme namecolors
- The theme colorspublic void copyTheme(Workbook source)
source
- Source workbook.public boolean hasExernalLinks()
public void updateLinkedDataSource(com.aspose.cells.Workbook[] exteralWorkbooks) throws java.lang.Exception
exteralWorkbooks
-
External workbooks are referenced by this workbook.
If it's null, we will directly open the external linked files..
If it's not null,
we will check whether the external link in the array first;
if not, we will open the external linked files again.
public void importXml(java.lang.String url, java.lang.String sheetName, int row, int col) throws java.lang.Exception
url
- the path of the xml file.sheetName
- the destination sheet name .row
- the destination row of the xml.col
- the destination column of the xml.public void importXml(java.io.InputStream stream, java.lang.String sheetName, int row, int col) throws java.lang.Exception
stream
- the xml file stream.sheetName
- the destination sheet name .row
- the destination row of the xml.col
- the destination column of the xml.public void exportXml(java.lang.String mapName, java.lang.String path) throws java.lang.Exception
mapName
- name of the XML map that need to be exportedpath
- the export pathpublic void exportXml(java.lang.String mapName, java.io.OutputStream stream) throws java.lang.Exception
mapName
- name of the XML map that need to be exportedstream
- the export streampublic void setDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)
digitalSignatureCollection
- public void addDigitalSignature(DigitalSignatureCollection digitalSignatureCollection)
digitalSignatureCollection
- public DigitalSignatureCollection getDigitalSignature()
public void dispose()