【Python】工作中自己用的一个程序,操作excel

工作中用到的程序,今天刚写出来,用于检测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()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值