导入BarChart的语法错误,有关Python 3.7的参考

时间:2019-06-06 15:30:54

标签: python-3.7

我正在观看一个在线视频,练习使用python对excel进行调整。
我已经在该论坛上尝试过提供的解决方案-但这没有用。

import openpyxl as xl
from openpyxl.chart import BarChart, Reference


wb = xl.load_workbook('transactions.xlsx')
sheet = wb['Sheet1']
cell = sheet['a1']
cell = sheet.cell(1, 1)


for row in range(2, sheet.max_row + 1):
    cell = sheet.cell(row, 3)
    corrected_price = cell.value*0.9
    corrected_price_cell = sheet.cell(row, 4)
    corrected_price_cell.value = corrected_price

values = Reference(sheet,
                   min_row=2,
                   max_row=sheet.max_row,
                   min_col=4,
                   max_col=4)

chart = BarChart()
chart.add_data(values)
sheet.add_chart(chart, 'f2') #code runs ok until it gets to this line

wb.save('transactions2.xlsx')

结果应该是插入一个图形以显示代码上部已计算出的值。

0 个答案:

没有答案