gpt4 book ai didi

python - 无法从 openpyxl 导入导入样式

转载 作者:行者123 更新时间:2023-12-05 09:18:08 33 4
gpt4 key购买 nike

我已经能够导入 openpyxl 并成功地更改了一些字符的字体颜色,但是当我写下以下行时:

from openpyxl.styles import Style

我收到一条错误消息,指出它无法导入样式。我也尝试过小写风格。我觉得这很奇怪,因为以下工作正常:

from openpyxl import load_workbook
from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font
from openpyxl.styles import Fill, Color

最佳答案

不确定您是否将此工作基于教程,但是 Style 不是 openpyxl.styles 中用于 openpyxl 的选项> 版本 2.4.8。

我在这里导入 openpyxl.styles,然后使用 dir() 函数检查所有可用的选项。

如您所见,FontPatternFill 等项目存在,但Style 不存在。

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']

stack overflow question表示 Style 已被弃用:

section of the openpyxl documentation有一些关于使用样式的指导。很可能其中描述了您要实现的目标。

关于python - 无法从 openpyxl 导入导入样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45518050/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com