openpyxl python中的自定义系列标题 [英] Customized series title in 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.