forked from prathimacode-hub/Awesome_Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcel_file_automation.py
60 lines (55 loc) · 1.21 KB
/
excel_file_automation.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
53
54
55
56
57
58
59
60
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
from openpyxl.styles import Font
#making the grid and giving the data
data = {
"Joe": {
"math": 65,
"science": 78,
"english": 98,
"gym": 89
},
"Bill": {
"math": 55,
"science": 72,
"english": 87,
"gym": 95
},
"Tim": {
"math": 100,
"science": 45,
"english": 75,
"gym": 92
},
"Sally": {
"math": 30,
"science": 25,
"english": 45,
"gym": 100
},
"Jane": {
"math": 100,
"science": 100,
"english": 100,
"gym": 60
}
}
wb = Workbook()
ws = wb.active
#assigning the title
ws.title = "Grades"
#giving proper formatting for columns
headings = ['Name'] + list(data['Joe'].keys())
ws.append(headings)
#reading the data for persom
for person in data:
grades = list(data[person].values())
ws.append([person] + grades)
for col in range(2, len(data['Joe']) + 2):
char = get_column_letter(col)
ws[char + "7"] = f"=SUM({char + '2'}:{char + '6'})/{len(data)}"
#assigning the colour and text type
for col in range(1, 6):
ws[get_column_letter(col) + '1'].font = Font(bold=True, color="0099CCFF")
#saving the excel file in the same folder
wb.save("NewGrades.xlsx")