Workbook class

Workbook class

Represents a root object to create an Excel spreadsheet.

The Workbook type exposes the following members:

Constructors

ConstructorDescription
__init__(self)Initializes a new instance of the Workbook class.
__init__(self, file_format_type)Initializes a new instance of the Workbook class.
__init__(self, file)Initializes a new instance of the Workbook class and open a file.
__init__(self, stream)Initializes a new instance of the Workbook class and open a stream.
__init__(self, file, load_options)Initializes a new instance of the Workbook class and open a file.
__init__(self, stream, load_options)Initializes a new instance of the Workbook class and open stream.

Properties

PropertyDescription
settingsRepresents the workbook settings.
worksheetsGets the WorksheetCollection collection in the spreadsheet.
is_licensedIndicates whether license is set.
colorsReturns colors in the palette for the spreadsheet.
count_of_styles_in_poolGets number of the styles in the style pool.
default_styleGets or sets the default Style object of the workbook.
is_digitally_signedIndicates if this spreadsheet is digitally signed.
is_workbook_protected_with_passwordIndicates whether structure or window is protected with password.
vba_projectGets the Workbook.vba_project in a spreadsheet.
has_macroIndicates if this spreadsheet contains macro/VBA.
has_revisionsGets if the workbook has any tracked changes
file_nameGets and sets the current file name.
cells_data_table_factoryGets the factory for building ICellsDataTable from custom objects
data_sorterGets a DataSorter object to sort data.
themeGets the theme name.
built_in_document_propertiesReturns a DocumentProperty collection that represents all the built-in document properties of the spreadsheet.
custom_document_propertiesReturns a DocumentProperty collection that represents all the custom document properties of the spreadsheet.
file_formatGets and sets the file format.
interrupt_monitorGets and sets the interrupt monitor.
content_type_propertiesGets the list of ContentTypeProperty objects in the workbook.
custom_xml_partsRepresents a Custom XML Data Storage Part (custom XML data within a package).
data_mashupGets mashup data.
ribbon_xmlGets and sets the XML file that defines the Ribbon UI.
absolute_pathGets and sets the absolute path of the file.
data_connectionsGets the ExternalConnection collection.
data_modelGets data model in the workbook.

Methods

MethodDescription
save(self, file_name, save_format)Saves the workbook to the disk.
save(self, file_name)Save the workbook to the disk.
save(self, file_name, save_options)Saves the workbook to the disk.
save(self, stream, save_format)Saves the workbook to the stream.
save(self, stream, save_options)Saves the workbook to the stream.
create_style(self)Creates a new style.
create_style(self, clone_default_style)Creates a new style.
replace(self, place_holder, new_value)Replaces a cell’s value with a new string.
replace(self, place_holder, new_value)Replaces a cell’s value with a new integer.
replace(self, place_holder, new_value)Replaces a cell’s value with a new double.
replace(self, place_holder, new_values, is_vertical)Replaces a cell’s value with a new string array.
replace(self, place_holder, new_values, is_vertical)Replaces cells’ values with an integer array.
replace(self, place_holder, new_values, is_vertical)Replaces cells’ values with a double array.
replace(self, bool_value, new_value)Replaces cells’ values with new data.
replace(self, int_value, new_value)Replaces cells’ values with new data.
replace(self, place_holder, new_value, options)Replaces a cell’s value with a new string.
copy(self, source, copy_options)Copies another Workbook object.
copy(self, source)Copies data from a source Workbook object.
calculate_formula(self)Calculates the result of formulas.
calculate_formula(self, ignore_error)Calculates the result of formulas.
calculate_formula(self, options)Calculating formulas in this workbook.
refresh_dynamic_array_formulas(self, 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.
refresh_dynamic_array_formulas(self, calculate, copts)Refreshes dynamic array formulas(spill into new range of neighboring cells according to current data)
import_xml(self, url, sheet_name, row, col)Imports/Updates an XML data file into the workbook.
import_xml(self, stream, sheet_name, row, col)Imports/Updates an XML data file into the workbook.
export_xml(self, map_name, path)Export XML data linked by the specified XML map.
export_xml(self, map_name, stream)Export XML data.
parse_formulas(self, ignore_error)Parses all formulas which have not been parsed when they were loaded from template file or set to a cell.
start_access_cache(self, opts)Starts the session that uses caches to access data.
close_access_cache(self, opts)Closes the session that uses caches to access data.
remove_unused_styles(self)Remove all unused styles.
create_builtin_style(self, type)Creates built-in style by given type.
create_cells_color(self)Creates a CellsColor object.
combine(self, second_workbook)Combines another Workbook object.
get_style_in_pool(self, 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.
get_fonts(self)Gets all fonts in the style pool.
get_named_style(self, name)Gets the named style in the style pool.
change_palette(self, color, index)Changes the palette for the spreadsheet in the specified index.
is_color_in_palette(self, color)Checks if a color is in the palette for the spreadsheet.
get_matching_color(self, raw_color)Find best matching Color in current palette.
set_encryption_options(self, encryption_type, key_length)Set Encryption Options.
protect(self, protection_type, password)Protects a workbook.
protect_shared_workbook(self, password)Protects a shared workbook.
unprotect(self, password)Unprotects a workbook.
unprotect_shared_workbook(self, password)Unprotects a shared workbook.
remove_macro(self)Removes VBA/macro from this spreadsheet.
remove_digital_signature(self)Removes digital signature from this spreadsheet.
accept_all_revisions(self)Accepts all tracked changes in the workbook.
remove_external_links(self)Removes all external links in the workbook.
get_theme_color(self, type)Gets theme color.
set_theme_color(self, type, color)Sets the theme color
custom_theme(self, theme_name, colors)Customs the theme.
copy_theme(self, source)Copies the theme from another workbook.
has_exernal_links(self)Indicates whether this workbook contains external links to other data sources.
update_custom_function_definition(self, definition)Updates definition of custom functions.
update_linked_data_source(self, external_workbooks)If this workbook contains external links to other data source,
Aspose.Cells will attempt to retrieve the latest data from give sources.
set_digital_signature(self, digital_signature_collection)Sets digital signature to an spreadsheet file (Excel2007 and later).
add_digital_signature(self, digital_signature_collection)Adds digital signature to an OOXML spreadsheet file (Excel2007 and later).
get_digital_signature(self)Gets digital signature from file.
remove_personal_information(self)Removes personal information.
close(self)Dispose() is Skipped by wrapper since Python protocol

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.

from aspose.cells import Workbook

# Open a designer file
designerFile = "designer.xls"
workbook = Workbook(designerFile)
# Set scroll bars
workbook.settings.is_h_scroll_bar_visible = False
workbook.settings.is_v_scroll_bar_visible = False
# Replace the placeholder string with new values
newInt = 100
workbook.replace("OldInt", newInt)
newString = "Hello!"
workbook.replace("OldString", newString)
workbook.save("result.xlsx")

See Also