工作中用到的程序,今天刚写出来,用于检测excel,里面有操作表格的部分代码,可供参考。
#author kingdz
#create_time 2017.06.26
import xlrd
import os
contentList = []
def check():
hasFunctionTestReport = False
hasInnerTestReport = False
hasSoftDescription = False
getFileList()
files = os.listdir()
for i in contentList:
if not i in files:
print("ERROR:",i," name is wrong")
if i.find("软件产品版本说明书") != -1:
hasSoftDescription = True
if i.find("功能测试报告") != -1:
hasFunctionTestReport = True
if i.find("内部测试报告") != -1:
hasInnerTestReport = True
if not hasSoftDescription:
print("ERROR:没有软件产品版本说明书")
if not hasFunctionTestReport and not hasInnerTestReport:
print("ERROR:没有测试报告")
print("Check complete")
#os.system("pause")
def getFileList():
excelfile = xlrd.open_workbook('下发清单.xls')
sheetOne = excelfile.sheets()[0] #通过索引顺序获取
sheetTwo = excelfile.sheets()[1]
sheetOne.nrows #获得行数
sheetOne.ncols #获得列数
sheetOne.row_values(1) #获取行内容
colB = sheetOne.col_values(1) #获取列内容
for content in colB:
if content == '程序名称(带路径)':
continue
if len(content) == 0:
continue
#print(content)
contentList.append(content)
colB = sheetTwo.col_values(1) #获取列内容
for content in colB:
if content == '文档名称(带路径)':
continue
if len(content) == 0:
continue
#print(content)
contentList.append(content)
if __name__ == '__main__':
check()