楼主可以参考一下
import xlrd
import os
from xlutils3.copy import copy
import xlwt
def getName(fileName):
nameList = []
workbook = xlrd.open_workbook(fileName)
sheet = workbook.sheet_by_index(0)
for i in range(1,sheet.nrows):
# 第八列即为名字
nameList.append(sheet.row(i)[7].value)
return nameList
def hasDoneName(path):
hasDoneList = []
for i in os.listdir(path):
name = i.split(".")[0]
hasDoneList.append(name)
return hasDoneList
def check(name1,name2):
checkDic = {}
for i in name1:
checkDic[i]=(i in name2)
return checkDic
def writeXls(fileName,checkDic):
workbook = xlrd.open_workbook(fileName)
sheet = workbook.sheet_by_index(0)
newbook = copy(workbook)
newsheet = newbook.get_sheet(0)
for i in range(1,sheet.nrows):
name = str(sheet.row(i)[7].value)
newsheet.write(i, 8, str(checkDic[name]))
newbook.save("result.xls")
if __name__ == '__main__':
fileName = "test.xlsx"
name1 = getName(fileName)
name2 = hasDoneName("./")
print(name1)
print(name2)
myDic = check(name1,name2)
print(myDic)
writeXls(fileName,myDic)
|