Automating Boring Stuff

Picked up a copy of by Al Sweigart and I’m already improving.  A coworker had a really ugly spreadsheet with usernames that needed to be converted to email addresses. I was able to run through a few hundred entries in short time.  Have a few more quicky projects to run through as well.


import os, openpyxl

#change directory to location of spreadsheet
#open a file that will contain the mail addresses in write mode
mailingList = open('managermail.txt', 'w')
#declare workbook variable wb / and load workbook/spreadsheet
wb = openpyxl.load_workbook('test.xlsx')
#declare sheet variable / from workbook and name of sheet to work with
sheet = wb.get_sheet_by_name('Sheet2')

#create for loop to iterate through 182 entries of column B.
for i in range(1,183):
#write cell value to mailing list file named managermail.txt, convert to lowercase
#add email extension and new line break at end of loop
mailingList.write(str.lower(sheet.cell(row=i,column=2).value) + "\n")

#close file

This entry was posted in Tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *