API reference¶
The importable Python surface: write_xlsx, the package's one public
function, which the core discovers through the
bankstatementparser.writers entry point. Generated from the
docstrings by mkdocstrings.
bankstatementparser_writer_xlsx.writer
¶
Excel .xlsx writer for parsed bank-statement data.
This module turns the output of a
bankstatementparser
parser into a polished Excel workbook via
openpyxl.
The single public entry point is :func:write_xlsx, which accepts any
of three input shapes and normalises them to a flat, rectangular table:
- a :class:
pandas.DataFrame(as returned by a parser's.parse()), - a list of :class:
bankstatementparser.Transactionobjects, or - a list of plain
dictrow records.
The resulting workbook has a bold header row followed by one row per
record on the Transactions sheet, with column widths auto-sized for
readability. An optional summary mapping (e.g. the output of a
parser's get_summary()) is written to a second Summary sheet as
key/value rows.
Value coercion¶
Cells must hold spreadsheet-friendly values, so the writer coerces the rich Python types the parser emits:
- :class:
decimal.Decimalis written as afloat(Excel has no decimal type; floats sort and aggregate natively in spreadsheets). - :class:
datetime.dateand :class:datetime.datetimeare written unchanged — openpyxl serialises them as native Excel date cells. - Every other value is written as-is when openpyxl accepts it
(
str,int,float,bool,None) and otherwise stringified viastr().
write_xlsx(data, path, *, sheet_name='Transactions', summary=None)
¶
Write parsed bank-statement data to a .xlsx workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The records to serialise. One of:
An empty list (or empty DataFrame) is accepted and writes a header-only sheet (header omitted entirely when no columns can be determined). |
required |
path
|
str | Path
|
The output |
required |
sheet_name
|
str
|
The title of the sheet holding the transaction rows.
Defaults to |
'Transactions'
|
summary
|
Mapping[str, Any] | None
|
Optional mapping (e.g. a parser's |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
The |
Path
|
class: |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If |
Source code in bankstatementparser_writer_xlsx/writer.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |