13

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
Martin Brown
  • 24,692
  • 14
  • 77
  • 122
jcmcdonald
  • 327
  • 1
  • 3
  • 9
  • Where is this `xlsx` file coming from? What tool was used to create it? Thanks. – alecxe Dec 16 '15 at 21:38
  • The .xlsx file is coming from the same folder as the python file. I created it using Microsoft Excel for Mac 2011(version 14.5.9). – jcmcdonald Dec 16 '15 at 21:48

5 Answers5

11

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.

Charlie Clark
  • 18,477
  • 4
  • 49
  • 55
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • 4
    Sorry for my ignorance but are you saying that openpyxl cannot understand/read .xlsx files? If I were to add read_only = True to this line.. wb = load_workbook('NFL.xlsx', read_only = True, data_only = True). I no longer receive this warning message. – jcmcdonald Dec 16 '15 at 22:07
  • 2
    @jcmcdonald nope, I'm saying there is an extension/feature used inside the file that openpyxl cannot understand. And, yes, if you need data only, `date_only` would make it not parse the extensions at all. Hope that helps. – alecxe Dec 16 '15 at 22:08
  • 2
    Sorry again. Is there away to avoid the warning? – jcmcdonald Dec 16 '15 at 22:15
  • @jcmcdonald that's what would be not easy without seeing the actual file. See if you can share it (no need for any private data inside it please). Thanks. – alecxe Dec 16 '15 at 22:18
  • Thanks for the help. Even if I open a brand new blank .xlsx document, save it to the same directory and change the file name in the code I still get the same error. – jcmcdonald Dec 16 '15 at 22:27
  • @jcmcdonald sure, please share the file, I mean. Thanks. – alecxe Dec 16 '15 at 23:20
  • 2
    The warnings refer to extensions that Microsoft has added to the file format since 2006. They are not covered by the specification. – Charlie Clark Dec 17 '15 at 07:52
  • 2
    How do I handle the Warning? Also, can I determine the offending built-in extension? How would I do that? – Vishal May 30 '18 at 07:49
  • The flag data_only=True **does NOT** cover extensions, so it seems that there is currently no way to suppress this warning. – Amir Katz Feb 11 '20 at 15:24
4

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

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

This works for me.

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
lug0lug0
  • 51
  • 5
1

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.

0

I was trying to use Openpyxl to do something that has nothing to do with charts or graphs. I got warning message: UserWarning: DrawingML support is incomplete and limited to charts and images only. Shapes and drawings will be lost.

In the line that opens pyxl workbook, I added a parameter that ReadOnly = True Being ReadOnly, I can't try to alter graphs, etc.; and the warning seems to be gone now.

Sharing it here because this is the first help page I see where I can add a comment; and internet searching was not serving me up an answer.

-1

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.

KillerKingTR
  • 9
  • 1
  • 3
  • yeah i know but i get the output I want and I need to hide error i couldnt find a way to get rid of it so I did it that way – KillerKingTR Oct 20 '19 at 23:12
  • 1
    This is a horrible idea as you'd be editing an installed package directly, which can interfere with updates and reproducibility of your code. – Tamoghna Chowdhury May 01 '21 at 20:33
  • 1
    As openpyxl uses the Python warnings library for its warnings, there's a better method [here](https://docs.python.org/3/library/warnings.html#temporarily-suppressing-warnings) for suppressing these warnings in specific sections of the code, or see [here](https://stackoverflow.com/a/14463321/4499183) for globally disabling warnings when running Python (also other answers therein, especially [this](https://stackoverflow.com/a/48649917/4499183) – Tamoghna Chowdhury May 01 '21 at 20:39