Python 2.7 Openpyxl UserWarning

2020-06-04 03:26发布

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

4条回答
Fickle 薄情
2楼-- · 2020-06-04 03:42

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.

查看更多
SAY GOODBYE
3楼-- · 2020-06-04 03:54

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.

查看更多
虎瘦雄心在
4楼-- · 2020-06-04 04:01

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.

查看更多
劫难
5楼-- · 2020-06-04 04:06

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

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

This works for me.

查看更多
登录 后发表回答