“xlCategory”和“xlValue”未在xlwings Charts API实现中定义

2024-07-05 09:53:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试用xlwings-python实现一个图表API,用于基本的图表操作,如添加轴标题、更改线条颜色、绘图标记大小等

我得到一个错误:

name 'xlCategory' is not defined

实现的代码是

import xlwings as xw

wb = xw.Book(r'Tau.xlsm') 
sht = wb.sheets.add(name ='Plot')
tau_plot = sht.charts.add()
tau_plot.chart_type='xy_scatter'
tau_plot.set_source_data(sht.range('E1:F135'))
tau_plot.api[1].Axes(xlCategory).HasTitle = True

你能帮我解决这个错误吗。在


Tags: nameaddapi标题plot颜色错误图表
2条回答

xlCategory定义在XlAxisType下,该枚举定义了许多常量值。如果您没有引用Excel类型库/对象模型,xlCategory对Python/xlwings没有任何意义。使用它的基础值(1),或者定义自己的副本,以便标识符xlCategory与值1相关联。在

您可以使用Excel的常量,如下所示:

>>> from xlwings.constants import AxisType
>>> AxisType.xlCategory

相关问题 更多 >