I have been following Automate the Boring Stuff, and I wrote a script to take the data from multiple excel daily employee sheets and then saved it into a .py file. Part of the issue there is to add key values to reference or how to reference the data to then move it onto a weekly employee sheet based on name and date? My next step would be taking the excel template and creating new sheets based on the persons name and then referencing the date they worked with the line in the sheet and fill that in from the data in the .py file.
Here is the code I have written so far and a portion of the .py file it created with the names blacked out. Any suggestions would be appreciated.
xlsx_files = [path for path in Path('/Users/Documents/PythonExcel/DTS').rglob('*.xlsx')]
wbs = [openpyxl.load_workbook(wb) for wb in xlsx_files]
employeeData = {}
for idx, ws in enumerate(wbs, start=1):
for sheet in list(ws):
sheet=ws['Daily Time Sheet']
date = ws['Daily Time Sheet']['B3']
date.value = date.value.strftime("%m-%d-%Y")
for key, *values in sheet.iter_rows(min_row=5, max_row=21, min_col=2):
employeeData[date.value, key.value] = [v.value for v in values]
employeeData.setdefault((date.value, key.value), {})
employeeData[date.value,key.value]=+1
print(employeeData.keys())
print('Writing results...')
resultFile = open('weeklytimecard.py', 'w')
resultFile.write(pprint.pformat(employeeData, sort_dicts=True, compact=True))
resultFile.close()
print('Done')