workbook.Workbook
Workbook is the container for all other parts of the document.
Usage
workbook.Workbook()Attributes
| Name | Description |
|---|---|
| active | Get the currently active sheet or None |
| chartsheets | A list of Chartsheets in this workbook |
| keep_formula_cache | True when formulas and cached values were dual-loaded. |
| mime_type | The mime type is determined by whether a workbook is a template or |
| named_styles | List available named styles |
| sheetnames | Returns the list of the names of worksheets in this workbook. |
| style_names | List of named styles |
| worksheets | A list of sheets in this workbook |
active
Get the currently active sheet or None
active
chartsheets
A list of Chartsheets in this workbook
chartsheets
keep_formula_cache
True when formulas and cached values were dual-loaded.
keep_formula_cache
mime_type
The mime type is determined by whether a workbook is a template or
mime_type
not and whether it contains macros or not. Excel requires the file extension to match but fastpyxl does not enforce this.
named_styles
List available named styles
named_styles
sheetnames
Returns the list of the names of worksheets in this workbook.
sheetnames
Names are returned in the worksheets order.
style_names
List of named styles
style_names
worksheets
A list of sheets in this workbook
worksheets
Methods
| Name | Description |
|---|---|
| __getitem__() | Returns a worksheet by its name. |
| add_named_style() | Add a named style |
| close() | Close workbook file if open. Only affects read-only, indexed, and |
| copy_worksheet() | Copy an existing worksheet in the current workbook |
| create_named_range() | Create a new named_range on a worksheet |
| create_sheet() | Create a worksheet (at an optional index). |
| get_index() | Return the index of the worksheet. |
| get_sheet_by_name() | Returns a worksheet by its name. |
| index() | Return the index of a worksheet. |
| materialize_pending_style_components() | Register shared style parts for styleable from deferred assignments. |
| move_sheet() | Move a sheet or sheetname |
| remove() | Remove worksheet from this workbook. |
| remove_sheet() | Remove worksheet from this workbook. |
| save() |
Save the current workbook under the given filename.
|
__getitem__()
Returns a worksheet by its name.
Usage
__getitem__(key)Parameters
name: string- the name of the worksheet to look for
add_named_style()
Add a named style
Usage
add_named_style(style)close()
Close workbook file if open. Only affects read-only, indexed, and
Usage
close()write-only modes.
copy_worksheet()
Copy an existing worksheet in the current workbook
Usage
copy_worksheet(from_worksheet)This function cannot copy worksheets between workbooks. worksheets can only be copied within the workbook that they belong
Parameters
from_worksheet- the worksheet to be copied from
Returns
- copy of the initial worksheet
create_named_range()
Create a new named_range on a worksheet
Usage
create_named_range(name, worksheet=None, value=None, scope=None)create_sheet()
Create a worksheet (at an optional index).
Usage
create_sheet(title=None, index=None)Parameters
title: str = None-
optional title of the sheet
index: int = None- optional position at which the sheet will be inserted
get_index()
Return the index of the worksheet.
Usage
get_index(worksheet)get_sheet_by_name()
Returns a worksheet by its name.
Usage
get_sheet_by_name(name)Parameters
name: string- the name of the worksheet to look for
index()
Return the index of a worksheet.
Usage
index(worksheet)materialize_pending_style_components()
Register shared style parts for styleable from deferred assignments.
Usage
materialize_pending_style_components(styleable)Styling attributes on cells and dimensions defer pushing fonts, fills, borders, number formats, alignments, protections, and named styles into the workbook until this method runs or until ~fastpyxl.styles.styleable.StyleableObject.style_id is read.
Saving a workbook calls this automatically for every standard worksheet, in the same order as sheet XML serialization, so shared-table indices stay stable. Write-only streams still resolve styles when each row is written.
move_sheet()
Move a sheet or sheetname
Usage
move_sheet(sheet, offset=0)remove()
Remove worksheet from this workbook.
Usage
remove(worksheet)remove_sheet()
Remove worksheet from this workbook.
Usage
remove_sheet(worksheet)save()
Save the current workbook under the given filename.
Usage
save(filename)Use this function instead of using an ExcelWriter.
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 fastpyxl.shared.exc.WorkbookAlreadySaved exception.