Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import re, openpyxl, os, sys
  2.  
  3.  
  4. def open_xl_file():
  5. loc = input("Please enter path of the file:")
  6. os.chdir(loc)
  7. file = input("Filename:")
  8. return openpyxl.load_workbook(file, use_iterators=True)
  9.  
  10. def sheet_select():
  11. wb = open_xl_file()
  12. sheet = input("Which Sheet do you want to email?\n")
  13. wb.get_sheet_by_name('Maharashtra')
  14.  
  15.  
  16. def sort_email_from_xl():
  17. sheet = sheet_select()
  18. return sheet
  19. ## emailRegex = re.compile(r'''([a-zA-Z0-9._%+-]+@+[a-zA-Z0-9.-]+(\.[a-zA-Z]{2,4}))''',re.VERBOSE)
  20. emailRegex = re.compile(".*?([a-zA-Z0-9\._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,4}).*?")
  21. customeremails = []
  22. for row in sheet.iter_rows():
  23. if emailRegex.match(cell.text):
  24. mail = emailRegex.match(cell.text).group[0]
  25. cell.text = mail
  26. customeremails.append(mail)
  27.  
  28. print(customeremails)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement