Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 an ugly 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.

Thanks!

like image 639
Philippe Avatar asked Feb 15 '21 20:02

Philippe


2 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")
like image 139
ruhanbidart Avatar answered Sep 23 '22 16:09

ruhanbidart


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.

like image 35
Jose Urena Avatar answered Sep 21 '22 16:09

Jose Urena