首页 > 其他 > 详细

excel

时间:2018-04-28 15:14:34      阅读:214      评论:0      收藏:0      [点我收藏+]
import openpyxl

#模板表的名称
fileDir=D:\\xxi\\liangxi 1\\fileDir\\
tempFileName = fileDir+temp.xlsx
fileName = fileDir + hehe.xlsx

#开始创建模板
def createTemplateExcel():
    wb = openpyxl.Workbook()
    sht0 = wb.active
    sht0.title= "原数据"
    sht0.merge_cells(A1:F1)
    sht0[A1]=用户账户余额
    sht0[A2]=用户名
    sht0[B2]=余额

    print("输入4个用户的用户名和余额:")
    for i in range(4):
        name=input()
        num=input()
        sht0[A%d % (i+3)]=name
        sht0[B%d % (i+3)]=num

    wb.save(tempFileName)


#写入历史数据
def writeTemplateInfo0(sht):
    try:
       sht[C2]=预期结果
       sht[D2]=实际结果
       sht[E2]=执行的判断结果
    except BaseException as er:
        print("表头的更改发生错误")
    print("输入需要充值用户的用户名和需充值的金额:")
    name=input()
    num=input()
    for i in range(4):
        x=str(sht[A%d % (i+3)].value)
        if x == name:
           y=sht[B%d % (i+3)].value
           sht[D%d % (i+3)].value=y+int(num)

    wb.save(fileName)

#数据比较
def DataComparison(sht):
    for i in range(4):
        if sht[D%d % (i+3)].value != sht[C%d % (i+3)].value:
            sht[E%d % (i+3)]="用户执行错误"
        else:
            sht[E%d % (i+3)]="用户执行正常"

    wb.save(fileName)

#createTemplateExcel()
wb = openpyxl.load_workbook(fileName)
sheet0 = wb[原数据]
writeTemplateInfo0(sheet0)
wb = openpyxl.load_workbook(fileName)
sheet0 = wb[原数据]
DataComparison(sheet0)

 

excel

原文:https://www.cnblogs.com/fenhong/p/8967509.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!