openpyxl and stdev.p name error

北战南征 提交于 2019-12-23 20:21:11

问题


I have a script to format a bunch of data and then push it into excel, where I can easily scrub the broken data, and do a bit more analysis.

As part of this I'm pushing quite a lot of data to excel, and want excel to do some of the legwork, so I'm putting a certain number of formulae into the sheet.

Most of these ("=AVERAGE(...)" "=A1+3" etc) work absolutely fine, but when I add the standard deviation ("=STDEV.P(...)" I get a name error when I open in excel 2013.

If I click in the cell within excel and hit (i.e. don't change anything within the cell), the cell re-calculates without the name error, so I'm a bit confused.

Is there anything extra that needs to be done to get this to work?

Has anyone else had any experience of this?

Thanks,

Will --


回答1:


I've investigated further and this is the issue:

When saving the formula "STDEV.P" openpyxl saves it as:

"=_xludf.STDEV.P(...)"

which is correct for many formula, but not this one. The result should be:

"=_xlfn.STDEV.P(...)"

When I explicitly change the function to the latter, it works as expected. I'll file a bug report, so hopefully this is done automatically in the future.




回答2:


I suspect that there might be a subtle difference in what you think you need to write as the formula and what is actually required. openpyxl itself does nothing with the formula, not even check it. You can investigate this by comparing two files (one from openpyxl, one from Excel) with ostensibly the same formula. The difference might be simple – using "." for decimals and "," as a separator between values even if English isn't the language – or it could be that an additional feature is required: Microsoft has continued to extend the specification over the years.

Once you have some pointers please submit a bug report on the openpyxl issue tracker.



来源:https://stackoverflow.com/questions/29486671/openpyxl-and-stdev-p-name-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!