xlwings设置chart type
时间: 2023-12-07 21:04:47 浏览: 102
您可以使用xlwings将Excel图表类型更改为以下几种:
1. 柱形图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'column_clustered'
```
2. 折线图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'line'
```
3. 饼图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'pie'
```
4. 散点图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'scatter'
```
5. 气泡图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:C5'))
chart.chart_type = 'bubble'
```
6. 面积图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'area'
```
7. 条形图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'bar_clustered'
```
8. 雷达图:
```
import xlwings as xw
wb = xw.Book()
sheet = wb.sheets[0]
chart = sheet.charts.add()
chart.set_source_data(sheet.range('A1:B5'))
chart.chart_type = 'radar'
```
请注意,这些图表类型在不同版本的Excel中可能会有所不同。在使用时,请根据您的Excel版本和需求进行调整。
阅读全文