用openpyxl插入格公式2

来源:互联网 发布:nginx 500错误 编辑:程序博客网 时间:2024/05/14 21:14
# __*__encoding:utf8__*__import openpyxlimport openpyxl.worksheetwb = openpyxl.load_workbook("files/whsf.xlsx")st = wb.activerow_max = st.max_rowprintrow_maxcell1 = []cell2 = []cell3 = []for i in range(1, row_max):    btxt1 = st.cell(row=i, column=2).value    btxt2 = st.cell(row=i, column=2).value    btxt3 = st.cell(row=i, column=2).value    if (btxt1 == u"断路器*"):        cell1.append(i)    if (btxt2 == u"辅材"):        cell2.append(i)    if (btxt3 == u"合计"):        cell3.append(i)printcell1, cell2, cell3print(len(cell1))for i in range(0, len(cell1)-1):    st['G' + str(cell3[i])].value = "=SUM(G" + str(cell1[i]) + ":G" + str(cell2[i]) + ")"wb.save("whsfc.xlsx")

原创粉丝点击