Paper Office
paper-xlsxAPI reference

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

attributeactive

Get the currently active sheet or None

:type: openpyxl.worksheet.worksheet.Worksheet

calculation

attributecalculation
= CalcProperties()

chartsheets

attributechartsheets

A list of Chartsheets in this workbook

:type: list of openpyxl.chartsheet.chartsheet.Chartsheet

code_name

attributecode_name
= None

custom_doc_props

attributecustom_doc_props
= CustomPropertyList()

data_only

attributedata_only

defined_names

attributedefined_names
= DefinedNameDict()

encoding

attributeencoding
= 'utf-8'

epoch

attributeepoch

excel_base_date

attributeexcel_base_date

is_template

attributeis_template
= False

iso_dates

attributeiso_dates
= iso_dates

loaded_theme

attributeloaded_theme
= None

mime_type

attributemime_type

The 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_styles

List available named styles

path

attributepath
= '/xl/workbook.xml'

preserve

attributepreserve

True 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_only

rels

attributerels
= RelationshipList()

security

attributesecurity
= DocumentSecurity()

shared_strings

attributeshared_strings
= IndexedList()

sheetnames

attributesheetnames

Returns 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
= False

style_names

attributestyle_names

List of named styles

template

attributetemplate
= False

vba_archive

attributevba_archive
= None

views

attributeviews
= [BookView()]

worksheets

attributeworksheets

A list of sheets in this workbook

:type: list of openpyxl.worksheet.worksheet.Worksheet

write_only

attributewrite_only

Functions

__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

paramstyle

close

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_worksheet

the worksheet to be copied from

Returns

Not annotated

copy of the initial worksheet

create_chartsheet

funccreate_chartsheet(title=None, index=None)
paramtitle
= None
paramindex
= None

create_named_range

funccreate_named_range(name, worksheet=None, value=None, scope=None)

Create a new named_range on a worksheet

paramname
paramworksheet
= None
paramvalue
= None
paramscope
= None

create_sheet

funccreate_sheet(title=None, index=None)

Create a worksheet (at an optional index).

paramtitlestr
= None

optional title of the sheet

paramindexint
= None

optional position at which the sheet will be inserted

get_index

funcget_index(worksheet)

Return the index of the worksheet.

paramworksheet

get_sheet_by_name

funcget_sheet_by_name(name)

Returns a worksheet by its name.

paramnamestring

the name of the worksheet to look for

get_sheet_names

funcget_sheet_names()

index

funcindex(worksheet)

Return the index of a worksheet.

paramworksheet

move_sheet

funcmove_sheet(sheet, offset=0)

Move a sheet or sheetname

paramsheet
paramoffset
= 0

remove

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.

paramworksheet

remove_sheet

funcremove_sheet(worksheet)

Remove worksheet from this workbook.

paramworksheet

save

funcsave(filename, *, allow_formula_loss=False, receipt=False)

Save the current workbook under the given filename. Use this function instead of using an ExcelWriter.

paramfilename
paramallow_formula_loss
= False

a 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
= False

preserve 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.

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_regex
paramregex
= False
paramvalues
= True
paramformulas
= True

set_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
= None
paramall
= False

validate

funcvalidate()

Run the preserve save planner without assembling an archive.

On this page