xl
Read and Write Excel Files.
The vendored xlrd reads both .xlsx and .xls workbooks and xlsxwriter writes them, on IronPython and CPython alike, so both engines return the same values.
Functions:
load(xlfile, sheets=[], columns=[], datatype=None, headers=True)
Read data from Excel file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xlfile
|
str
|
full path of the excel file to read |
required |
sheets
|
list
|
worksheets to read. Defaults to all the sheets. |
[]
|
columns
|
list
|
Names to give to the columns. It builds a dictionary for each row with the column name and value. If none given (default), it returns a simple list of values. |
[]
|
datatype
|
type
|
Type of the data. Defaults to None. |
None
|
headers
|
bool
|
Whether to use the first row as headers. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Excel data grouped by worksheet.
Each worksheet is a dictionary with |
Note
The file is read into memory and closed before parsing, so it can be renamed or deleted as soon as this returns. Opening it by path would leave xlrd's zip handle on .xlsx files open until IronPython's GC runs.
Source code in pyrevitlib/pyrevit/interop/xl.py
dump(xlfile, datadict)
Write data to Excel file.
Creates a worksheet for each item of the input dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xlfile
|
str
|
full path of the target excel file |
required |
datadict
|
dict[str, list]
|
dictionary of worksheets names and data |
required |