码迷,mamicode.com
首页 > 其他好文 > 详细

excel

时间:2018-04-28 15:47:28      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:创建模板   tac   def   value   class   更改   pen   xls   work   

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

标签:创建模板   tac   def   value   class   更改   pen   xls   work   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!