import xlrd, re
from datetime import datetime
from xlrd import xldate_as_tuple
xls_path =r"E:\工作相关\收件人員信息.xlsx"
data = xlrd.open_workbook(xls_path)
table = data.sheet_by_name("BU收件人員")defget_mail_list(sheet_name):
table = data.sheet_by_name(sheet_name)
nrows = table.nrows
ncols = table.ncols
print(nrows, ncols)for i inrange(1, nrows):
bu_dict ={}
name = table.cell(i,0).value.strip().replace('次群报表','')
to = table.cell(i,1).value.strip().replace('次群报表','')
cc = table.cell(i,2).value.strip().replace('次群报表','')
to = re.findall("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)", to)
cc = re.findall("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)", cc)# print(name)# print(to)# print(cc)
bu_dict['to']= to
bu_dict['cc']= cc
mail_info[name]= bu_dict
sheet_list =["群收件人員","BU收件人員"]
mail_info ={}for sheet_name in sheet_list:
get_mail_list(sheet_name)print(mail_info)for k,v in mail_info.items():print(k, v)print(len(mail_info))
import re
my_str ="Hi my name is John and email address is john.doe@somecompany.co.uk and my friend's email is jane_doe124@gmail.com"
emails = re.findall("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)", my_str)for mail in an email:print(mail)