Python 2.7 Openpyxl UserWarning

寵の児 提交于 2019-12-04 22:56:01

问题


Why do I receive this warning message every time I run my code? (below). Is it possible to get rid of it? If so, how do I do that?

My code:

from openpyxl import load_workbook
from openpyxl import Workbook

wb = load_workbook('NFL.xlsx', data_only = True)
ws = wb.active
sh = wb["Sheet1"]


ptsDiff = (sh['J127'].value)
print ptsDiff

The code works but I get this warning message:

Warning (from warnings module):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/openpyxl/reader/worksheet.py", line 320
warn(msg)
UserWarning: Unknown extension is not supported and will be removed

回答1:


This error happens when openpyxl cannot understand/read an extension (source). Here is the list of built-in extensions openpyxl currently knows that is doesn't support:

  • Conditional Formatting
  • Data Validation
  • Sparkline Group
  • Slicer List
  • Protected Range
  • Ignored Error
  • Web Extension
  • Slicer List
  • Timeline Ref

Also see the Worksheet extension list specification.




回答2:


Using python 3.5 under Anaconda3, Excel 2016, Windows10 -- I had the same problem initially with an xlsx file. Tried to make it into a csv and did not work. What worked was: select the entire spreadsheet, copy on a Notepad, select the notepad text, paste in a new spreadsheet, save as xslx. It looks like any extra formatting would result in a warning.




回答3:


Try to add single quotes to your data_only parameter like this:

wb = load_workbook('NFL.xlsx', data_only = **'True'**)

This works for me.




回答4:


It is already listed in the first answer what is wrong with it If you only want to get rid of the error that is given in red for some reason. You can go to the file location of the error and # the line where is says warn(msg) this will stop the error being displayed the code still works fine in my experience.I am not sure if this will work after compiled but this should work in the same machine. PS:I had the same error and this is what I did because I though it could be confusing for the end user PS:You can use a try and except error catcher too but this is quicker.



来源:https://stackoverflow.com/questions/34322231/python-2-7-openpyxl-userwarning

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