xlscheck base

This commit is contained in:
zhulongjun 2019-01-22 10:45:27 +08:00
parent 3ad97402f1
commit 9056606e05

View File

@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
import xdrlib, sys
import xlrd
import os
import os.path
import json
global COL_BEGIN
global error_info
COL_BEGIN = 4 #列中检查的初始位置设定
error_info = { #错误信息的定义和描述
0 : "success!", #成功
101 : "not continuity!", #数据不连续
102 : 'data is null!', #数据为空
201 : "data type error!" #数据类型错误
}
def main(): #设置main函数为入口函数
inspect_activity()
def printErrorLog(error_code):
global error_info
if error_code == None:
print('错误码异常!!!')
return
if error_code != 0:
print(error_info[error_code])
print(num)
def checkContinuity(checkContent):
if checkContent:
befVal = -1
for val in checkContent:
print(val)
if type(val) == int or type(val) == float:
if befVal + 1 != val and befVal != -1:
print('checkContinuity error!')
return 101
befVal = val
else:
print('checkContinuity error!')
return 201
return 0
def checkIsNull(checkContent):
if checkContent:
for val, i in enumerate(checkContent):
print(val)
print(i)
if val == '' or val == None:
return 102, i
return 0
def getXlsContent(xlsName):
excl = xlrd.open_workbook(xlsName)
return excl.sheets()
def inspect_activity():
global COL_BEGIN
sheets = getXlsContent('activity.xlsx')
print(sheets[0].name)
#printErrorLog(checkContinuity(sheets[0].col_values(0,COL_BEGIN)))
printErrorLog(checkIsNull(sheets[0].col_values(2,COL_BEGIN)))
return
if __name__ == "__main__":
main()