API Reference¶
Tools for creating and formatting spreadsheets with Python and OpenPyXL.
Functions:
|
Add CSV file to xlsx file as a new worksheet. |
|
Returns an estimate of the width of the column in pixels, given the size in centimeters. |
|
Format the alignment of the header rows of a worksheet. |
|
Format columns of an xlsx worksheet. |
|
Generate property lists from integer values. |
- append_to_xlsx(csv_input_file, xlsx_output_file, sheet_title=None, separator=',', overwrite=False, to_floats=False, encoding='UTF-8')[source]¶
Add CSV file to xlsx file as a new worksheet.
- Parameters
csv_input_file (
Union
[str
,Path
,PathLike
]) – filepath of CSV file.xlsx_output_file (
Union
[str
,Path
,PathLike
]) – filepath of xlsx file.sheet_title (
Optional
[str
]) – Title of sheet to append. Default is the value ofcsv_input_file
.separator (
str
) – Separator for reading CSV file. Default','
.overwrite (
bool
) – Whether to overwrite the xlsx output file (i.e. create a new file containing just the new sheet). DefaultFalse
.to_floats (
bool
) – Whether to read strings with thousand separators as floats. DefaultFalse
.encoding (
str
) – The encoding to read the file as. Default'UTF-8'
.
- col_width_from_cm(width)[source]¶
Returns an estimate of the width of the column in pixels, given the size in centimeters.
- Parameters
width (
float
) – The width in centimeters.
New in version 0.2.0.
- Return type
- format_header(ws, alignment_list, start_row=1, end_row=1)[source]¶
Format the alignment of the header rows of a worksheet.
- Parameters
- format_sheet(ws, number_format_list=None, width_list=None, alignment_list=None)[source]¶
Format columns of an xlsx worksheet.
- Parameters
ws (
openpyxl.worksheet.worksheet.Worksheet
.) – The worksheet to format.number_format_list (
Optional
[Dict
[str
,str
]]) – dictionary of number format strings for each column letter. DefaultNone
.width_list (
Optional
[Dict
[str
,float
]]) – dictionary of widths for each column letter. DefaultNone
.alignment_list (
Optional
[Dict
[str
,str
]]) – dictionary of alignments (left
,right
, orcenter
) for each column letter. DefaultNone
.