用XLSXWRITER分配Excel图表对象名称

发布于 2025-01-30 19:24:39 字数 55 浏览 4 评论 0原文

是否可以将Excel图表对象名称分配给我使用XLSXWriter创建的图表?

谢谢

Is it possible to assign an Excel Chart Object name to a chart I am creating with XlsxWriter?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2025-02-06 19:24:39

它(无意间)无证件,但是创建图表时可以为图表设置对象名称。这样:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()

# Create a new Chart object.
chart = workbook.add_chart({'type': 'column',
                            'name': 'MyChart'})  # Setting the name.

worksheet.write_row('A1', [1, 2, 3, 2, 1])

# Configure the chart.
chart.add_series({'values': '=Sheet1!$A$1:$E$1'})

# Insert the chart into the worksheet.
worksheet.insert_chart('A3', chart)

workbook.close()

输出

​Workbook-Add-chart“ rel =” nofollow noreferrer”>已记录为单位。

It is (unintentionally) undocumented but you can set the object name for a chart when you create it. Like this:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()

# Create a new Chart object.
chart = workbook.add_chart({'type': 'column',
                            'name': 'MyChart'})  # Setting the name.

worksheet.write_row('A1', [1, 2, 3, 2, 1])

# Configure the chart.
chart.add_series({'values': '=Sheet1!$A$1:$E$1'})

# Insert the chart into the worksheet.
worksheet.insert_chart('A3', chart)

workbook.close()

Output:

enter image description here

Update: It is documented now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文