您好,登錄后才能下訂單哦!
需求有如圖表格:
然后有姓名,想要把這些人所在的這一行資料給導(dǎo)出來。
1、把姓名保存成名字.txt 源表格為'excelFile.xls'
2、源碼如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import xlwt
import xlrd
def main():
workbook = xlwt.Workbook(encoding='ascii')
worksheet = workbook.add_sheet('入職員工')
with open('.\名字.txt') as f:
h = 0
line = f.readline()
while line:
line = line.replace('\r', '').replace('\n', '').replace('\t', '')
# print(line)
Meiyitiao = Ex_Find(line)
print(Meiyitiao)
i = 0
for zhi in Meiyitiao:
# 寫入excel
# 參數(shù)對應(yīng) 行, 列, 值
worksheet.write(h, i, label=zhi)
i += 1
h += 1
line = f.readline()
workbook.save('入職員工資料.xls')
def Ex_Find(Name):
workfile = xlrd.open_workbook('excelFile.xls')
table = workfile.sheets()[0]
nrows = table.nrows#nrows有效行數(shù)
for i in range(0,nrows):
Ndangqian_List = table.row_values(i)#當前行資料 list list[1]為名字
z = 0
for c in range(0,len(Ndangqian_List)):
if Name == Ndangqian_List[z]:#Ndangqian_List[] z += 1 每一格的資料,遍歷列表每個元素
return table.row_values(i)
z += 1
return [Name]
if name == 'main':
main()
```**
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。