计算EXCEL中的金额
import re, openpyxl
wb=openpyxl.load_workbook(r'D:\采购表2.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=round(p*q*z)
v.offset(0,1).value=sales
wb.save(r'D:\result2.xlsx')
不会保留一位小数
如果对结果要求精度不高,可以直接使用round()函数保留一位小数,可参考https://blog.csdn.net/sinat_41752325/article/details/126477260。
round(p*q*z,1)