Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
CLN: Make ExcelWriter more pluggable #4750
FIxes #4745 and makes it easier to swap in other
Basically, you can subclass
The great thing is that it should be really simple to add additional writers and relatively trivial to add additional readers by following the same format. (if, for example, we wanted to resurrect
Here's the 'interface':
You also need to register the class with
There's a tiny bit of metaclass magic to make this backwards-compatible, but it's nothing particularly complicated.
It looks fine. I'll subclass it and let you know how I get on.
Should I subclass it in another file or in excel.py?
# declare external properties you can count on book = None curr_sheet = None path = None
That is good. I was going to ask for some interface to the workbook and worksheet since that could be useful to the end user for adding additional formatting or invoking other methods on them.
How about calling them
@jmcnamara huh? You would just put whatever setup you need in your
Sure. What I meant was it that it would be useful (from my point of view) to have interfaces in the base class that would return workbook and worksheet objects that could be used to access APIs that aren't exposed by ExcelWriter.
For example, if I wanted to set a column width in an xlwt worksheet. Something like this:
writer = ExcelWriter('file.xls') df.to_excel(writer, 'Sheet1') # Access the underlying worksheet. worksheet = writer.worksheet() worksheet.col(0).width = 256 * 12 writer.save()
I just rebased this. I think it's in a pretty good state now. I could change ExcelReader slightly to do the same thing (for completeness sake) - is that worth doing right now even though we don't have any other readers in the pipeline at the moment?
The only other item is whether the formatting should be done by