Excel 和 CSV 仍在处理中,但我无法真正编辑 Excel 文件

Still progressing in Excel and CSV, and I can't really edit Excel file

代码:

#Load the file by name
food_price = opxl.load_workbook('Food.xlsx')
sheet_food = food_price['Sheet1']
#Specify position
acell = sheet_food['a1'] 
#Specify number position of cell.
cell2 = sheet_food.cell(2, 3)
for row in range(2, sheet_food.max_row + 1):
    cell = sheet_food.cell(row, 3)
    correct_price = cell.value * 0.85
    correct_price_cell = sheet_food.cell(row, column = 3)
    correct_price_cell.value = correct_price_cell

food_price.save("Food.xlsx")

我想在电子表格中添加一列,但它似乎阻止我这样做。

错误:

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\site-packages\openpyxl\cell\cell.py", line 199, in _bind_value
    raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert <Cell 'Sheet1'.C2> to Excel

请帮忙,因为我是电子表格编辑的新手。 我将非常感激我得到的答案和建议。 谢谢,堆栈溢出!

试试这个

food_price = opxl.load_workbook('Food.xlsx')
sheet_food = food_price['Sheet1']
#Specify position
acell = sheet_food['a1'] 
#Specify number position of cell.
cell2 = sheet_food.cell(2, 3)
for row in range(2, sheet_food.max_row + 1):
    cell = sheet_food.cell(row, 3)
    if  cell.value  :
        correct_price = cell.value * 0.85
        correct_price_cell = sheet_food.cell(row,  3)
        correct_price_cell.value = correct_price

food_price.save("Food.xlsx")