'xlCategory' 和 'xlValue' 未在 xlwings 图表 API 实现中定义

'xlCategory' and 'xlValue' is not defined in xlwings Charts API implementation

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

我收到一个错误:

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

你能帮我解决这个错误吗?

xlCategory 定义在 XlAxisType 下,一个枚举定义了一些常量值。如果您没有引用 Excel 类型库/对象模型,xlCategory 对 Python/xlwings 没有任何意义。请改用其基础值 (1),或定义您自己的副本,以便标识符 xlCategory 与值 1.

相关联

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

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