Workbook
paper-xlsx 0.2.1 API reference
Workbook is the container for all other parts of the document.
Workbook(write_only=False, iso_dates=False)Attributes
active
attributeactiveGet the currently active sheet or None
:type: openpyxl.worksheet.worksheet.Worksheet
calculation
attributecalculation= CalcProperties()chartsheets
attributechartsheetsA list of Chartsheets in this workbook
:type: list of openpyxl.chartsheet.chartsheet.Chartsheet
code_name
attributecode_name= Nonecustom_doc_props
attributecustom_doc_props= CustomPropertyList()data_only
attributedata_onlydefined_names
attributedefined_names= DefinedNameDict()encoding
attributeencoding= 'utf-8'epoch
attributeepochexcel_base_date
attributeexcel_base_dateis_template
attributeis_template= Falseiso_dates
attributeiso_dates= iso_datesloaded_theme
attributeloaded_theme= Nonemime_type
attributemime_typeThe mime type is determined by whether a workbook is a template or not and whether it contains macros or not. Excel requires the file extension to match but openpyxl does not enforce this.
named_styles
attributenamed_stylesList available named styles
path
attributepath= '/xl/workbook.xml'preserve
attributepreserveTrue when this workbook was loaded with preserve=True: the
original package bytes are the source of truth and save is a
lossless splice of recorded edits into them.
properties
attributeproperties= DocumentProperties()read_only
attributeread_onlyrels
attributerels= RelationshipList()security
attributesecurity= DocumentSecurity()shared_strings
attributeshared_strings= IndexedList()sheetnames
attributesheetnamesReturns the list of the names of worksheets in this workbook.
Names are returned in the worksheets order.
:type: list of strings
strict_protection
attributestrict_protection= Falsestyle_names
attributestyle_namesList of named styles
template
attributetemplate= Falsevba_archive
attributevba_archive= Noneviews
attributeviews= [BookView()]worksheets
attributeworksheetsA list of sheets in this workbook
:type: list of openpyxl.worksheet.worksheet.Worksheet
write_only
attributewrite_onlyFunctions
__contains__
func__contains__(key)paramkey__delitem__
func__delitem__(key)paramkey__getitem__
func__getitem__(key)Returns a worksheet by its name.
paramkey__iter__
func__iter__()add_named_style
funcadd_named_style(style)Add a named style
paramstyleclose
funcclose()Close workbook file if open. Only affects read-only and write-only modes.
copy_worksheet
funccopy_worksheet(from_worksheet)Copy an existing worksheet in the current workbook
.. warning:: This function cannot copy worksheets between workbooks. worksheets can only be copied within the workbook that they belong
paramfrom_worksheetthe worksheet to be copied from
Returns
Not annotatedcopy of the initial worksheet
create_chartsheet
funccreate_chartsheet(title=None, index=None)paramtitle= Noneparamindex= Nonecreate_named_range
funccreate_named_range(name, worksheet=None, value=None, scope=None)Create a new named_range on a worksheet
paramnameparamworksheet= Noneparamvalue= Noneparamscope= Nonecreate_sheet
funccreate_sheet(title=None, index=None)Create a worksheet (at an optional index).
paramtitlestr= Noneoptional title of the sheet
paramindexint= Noneoptional position at which the sheet will be inserted
get_index
funcget_index(worksheet)Return the index of the worksheet.
paramworksheetget_sheet_by_name
funcget_sheet_by_name(name)Returns a worksheet by its name.
paramnamestringthe name of the worksheet to look for
get_sheet_names
funcget_sheet_names()index
funcindex(worksheet)Return the index of a worksheet.
paramworksheetmove_sheet
funcmove_sheet(sheet, offset=0)Move a sheet or sheetname
paramsheetparamoffset= 0remove
funcremove(worksheet)Remove worksheet from this workbook.
Under preserve mode a loaded sheet's removal runs the reference audit first. The package-part cascade happens at save.
paramworksheetremove_sheet
funcremove_sheet(worksheet)Remove worksheet from this workbook.
paramworksheetsave
funcsave(filename, *, allow_formula_loss=False, receipt=False)Save the current workbook under the given filename.
Use this function instead of using an ExcelWriter.
paramfilenameparamallow_formula_loss= Falsea workbook loaded with data_only=True holds cached values instead of formulas, so saving destroys formulas. Under preserve mode such a save refuses unless this flag is set (and even then only cells you actually edited lose their formulas — untouched cells keep them in the original bytes). On the stock path the flag silences the loud warning.
paramreceipt= Falsepreserve mode only — return an openpyxl.preserve.receipts.EditReceipt comparing the saved file against the AS-LOADED source bytes. NOTE: after several saves from one session the receipt is cumulative — it describes the session, not the last call. .. warning:: When creating your workbook using write_only set to True, you will only be able to call this function once. Subsequent attempts to modify or save the file will raise an openpyxl.shared.exc.WorkbookAlreadySaved exception.
search
funcsearch(text_or_regex, *, regex=False, values=True, formulas=True)Find text across the workbook (paper-xlsx).
Returns [{"address", "match", "kind"}, ...] where kind is
"value" or "formula".
paramtext_or_regexparamregex= Falseparamvalues= Trueparamformulas= Trueset_pivot_refresh_on_load
funcset_pivot_refresh_on_load(pivots=None, *, all=False)Request refresh-on-load for named pivots or explicitly all pivots.
Pivot names may be sheet-qualified ("Sheet!PivotName"). Multiple
pivots that share a cache necessarily share this cache-level setting.
parampivots= Noneparamall= Falsevalidate
funcvalidate()Run the preserve save planner without assembling an archive.