您好,登錄后才能下訂單哦!
需求有如圖表格:
然后有姓名,想要把這些人所在的這一行資料給導出來。
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
# 參數對應 行, 列, 值
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有效行數
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()
```**
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。