Excel 워크 시트의 J 열에 비어 있지 않은 값을 찾는 다음 코드를 작성했습니다. K 열에 값의 전자 메일 주소를 가져 오는 것을 포함하여 일부 작업을 수행합니다. 그런 다음 smtp를 사용하여 구성원에게 전자 메일을 보냅니다.Python을 사용하여 Excel 시트의 목록 항목 찾기
대신 코드의 시작 부분에서 선언 할 수있는 Python 목록에서 전자 메일을받는 것이 좋습니다. 목록마다 워크 시트의 J 열에서 일치하는 이름을 찾은 다음 목록에서 결과 이메일 주소를 가져 오는 방법을 알아낼 수 없습니다.
끔찍한 구문을 사용하지 마십시오 ... 이것은 주요 파이썬 프로젝트의 첫 번째 찌르기입니다.
memlist = {'John Frank':'[email protected]',
'Liz Poe':'[email protected]'}
try:
for i in os.listdir(os.getcwd()):
if i.endswith(".xlsx") or i.endswith(".xls"):
workbook = load_workbook(i, data_only=True)
ws = workbook.get_sheet_by_name(wsinput)
cell_range = ws['j3':'j7']
for row in cell_range: # This is iterating through rows 1-7
#for matching names in memlist
for cell in row: # This iterates through the columns(cells) in that row
value = cell.value
if cell.value:
if cell.offset(row=0, column =-9).value.date() == (datetime.now().date() + timedelta(days=7)):
#print(cell.value)
email = cell.offset(row=0, column=1).value
name = cell.value.split(',',1)[0]
저는 파이썬 3.5를 사용하고 있기 때문에 has_key가 작동하지 않는다고 생각합니다. –