Ankit Bansal
Ankit Bansal

Reputation: 337

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

I'm trying to do a Charts API implementation in xlwings - python, for basic chart manipulation like adding axis title, changing the line colors, plot marker size etc.

I get an error:

name 'xlCategory' is not defined

The code for implementation is

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

Can you please help me with this error.

Upvotes: 1

Views: 762

Answers (2)

Felix Zumstein
Felix Zumstein

Reputation: 7070

You can use Excel's constants as follows:

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

Upvotes: 1

Mathieu Guindon
Mathieu Guindon

Reputation: 71177

xlCategory is defined under XlAxisType, an enum that defines a number of constant values. If you're not referencing the Excel type library / object model, xlCategory means nothing to Python/xlwings. Use its underlying value instead (1), or define your own copy so that the identifier xlCategory is associated with the value 1.

Upvotes: 1

Related Questions