openpyxl python中的自定义系列标题 [英] Customized series title in openpyxl python

查看:381
本文介绍了openpyxl python中的自定义系列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改现有的xlsx工作表,并使用python中的openpyxl模块向其中添加图形.

I am trying to modify the existing xlsx sheet and adding graphs to it using openpyxl module in python.

但是在创建折线图时,系列标题显示为系列1,系列2,系列3,系列4,在这里我需要将系列标题重命名为"A","B","C",D "(注意:此名称不能从任何单元格中获取)

But while creating a line chart, the series title is shown as Series 1,Series 2,Series 3,Series 4 where as I need to rename the series title as "A", "B", "C", D". (Note: this name are not fetched from any cell)

另一种可能的解决方案是,从同一工作表的行/列之外的另一个工作表中获得系列名称.但不确定是否可行.

Another possible solution would to give series name from another worksheet apart from row/column of the same worksheet. But not sure whether it is doable.

下面的代码为我提供了工作表"ws"的行/列中的系列名称. 但是我需要重命名它(自定义名称)或从另一张纸上分配系列名称.

Below code give me the series name from row/column of worksheet 'ws'. But I need to rename it (customize name) or assign the series name from another sheet.

有人可以帮我吗??

c1 = LineChart()
c1.title = worksheet
c1.x_axis.title = "Average depth"
c1.y_axis.title = "Average Response time (ms)"
c1.y_axis.majorGridlines = None

refseries1 = Reference(ws, min_col=5, min_row=2, max_col=5, max_row=9)
seriesdata1 = Reference(ws, min_col=6, min_row=10, max_col=6, max_row=15)

c1.add_data(data=seriesdata1,titles_from_data=False)
c1.set_categories(refseries1)

在上面的代码中,refseries1是xaxis数据,seriesdata1是y轴数据.

In above code, refseries1 is xaxis data and seriesdata1 is y axis data.

推荐答案

我在

它比chart.add_data方法更有趣,我假设如果您对该方法的代码进行深入研究,将会发现更多... pythony.

It's a bit more fiddly than the chart.add_data method, I'm going to assume that if you dig around in the code for that method you'll find something a bit more... pythony.

这篇关于openpyxl python中的自定义系列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆