Python篩選Excel資料,讀取、儲存
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
版權宣告:本文為博主原創文章,轉載請附上博文連結!