Charts

class Charts(impl)

A collection of all chart objects on the specified sheet:

>>> import xlwings as xw
>>> xw.books['Book1'].sheets[0].charts
Charts([<Chart 'Chart 1' in <Sheet [Book1]Sheet1>>,
        <Chart 'Chart 1' in <Sheet [Book1]Sheet1>>])

在 0.9.0 版本加入.

add(left=0, top=0, width=355, height=211)

在指定的工作表中创建一个新的图表。

参数:
  • left (float) -- 左边起点,单位是 point

  • top (float) -- 上边的起点,单位是 point

  • width (float) -- 宽带,单位是 point

  • height (float) -- 高度,单位是 point

示例

>>> import xlwings as xw
>>> sht = xw.Book().sheets[0]
>>> sht.range('A1').value = [['Foo1', 'Foo2'], [1, 2]]
>>> chart = sht.charts.add()
>>> chart.set_source_data(sht.range('A1').expand())
>>> chart.chart_type = 'line'
>>> chart.name
'Chart1'