From 9056606e05353b3d624565cf1dac14d12792234d Mon Sep 17 00:00:00 2001 From: zhulongjun Date: Tue, 22 Jan 2019 10:45:27 +0800 Subject: [PATCH] xlscheck base --- scripts/xlscheck/xlscheck.py | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 scripts/xlscheck/xlscheck.py diff --git a/scripts/xlscheck/xlscheck.py b/scripts/xlscheck/xlscheck.py new file mode 100644 index 0000000..b818729 --- /dev/null +++ b/scripts/xlscheck/xlscheck.py @@ -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() +