使用spyder,
计算excel表格中商品金额,第一项是3斤鱼8元每斤共2批,要先读取数字再计算再转回
代码:
import re,openpyxl
wb=openpyxl.load_workbook(r'D:\采购表1.xlsx')
ws=wb.active
pat=re.compile(r'\d+')
for v in ws ['a:a'][1:]:
q=int(pat.findall(v.value)[0])
p=int(pat.findall(v.value)[1]
z=int(pat.findall(v.value)[2])
sales=q*p*z
v.offset(0,1).values=sales
ws.cell(1,2,)
wb.save(r'D:\result1.xlsx')
报错:
AttributeError: 'Cell' object has no attribute 'values'