import openpyxl#引入openpyxl filename = r'./求33的矩阵.xlsx' wb = openpyxl.load_workbook(filename)#打开Excel ws = wb ['计算']#打开‘计算’这页 x11=float(ws.cell(1,1).value) x12=float(ws.cell(1,2).value) x13=float(ws.cell(1,3).value) x21=float(ws.cell(2,1).value) x22=float(ws.cell(2,2).value) x23=float(ws.cell(2,3).value) x31=float(ws.cell(3,1).value) x32=float(ws.cell(3,2).value) x33=float(ws.cell(3,3).value) x14=x11 x15=x12 x24=x21 x25=x22 x34=x31 x35=x32 result =(x11 * x22 * x33) + (x12 * x23 * x31) + (x13 * x21 * x32) - (x13 * x22 * x31) - (x11 * x23 * x32) - (x12 * x21 * x33)#用对角线法则计算 ws.cell(5,2).value = result#在(5,2)这个单元格写入结果 wb.save(filename+'1.xlsx')#保存 print('执行完毕') |