A special class that reads Excel strings and implements access to them through a dictionary: {Column name: value}
. Implemented on the principle of generators through the __next__
method.
Is able to:
- You can define your own fields using the
fieldnames
attribute. If there are more or less own fields, it fillsNone
empty spaces, similar tocsv.DictReader ()
. - You can set the string with which to read the column names. In this case, it will start displaying rows after the selected row of column names.
- Fully annotated.
The example works in conjunction with the file test.xlsx
.
from dict_reader import XlDictReader
from openpyxl import load_workbook
wb = load_workbook('test.xlsx')
d = XlDictReader(wb['main'])
for r in d:
v = r["column 1"]
print(f'{v.value} - {d.line_num}')
The result of the script:
>>> 1 - 2
>>> None - 3
>>> 12.5 - 4
>>> 2021-02-01 00:00:00 - 5
>>> None - 6
>>> exit - 7
- openpyxl 3.0.8