import re
import xlrd
import xlwt
def main():
#读取Excel
wk=xlrd.open_workbook(r'C:\Users\https://mp.csdn.net/posteditPublic\Nwt\cache\recv\旧白名单.xlsx')
#获取目标EXCEL文件sheet名
sheets=wk.sheet_names()
#根据表索引
ws=wk.sheet_by_index(0)
#获取总行数
nrows=ws.nrows
#获取总列数
ncols=ws.ncols
print(nrows,ncols)
#获取一列的值row_values(i)#获取一行的数值
datarow=ws.col_values(1)
# print(type(datarow))
#拼接字符串
text=" ".join('%s' %id for id in datarow)
# print(type(text))
m=re.findall(r"130\d{8}",text)
if m:
print('1111',m)
return m
def main_n(fun):
m=fun()
print("5555",m)
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
sheet = book.add_sheet('demom', cell_overwrite_ok=True)
count=0
for a in m:
count+=1
print(count)
sheet.write(count,0,a)
book.save('130.xls')
if __name__ == "__main__":
main_n(main)
---------------------
作者:lly2234317974
来源:CSDN
原文:https://blog.csdn.net/lly2234317974/article/details/80524658
版权声明:本文为博主原创文章,转载请附上博文链接!
Python筛选Excel数据,读取、保存
最新推荐文章于 2024-09-07 20:47:26 发布