Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import import Style from openpyxl

I've been able to import openpyxl and have succeeded in changing the font color of some of the characters but when I write the following line:

from openpyxl.styles import Style

I get an error saying that it cannot import Style. I've also tried lowercasing style. I find this strange because the following work just fine:

from openpyxl import load_workbook
from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font
from openpyxl.styles import Fill, Color
like image 996
bobsmith76 Avatar asked Dec 11 '25 17:12

bobsmith76


1 Answers

Not sure if you are basing this effort on a Tutorial or not, but Style is not an option available in openpyxl.styles for openpyxl version 2.4.8.

Here I import openpyxl.styles and then examine all the options that are available using the dir() function.

As you note, items like Font, PatternFill, etc are present, but Style is not.

In [2]: import openpyxl.styles as ops

In [3]: dir(ops)
Out[3]:
['Alignment',
 'Border',
 'Color',
 'DEFAULT_FONT',
 'Fill',
 'Font',
 'GradientFill',
 'NamedStyle',
 'NumberFormatDescriptor',
 'PatternFill',
 'Protection',
 'Side',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 'absolute_import',
 'alignment',
 'borders',
 'builtins',
 'cell_style',
 'colors',
 'differential',
 'fills',
 'fonts',
 'is_builtin',
 'is_date_format',
 'named_styles',
 'numbers',
 'protection',
 'proxy',
 'styleable',
 'stylesheet',
 'table']

This stack overflow question indicates that Style was deprecated:

This section of the openpyxl documentation has some guidance on using styles. It is likely that what you are trying to achieve is described therein.

like image 179
E. Ducateme Avatar answered Dec 13 '25 07:12

E. Ducateme



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!