How to deal with warning : "Workbook contains no default style, apply openpyxl's default "

I have the -current- latest version of pandas, openpyxl, xlrd.

openpyxl : 3.0.6.
pandas : 1.2.2.
xlrd : 2.0.1.

I have a generated excel xlsx- file (export from a webapplication).
I read it in pandas:

myexcelfile = pd.read_excel(easy_payfile, engine="openpyxl") 

Everything goes ok, I can successfully read the file.

But I do get a warning:

/Users/*******/projects/environments/venv/lib/python3.8/site-packages/openpyxl/styles/stylesheet.py:214: UserWarning: Workbook contains no default style, apply openpyxl's default warn("Workbook contains no default style, apply openpyxl's default") 

The documentation doesn't shed too much light on it.

Is there any way I can add an option to avoid this warning?

I prefer not to suppress it.

5

7 Answers

I don't think the library offers you a way to disable this thus you are going to need to use the warnings package directly.

A simple and punctual solution to the problem would be doing:

import warnings with warnings.catch_warnings(record=True): warnings.simplefilter("always") myexcelfile = pd.read_excel(easy_payfile, engine="openpyxl") 
1

@ruhanbidart solution is better than mine because you turn off warnings just for the call to read_excel, but if you have dozens of calls to pd.read_excel, you can simply disable all warnings:

import warnings warnings.simplefilter("ignore") 

I had the same warning. Just changed the sheet name of my excel file from "sheet_1" to "Sheet1", then the warning disappeared. very similar with Yoan. I think pandas should fix this warning later.

1

df=pd.read_excel("my.xlsx",engine="openpyxl") passing the engine parameter got rid of the warning for me. Default = None, so I think it is just warning you that it using openpyxl for default style.

1

I had the exact same warning and was unable to read the file. In my case the problem was coming from the Sheet name in the Excel file.

The initial name contained a . (ex: MDM.TARGET) I simply replace the . with _ and everything's fine.

In my case it was the sheet name. From Sheet0 I renamed it to Sheet1

2

In my situation some columns' names had a dollar sign ($) in them. Replacing '$' to '_' solved the issue.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like