Psychopy: openpyxl errors when using saveAsExcel methods

Created on 14 Oct 2016  Â·  7Comments  Â·  Source: psychopy/psychopy

As discussed in a previous issue (#1207), there are errors when using saveAsExcel when using openpyxl 2.4.0:

With PsychoPy 1.84.2 (and openpyxl 2.4.0), I am now getting an ImportError when trying to call saveAsExcel:
ImportError: openpyxl is required for saving files in Excel (xlsx) format, but was not found.

I did a little digging, and found that this seems to stem from line 29 in data.py:
from openpyxl.cell import get_column_letter

as far as I can tell, get_column_letter sits in openpyxl.utils.cell:
http://openpyxl.readthedocs.io/en/default/api/openpyxl.utils.cell.html#openpyxl.utils.cell.get_column_letter

Now, if I change line 29 to import from openpyxl.utils.cell instead, I don't get the ImportError anymore. However, I get a different error instead:

File "[local python path]/data.py", line 3326, in saveAsExcel:
ew = ExcelWriter(workbook=wb)
TypeError: init() takes exactly 3 arguments (2 given)

bug effort low library waiting for feedback

All 7 comments

and the solution from @peircej:

Yes, it looks like a change in the openpyxl APA. It seems we don't need to use the ExcelWriter explicitly at all though. From the docs here:
http://openpyxl.readthedocs.io/en/default/tutorial.html#saving-to-a-file
it looks like we can forget of any mention of it and just do workbook.save(filename) rather than

ew = ExcelWriter(workbook);
ew.save(filename)

@janfreyberg Feel like submitting a PR for this one? The code should check whether the openpyxl version is >= 2.4.0, and if yes, use the new approach; and run the existing code otherwise.

Probably the "version test" should be catching the import exception. ;)

Yep, I'll do that in a bit!

On Fri, 14 Oct 2016, 22:09 Richard Höchenberger, [email protected]
wrote:

Probably the "version test" should be catching the import exception. ;)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/psychopy/psychopy/issues/1274#issuecomment-253919929,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AD5yCbL2huvjZZiNLgp3N9DaqcIYjjfbks5qz-91gaJpZM4KXQjd
.

Great, I'll gladly review it and give you feedback in anything needs to be adjusted. You may also contact me/post here if you have questions.

Thanks! I've made a PR: #1276

I used an explicit version test rather than catching an error. This involved importing a version checker from distutils. Let me know if you would prefer some other way of handling this (or if you want a warning in there regarding updating openpyxl).

Discussing these changes under the PR now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lindeloev picture lindeloev  Â·  10Comments

lucaf picture lucaf  Â·  13Comments

laurentperrinet picture laurentperrinet  Â·  4Comments

luketudge picture luketudge  Â·  14Comments

dantheman39 picture dantheman39  Â·  11Comments