Example:
The following example creates a Workbook, opens a file named designer.xls in it and makes the horizontal and vertical scroll bars invisible for the Workbook. It then replaces two string values with an Integer value and string value respectively within the spreadsheet and finally save it to file named result.xls.# Use Aspose.Cells for Python via Java import jpype import asposecells jpype.startJVM() from asposecells.api import * # Open an excel file workbook = Workbook("Book2.xlsx") # Set scroll bars workbook.getSettings().setHScrollBarVisible(False) workbook.getSettings().setVScrollBarVisible(False) # Replace the placeholder string with new values workbook.replace("OldInt", 100) newString = "Hello!" workbook.replace("OldString", newString) saveOptions = XlsSaveOptions() workbook.save("Book1.xls", saveOptions)
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
method | getAbsolutePath() | |
method | setAbsolutePath(value) | |
Gets and sets the absolute path of the file. | ||
method | getBuiltInDocumentProperties() | |
Returns a |
||
method | getCellsDataTableFactory() | |
Gets the factory for building ICellsDataTable from custom objects
|
||
method | getColors() | |
Returns colors in the palette for the spreadsheet.
|
||
method | getContentTypeProperties() | |
Gets the list of |
||
method | getCountOfStylesInPool() | |
Gets number of the styles in the style pool.
|
||
method | getCustomDocumentProperties() | |
Returns a |
||
method | getCustomXmlParts() | |
Represents a Custom XML Data Storage Part (custom XML data within a package).
|
||
method | getDataConnections() | |
Gets the |
||
method | getDataMashup() | |
Gets mashup data.
|
||
method | getDataSorter() | |
Gets a DataSorter object to sort data.
|
||
method | getDefaultStyle() | |
method | setDefaultStyle(value) | |
Gets or sets the default |
||
method | getFileFormat() | |
method | setFileFormat(value) | |
Gets and sets the file format. The value of the property is FileFormatType integer constant. | ||
method | getFileName() | |
method | setFileName(value) | |
Gets and sets the current file name. | ||
method | hasMacro() | |
Indicates if this spreadsheet contains macro/VBA.
|
||
method | hasRevisions() | |
Gets if the workbook has any tracked changes
|
||
method | getInterruptMonitor() | |
method | setInterruptMonitor(value) | |
Gets and sets the interrupt monitor. | ||
method | isDigitallySigned() | |
Indicates if this spreadsheet is digitally signed.
|
||
method | isLicensed() | |
Indicates whether license is set.
|
||
method | isWorkbookProtectedWithPassword() | |
Indicates whether structure or window is protected with password.
|
||
method | getRibbonXml() | |
method | setRibbonXml(value) | |
Gets and sets the XML file that defines the Ribbon UI. | ||
method | getSettings() | |
Represents the workbook settings.
|
||
method | getTheme() | |
Gets the theme name.
|
||
method | getVbaProject() | |
Gets the |
||
method | getWorksheets() | |
Gets the |
Method Summary | ||
---|---|---|
method | acceptAllRevisions() | |
Accepts all tracked changes in the workbook.
|
||
method | addDigitalSignature(digitalSignatureCollection) | |
Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
|
||
method | calculateFormula() | |
Calculates the result of formulas.
|
||
method | calculateFormula(ignoreError) | |
Calculates the result of formulas.
|
||
method | calculateFormula(options) | |
Calculating formulas in this workbook.
|
||
method | changePalette(color, index) | |
Changes the palette for the spreadsheet in the specified index.
|
||
method | closeAccessCache(opts) | |
Closes the session that uses caches to access data.
|
||
method | combine(secondWorkbook) | |
Combines another Workbook object.
|
||
method | copy(source) | |
Copies data from a source Workbook object.
|
||
method | copy(source, copyOptions) | |
Copies another Workbook object.
|
||
method | copyTheme(source) | |
Copies the theme from another workbook.
|
||
method | createBuiltinStyle(type) | |
Creates built-in style by given type.
|
||
method | createCellsColor() | |
Creates a |
||
method | createStyle() | |
Creates a new style.
|
||
static method | createWorkbookFromBytes(byte_array) | |
Initializes a new instance of the |
||
static method | createWorkbookFromBytes(byte_array, loadOptions) | |
Initializes a new instance of the |
||
method | customTheme(themeName, colors) | |
Customs the theme.
|
||
method | dispose() | |
Performs application-defined tasks associated with freeing, releasing, or
resetting unmanaged resources.
|
||
method | exportXml(mapName, stream) | |
Export XML data linked by the specified XML map.
|
||
method | exportXml(mapName, path) | |
Export XML data linked by the specified XML map.
|
||
method | getDigitalSignature() | |
Gets digital signature from file.
|
||
method | getFonts() | |
Gets all fonts in the style pool.
|
||
method | getMatchingColor(rawColor) | |
Find best matching Color in current palette.
|
||
method | getNamedStyle(name) | |
Gets the named style in the style pool.
|
||
method | getStyleInPool(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.
|
||
method | getThemeColor(type) | |
Gets theme color.
|
||
method | hasExernalLinks() | |
Indicates whether this workbook contains external links to other data sources.
|
||
method | importXml(stream, sheetName, row, col) | |
Imports/Updates an XML data file into the workbook.
|
||
method | importXml(url, sheetName, row, col) | |
Imports/Updates an XML data file into the workbook.
|
||
method | isColorInPalette(color) | |
Checks if a color is in the palette for the spreadsheet.
|
||
method | parseFormulas(ignoreError) | |
Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.
|
||
method | protect(protectionType, password) | |
Protects a workbook.
|
||
method | protectSharedWorkbook(password) | |
Protects a shared workbook.
|
||
method | refreshDynamicArrayFormulas(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.
|
||
method | refreshDynamicArrayFormulas(calculate, copts) | |
Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data)
|
||
method | removeDigitalSignature() | |
Removes digital signature from this spreadsheet.
|
||
method | removeExternalLinks() | |
Removes all external links in the workbook.
|
||
method | removeMacro() | |
Removes VBA/macro from this spreadsheet.
|
||
method | removePersonalInformation() | |
Removes personal information.
|
||
method | removeUnusedStyles() | |
Remove all unused styles.
|
||
method | replace(placeHolder, newValue) | |
Replaces a cell's value with a new double.
|
||
method | replace(placeHolder, newValue) | |
Replaces a cell's value with a new integer.
|
||
method | replace(placeHolder, newValue) | |
Replaces a cell's value with a new string.
|
||
method | replace(placeHolder, newValue, options) | |
Replaces a cell's value with a new string.
|
||
method | replace(placeHolder, newValues, isVertical) | |
Replaces a cell's value with a new string array.
|
||
method | save(fileName) | |
Save the workbook to the disk.
|
||
method | save(fileName, saveOptions) | |
Saves the workbook to the disk.
|
||
method | save(fileName, saveFormat) | |
Saves the workbook to the disk.
|
||
method | saveToBytes(saveFormat) | |
Save the workbook to a byte array.
|
||
method | saveToBytes(saveOptions) | |
Save the workbook to a byte array.
|
||
method | setDigitalSignature(digitalSignatureCollection) | |
Sets digital signature to an spreadsheet file (Excel2007 and later).
|
||
method | setEncryptionOptions(encryptionType, keyLength) | |
Set Encryption Options.
|
||
method | setThemeColor(type, color) | |
Sets the theme color
|
||
method | startAccessCache(opts) | |
Starts the session that uses caches to access data.
|
||
method | unprotect(password) | |
Unprotects a workbook.
|
||
method | unprotectSharedWorkbook(password) | |
Unprotects a shared workbook.
|
||
method | updateCustomFunctionDefinition(definition) | |
Updates definition of custom functions.
|
||
method | updateLinkedDataSource(externalWorkbooks) | |
If this workbook contains external links to other data source,
Aspose.Cells will attempt to retrieve the latest data from give sources.
|
Workbook()
Example:
The following code shows how to use the Workbook constructor to create and initialize a new instance of the class.import jpype import asposecells jpype.startJVM() from asposecells.api import * workbook = Workbook()
Workbook(fileFormatType)
fileFormatType: int
- A Example:
The following code shows how to use the Workbook constructor to create and initialize a new instance of the class.import jpype import asposecells jpype.startJVM() from asposecells.api import * workbook = Workbook(FileFormatType.XLSX)
Workbook(file)
file: String
- The file name.Workbook(file, loadOptions)
file: String
- The file name.loadOptions: LoadOptions
- The load optionsWorkbookSettings getSettings()
WorksheetCollection getWorksheets()
boolean isLicensed()
Color[] getColors()
int getCountOfStylesInPool()
Style getDefaultStyle() / setDefaultStyle(value)
Example:
The following code creates and instantiates a new Workbook and sets a default Style to it.workbook = Workbook() defaultStyle = workbook.getDefaultStyle() defaultStyle.getFont().setName("Tahoma") workbook.setDefaultStyle(defaultStyle)
boolean isDigitallySigned()
boolean isWorkbookProtectedWithPassword()
VbaProject getVbaProject()
boolean hasMacro()
boolean hasRevisions()
String getFileName() / setFileName(value)
CellsDataTableFactory getCellsDataTableFactory()
DataSorter getDataSorter()
String getTheme()
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:
workbook = Workbook() doc = workbook.getBuiltInDocumentProperties().get("Author") doc.setValue("John Smith")
CustomDocumentPropertyCollection getCustomDocumentProperties()
Example:
workbook = Workbook() workbook.getCustomDocumentProperties().add("Checked by", "Jane")
int getFileFormat() / setFileFormat(value)
AbstractInterruptMonitor getInterruptMonitor() / setInterruptMonitor(value)
ContentTypePropertyCollection getContentTypeProperties()
CustomXmlPartCollection getCustomXmlParts()
DataMashup getDataMashup()
String getRibbonXml() / setRibbonXml(value)
String getAbsolutePath() / setAbsolutePath(value)
ExternalConnectionCollection getDataConnections()
parseFormulas(ignoreError)
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.startAccessCache(opts)
opts: int
- A closeAccessCache(opts)
opts: int
- A save(fileName, saveFormat)
fileName: String
- The file name.saveFormat: int
- A Example:
workbook = Workbook() sheets = workbook.getWorksheets() cells = sheets.get(0).getCells() cells.get("A1").putValue("Hello world!") workbook.save("Book1.xls", SaveFormat.EXCEL_97_TO_2003)
save(fileName)
fileName: String
- save(fileName, saveOptions)
fileName: String
- The file name.saveOptions: SaveOptions
- The save options.removeUnusedStyles()
Style createStyle()
Style createBuiltinStyle(type)
type: int
- A CellsColor createCellsColor()
int replace(placeHolder, newValue)
placeHolder: String
- Cell placeholdernewValue: String
- String value to replaceExample:
workbook = Workbook() workbook.replace("AnOldValue", "NewValue")
int replace(placeHolder, newValue)
placeHolder: String
- Cell placeholdernewValue: int
- Integer value to replaceExample:
workbook = Workbook() newValue = 100 workbook.replace("AnOldValue", newValue)
int replace(placeHolder, newValue)
placeHolder: String
- Cell placeholdernewValue: float
- Double value to replaceExample:
workbook = Workbook() newValue = 100.0 workbook.replace("AnOldValue", newValue)
int replace(placeHolder, newValues, isVertical)
placeHolder: String
- Cell placeholdernewValues: String[]
- String array to replaceisVertical: boolean
- True - Vertical, False - HorizontalExample:
import jpype import asposecells jpype.startJVM() from asposecells.api import * workbook = Workbook("Book2.xlsx") workbook.replace("OldString", ["Tom", "Alice", "Jerry"], True)
int replace(placeHolder, newValue, options)
placeHolder: String
- Cell placeholdernewValue: String
- String value to replaceoptions: ReplaceOptions
- The replace optionscopy(source, copyOptions)
source: Workbook
- Source Workbook object.copyOptions: CopyOptions
- The options of copying other workbook.copy(source)
source: Workbook
- Source Workbook object.combine(secondWorkbook)
secondWorkbook: Workbook
- Another Workbook object.Style getStyleInPool(index)
index: int
- The index.Font[] getFonts()
Style getNamedStyle(name)
name: String
- name of the stylechangePalette(color, index)
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 |
color: Color
- Color structure.index: int
- Palette index, 0 - 55.boolean isColorInPalette(color)
color: Color
- Color structure.calculateFormula()
calculateFormula(ignoreError)
ignoreError: boolean
- Indicates if hide the error in calculating formulas. The error may be unsupported function, external links, etc.calculateFormula(options)
options: CalculationOptions
- Options for calculationrefreshDynamicArrayFormulas(calculate)
calculate: boolean
- Whether calculates and updates cell values for those dynamic array formulasrefreshDynamicArrayFormulas(calculate, copts)
calculate: boolean
- Whether calculates and updates cell values for those dynamic array formulascopts: CalculationOptions
- The options for calculating formulasColor getMatchingColor(rawColor)
rawColor: Color
- Raw color.setEncryptionOptions(encryptionType, keyLength)
encryptionType: int
- A keyLength: int
- The key length.protect(protectionType, password)
protectionType: int
- A password: String
- Password to protect the workbook.protectSharedWorkbook(password)
password: String
- Password to protect the workbook.unprotect(password)
password: String
- Password to unprotect the workbook.unprotectSharedWorkbook(password)
password: String
- Password to unprotect the workbook.removeMacro()
removeDigitalSignature()
acceptAllRevisions()
removeExternalLinks()
Color getThemeColor(type)
type: int
- A setThemeColor(type, color)
type: int
- A color: Color
- the theme colorcustomTheme(themeName, 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: String
- The theme namecolors: Color[]
- The theme colorscopyTheme(source)
source: Workbook
- Source workbook.boolean hasExernalLinks()
updateCustomFunctionDefinition(definition)
definition: CustomFunctionDefinition
- Special definition of custom functions for user's special requirement.updateLinkedDataSource(externalWorkbooks)
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 importXml(url, sheetName, row, col)
url: String
- the url/path of the xml file.sheetName: String
- the destination sheet name.row: int
- the destination rowcol: int
- the destination columnimportXml(stream, sheetName, row, col)
stream: InputStream
- the xml file stream.sheetName: String
- the destination sheet name.row: int
- the destination row.col: int
- the destination column.exportXml(mapName, path)
mapName: String
- name of the XML map that need to be exportedpath: String
- the export pathexportXml(mapName, stream)
mapName: String
- name of the XML map that need to be exportedstream: OutputStream
- the export streamsetDigitalSignature(digitalSignatureCollection)
digitalSignatureCollection: DigitalSignatureCollection
- addDigitalSignature(digitalSignatureCollection)
digitalSignatureCollection: DigitalSignatureCollection
- DigitalSignatureCollection getDigitalSignature()
removePersonalInformation()
dispose()
static createWorkbookFromBytes(byte_array)
byte_array: bytes
- The byte arrayExample:
import jpype import asposecells jpype.startJVM() from asposecells.api import * with open('Book2.xlsx', 'rb') as f: wb = Workbook.createWorkbookFromBytes(f.read()) wb.save('result.xlsx') jpype.shutdownJVM()
static createWorkbookFromBytes(byte_array, loadOptions)
byte_array: bytes
- The byte arrayloadOptions: LoadOptions
- The load optionsExample:
import jpype import asposecells jpype.startJVM() from asposecells.api import * loadOptions = LoadOptions() with open('Book2.xlsx', 'rb') as f: wb = Workbook.createWorkbookFromBytes(f.read(), loadOptions=loadOptions) wb.save('result.xlsx') jpype.shutdownJVM()
saveToBytes(saveOptions)
saveOptions: SaveOptions
- The save optionsExample:
import jpype import asposecells jpype.startJVM() from asposecells.api import * wb = Workbook("Book2.xlsx") saveOptions = XlsSaveOptions() with open("wb.xls", "wb") as w: byte_array = wb.saveToBytes(saveOptions) w.write(byte_array) jpype.shutdownJVM()
saveToBytes(saveFormat)
saveFormat: int
- The save file format typeExample:
import jpype import asposecells jpype.startJVM() from asposecells.api import * wb = Workbook("Book2.xlsx") with open("wb.xlsx", "wb") as w: byte_array = wb.saveToBytes(SaveFormat.XLSX) w.write(byte_array) jpype.shutdownJVM()