excel

import openpyxl

#Template table name 
fileDir= ' D:\\xxi\\liangxi 1\\fileDir\\ ' 
tempFileName = fileDir+ ' temp.xlsx ' 
fileName = fileDir + ' hehe.xlsx '

#Start creating a template 
def createTemplateExcel():
    wb = openpyxl.Workbook()
    sht0 = wb.active
    sht0.title = " Original data " 
    sht0.merge_cells( ' A1:F1 ' )
    sht0[ ' A1 ' ]= ' User Account Balance ' 
    sht0[ ' A2 ' ]= ' Username ' 
    sht0[ ' B2 ' ]= ' Balance '

    print ( " Enter the username and balance of 4 users: " )
     for i in range(4 ):
        name=input()
        num=input()
        sht0['A%d' % (i+3)]=name
        sht0 [ ' B% d ' % (i + 3)] = num

    wb.save(tempFileName)


#Write historical data 
def writeTemplateInfo0(sht):
     try :
       sht[ ' C2 ' ]= ' Expected result ' 
       sht[ ' D2 ' ]= ' Actual result ' 
       sht[ ' E2 ' ]= ' Execution of judgment result ' 
    except BaseException as er:
         print ( " Error in header change " )
     print ( " Enter the username of the user who needs to recharge and the amount to be recharged: " )
    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)]= " User execution error " 
        else :
            sht[ ' E%d ' % (i+3)]= " User is executing normally "

    wb.save(fileName)

#createTemplateExcel()
wb = openpyxl.load_workbook(fileName)
sheet0 = wb[ ' original data ' ]
writeTemplateInfo0(sheet0)
wb = openpyxl.load_workbook(fileName)
sheet0 = wb[ ' original data ' ]
DataComparison(sheet0)

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325028664&siteId=291194637