foprel / openpyxl-dictreader Goto Github PK
View Code? Open in Web Editor NEWA simple module that reads openpyxl worksheets like Python's native csv DictReader
License: Other
A simple module that reads openpyxl worksheets like Python's native csv DictReader
License: Other
Latest PR to implement skipping of blank lines caused unexpected and unstable behaviour. The __next__()
method of the DictReader
class needs to be restructured to skip blank lines. Possibly give users the options to determine whether to skip blank lines or not by adding a kwarg to the constructor.
In requirements.txt, openpyxl==3.0.3 is a dependency; that's a two-year-old version of openpyxl (current is 3.0.9). Installing openpyxl_dictreader in an environment that also uses openpyxl causes roll-back of openpyxl to that old version.
It appears that openpyxl_dictreader also works with the current version of openpyxl, 3.0.9.
Could requirements.txt please be changed to allow openpyxl==3.0.*, or some other appropriately-large version range?
(It looks like some of the other dependencies in requirements.txt may not be needed, by the way)
Is there any use-case of DictReader where the default value of None for worksheet does not result in an exception? There always needs to be a worksheet specified. So remove the default value and make it the parameter immediately following filename:
def __init__(self, filename, worksheet, fieldnames=None, restval=None, restkey=None, *args, **kwargs):
btw: I'm finding your module very useful!
Your setup.py is not correctly configured for a single module project. You're using a packages
keyword in setup()
function, but your project doesn't contain any packages.
You should use py_modules=["dictreader"]
instead.
Also please consider changing the module name from dictreader
to something more specific, for example openpyxl_dictreader
, or just pyxl_dictreader
. A generic dictreader
could conflict with something else (I don't have any examples of conflicting packages at the moment though).
The load_workbook method takes several optional keyword arguments:
In order to read the values from Excel cells with formulas, data_only needs to be True. Others may be necessary as well.
I suggest passing kwargs (expanded with the ** operator) to load_workbook:
self.wb = load_workbook(filename, **kwargs)
Frank,
Would you be interested in an openpyxl dictionary writer to go with the reader?
The design of the interface would mimic the interface of the csv tool for writing dictionaries, similar to the reader.
dwriter = DictWriter(filename, fieldnames, worksheet="", restval="", extrasaction="raise", write_only=False, iso_dates=False)
restval
and extrasaction
are arguments from csv.DictWriter()
.
write_only
and iso_dates
are arguments from openpyxl's Workbook()
.
A typical usage would look like:
from openpyxl_dictreader import DictWriter
fieldnames = ["First Name", "Last Name"]
troupe = [
dict(zip(fieldnames, ["Eric", "Idle"])),
dict(zip(fieldnames, ["Graham", "Chapman"])),
dict(zip(fieldnames, ["John", "Cleese"])),
]
dwriter = DictWriter("names.xlsx", fieldnames)
dwriter.writeheader()
for player in troupe:
dwriter.writerow(player)
dwriter.save()
Good afternoon. Thanks for the helpful script! I don't understand one piece of code in it:
while row == []:
row = next(iter(self.ws_list))
Firstly, I cannot imagine in what case the program should be included in this part of the code.
And secondly, I cannot understand where the variable self.ws_list
comes from.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.