Workbook class

Workbook class

Represents a root object to create an Excel spreadsheet.

The Workbook type exposes the following members:

Constructors

ConstructorDescription
initInitializes a new instance of the Workbook class.
initInitializes a new instance of the Workbook class.
initInitializes a new instance of the Workbook class and open a file.
initInitializes a new instance of the Workbook class and open a stream.
initInitializes a new instance of the Workbook class and open a file.
initInitializes 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
saveSaves the workbook to the disk.
saveSave the workbook to the disk.
saveSaves the workbook to the disk.
saveSaves the workbook to the stream.
saveSaves the workbook to the stream.
replaceReplaces a cell’s value with a new string.
replaceReplaces a cell’s value with a new integer.
replaceReplaces a cell’s value with a new double.
replaceReplaces a cell’s value with a new string array.
replaceReplaces cells’ values with an integer array.
replaceReplaces cells’ values with a double array.
replaceReplaces cells’ values with new data.
replaceReplaces cells’ values with new data.
replaceReplaces a cell’s value with a new string.
copyCopies another Workbook object.
copyCopies data from a source Workbook object.
calculate_formulaCalculates the result of formulas.
calculate_formulaCalculates the result of formulas.
calculate_formulaCalculating formulas in this workbook.
refresh_dynamic_array_formulasRefreshes 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_formulasRefreshes dynamic array formulas(spill into new range of neighboring cells according to current data)
import_xmlImports/Updates an XML data file into the workbook.
import_xmlImports/Updates an XML data file into the workbook.
export_xmlExport XML data linked by the specified XML map.
export_xmlExport XML data.
parse_formulasParses all formulas which have not been parsed when they were loaded from template file or set to a cell.
start_access_cacheStarts the session that uses caches to access data.
close_access_cacheCloses the session that uses caches to access data.
remove_unused_stylesRemove all unused styles.
create_styleCreates a new style.
create_builtin_styleCreates built-in style by given type.
create_cells_colorCreates a CellsColor object.
combineCombines another Workbook object.
get_style_in_poolGets 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_fontsGets all fonts in the style pool.
get_named_styleGets the named style in the style pool.
change_paletteChanges the palette for the spreadsheet in the specified index.
is_color_in_paletteChecks if a color is in the palette for the spreadsheet.
get_matching_colorFind best matching Color in current palette.
set_encryption_optionsSet Encryption Options.
protectProtects a workbook.
protect_shared_workbookProtects a shared workbook.
unprotectUnprotects a workbook.
unprotect_shared_workbookUnprotects a shared workbook.
remove_macroRemoves VBA/macro from this spreadsheet.
remove_digital_signatureRemoves digital signature from this spreadsheet.
accept_all_revisionsAccepts all tracked changes in the workbook.
remove_external_linksRemoves all external links in the workbook.
get_theme_colorGets theme color.
set_theme_colorSets the theme color
custom_themeCustoms the theme.
copy_themeCopies the theme from another workbook.
has_exernal_linksIndicates whether this workbook contains external links to other data sources.
update_custom_function_definitionUpdates definition of custom functions.
update_linked_data_sourceIf this workbook contains external links to other data source,
Aspose.Cells will attempt to retrieve the latest data from give sources.
set_digital_signatureSets digital signature to an spreadsheet file (Excel2007 and later).
add_digital_signatureAdds digital signature to an OOXML spreadsheet file (Excel2007 and later).
get_digital_signatureGets digital signature from file.
remove_personal_informationRemoves personal information.

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