-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_filler.py
52 lines (43 loc) · 1.85 KB
/
form_filler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import openpyxl
# these functions fill the spreadsheet
#specify the spreadsheet being worked on
wb = openpyxl.load_workbook('type1.xlsx')
# define the number of columns in a 'fields' array for easy iterating
fields = [1,2,3,4,5,6,7]
# redefine fields for use with transport
transfields = [2,3,4,5,6,7,8]
# define a reusable function to fill the rows of the spreadsheet
def fill_row(assignment, position, date, dateNum):
# specify the sheet the data is being added to
sheet = wb['Payment Form']
for i in fields:
if i == 1:
sheet.cell(row=position, column=i).value = assignment['Name']
elif i == 2:
sheet.cell(row=position, column=i).value = assignment['Activity']
elif i == 3:
sheet.cell(row=position, column=i).value = assignment['Time']
elif i == 4:
sheet.cell(row=position, column=i).value = assignment['Hours']
elif i == 5:
sheet.cell(row=position, column=i).value = date[dateNum]
elif i == 6:
sheet.cell(row=position, column=i).value = assignment['Hours']
else:
sheet.cell(row=position, column=i).value = assignment['Rate']
return sheet
# refactored function to fill the rows of the transport sheet
def fill_row_transport(transport):
for i in transfields:
if i == 2:
sheet.cell(row=position, column=i).value = transport['Name']
elif i == 3:
sheet.cell(row=position, column=i).value = transport['Location']
elif i == 4:
sheet.cell(row=position, column=i).value = transport['Type']
elif i == 5:
sheet.cell(row=position, column=i).value = date[dateNum]
elif i == 7:
sheet.cell(row=position, column=i).value = transport['Time']
elif i == 8:
sheet.cell(row=position, column=i).value = transport['Rate']