需求有如图表格:
然后有姓名,想要把这些人所在的这一行资料给导出来。
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。