使用xlwings库可以在Excel中生成折线图,并且可以自定义生成的位置。下面是一个示例代码:

import xlwings as xw

# 连接到Excel应用程序
app = xw.App(visible=True)

# 打开Excel文件
wb = app.books.open('path/to/your/file.xlsx')

# 选择要操作的工作表
sht = wb.sheets['Sheet1']

# 设置折线图的数据范围
data_range = sht.range('A1:B10')

# 在指定位置插入折线图
chart = sht.charts.add(left=sht.range('D1').left, top=sht.range('D1').top)

# 设置折线图的数据源
chart.set_source_data(data_range)

# 设置折线图的样式和标题
chart.chart_type = 'line'
chart.name = '折线图示例'

# 保存Excel文件
wb.save()
wb.close()

# 关闭Excel应用程序
app.quit()

在上面的示例中,lefttop参数用来指定折线图的左上角位置,可以根据需要自行调整

python excel生成折线图 xlwings自己设置生成的位置

原文地址: https://www.cveoy.top/t/topic/hLPX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录