openpyxl.charts 中的引用不起作用 (min_col) Python 3

Reference in openpyxl.charts doesn't work (min_col) Python 3

我有来自 https://automatetheboringstuff.com/chapter12/ 的简单代码 哪个应该制作图表,但我不知道为什么 Reference 模块在这个例子中对我不起作用。

import openpyxl
from openpyxl import Workbook
from openpyxl.charts import BarChart, Series, Reference

wb = Workbook()
ws = wb.active
for i in range(10):
     ws.append([i])

values = Reference(ws, min_col = 1, min_row=1, max_col=1, max_row=10)
chart = BarChart()
chart.add_data(values)
ws.add_chart(chart, "E15")
wb.save("SampleChart.xlsx")

它给我一个类型错误:

Traceback (most recent call last):
  File "charts_excel.py", line 9, in <module>
    refObj = openpyxl.charts.Reference(sheet, min_col=1, min_row=1, max_col=1, max_row=10)
TypeError: __init__() got an unexpected keyword argument 'min_col'

有谁知道为什么这段代码不起作用?我没有在任何地方找到答案。我发现了几个使用 Reference 的例子,但它对我也不起作用,例如:

values = openpyxl.charts.Reference(sheet, min_col=1, min_row=1, max_col=1, max_row=10)

很遗憾,该在线图书中的信息已过时。请仅参考包含正确导入路径的官方文档http://openpyxl.readthedocs.io/en/2.5/charts/introduction.html

自 OP 发布问题以来已经有很长时间了,但这很可能是问题所在:全局命名空间中可能存在来自另一个导入(不是 openpyxl)的“引用”对象。我在导入时更改了名称,问题已解决。:

from openpyxl.chart import Reference as opyxlReference

...
values = opyxlReference(ws, min_col = 1, min_row=1, max_col=1, max_row=10)