openpyxl problem Workbook contains no default style, apply openpyxl's default

331 views
Skip to first unread message

Denis Bourouffala

unread,
Feb 1, 2024, 3:57:06 AMFeb 1
to openpyx...@googlegroups.com
Good Morning,

In the version 3.1.2 of openpyxl, I've message :

UserWarning: Workbook contains no default style, apply openpyxl's default
 warn("Workbook contains no default style, apply openpyxl's default")

This is my prog : 

from openpyxl import load_workbook
filename = "C:\\Analyse Article EPF.xlsx"
wb = load_workbook(filename, data_only=True)
ws_conversion = wb["Conversion"]
print(ws_conversion.max_column)


Where is the problem ?

Thanks to help

Best regards

Charlie Clark

unread,
Feb 1, 2024, 4:32:15 AMFeb 1
to openpyx...@googlegroups.com
On 1 Feb 2024, at 9:56, Denis Bourouffala wrote:

> Where is the problem ?

There isn't a problem: it's just a warning that the workbook contains no stylesheet and that we apply Openpyxl's default. All workbooks should contain a stylesheet so that there is no confusion when styles, including time and date formats are applied.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226

Denis Bourouffala

unread,
Feb 1, 2024, 4:44:53 AMFeb 1
to openpyx...@googlegroups.com
Thank you

How can I solve or remove this?

Best regards

--
You received this message because you are subscribed to the Google Groups "openpyxl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openpyxl-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/openpyxl-users/934281DC-F0C3-4A30-BCA7-FE99229857B8%40clark-consulting.eu.

Charlie Clark

unread,
Feb 1, 2024, 4:48:07 AMFeb 1
to openpyx...@googlegroups.com
On 1 Feb 2024, at 10:44, Denis Bourouffala wrote:

> Thank you
>
> How can I solve or remove this?

You can configure Python to ignore warnings.

John Hendy

unread,
May 16, 2024, 8:39:02 PMMay 16
to openpyxl-users
That is indeed one approach, but why is this preferred vs. giving the user a way to say "I know my workbook has no default style; please apply openpxyl's default"?

I expected something like pd.read_excel('foo.xlsx', style='openpyxl_default') so that I can be explicit and remove the warning, and was surprised not to find this ability. As a counter, see this proposed solution from SO where all the answers say to silence the warnings[1]:

import warnings
with warnings.catch_warnings():
    warnings.simplefilter("ignore")
    myexcelfile = pd.read_excel(easy_payfile, engine="openpyxl")

What if I'm reading in hundreds of files and some other warning I actually care about emerges? Other answers wrap pd.read_excel() in some other function just to handle this warning. Having the function itself address this seems cleaner in my opinion.

I'm reading that the "value" of this warning is to say, "All excel sheets should have a stylesheet and yours doesn't! But I went ahead and applied one, FYI!" Why not let me grant explicit permission to apply that default so I don't have to be warned that openpyxl is doing it anyway?

Admittedly the nuisance is minor, but results in a ton of junk output in e.g. jupyter notebooks if I'm reading in/concatenating a directory of excel files. Importing a library just to silence warnings this also feels like a nuisance, and that there's a better approach than silencing warnings.


Best,
John

Diego DM

unread,
Aug 28, 2024, 10:23:46 AMAug 28
to openpyxl-users
I agree with John
Reply all
Reply to author
Forward
0 new messages