Skip to content

Excel file reader inspired by csv.DistReader.

License

Notifications You must be signed in to change notification settings

ikocs/openpyxl-dictreader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Excel sheet reader to dictionary

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.

🇷🇺 Russian README

Is able to:

  • You can define your own fields using the fieldnames attribute. If there are more or less own fields, it fills None 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.

Implementation example

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

Libraries used

  • openpyxl 3.0.8

About

Excel file reader inspired by csv.DistReader.

Resources

License

Stars

Watchers

Forks

Languages