-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautomation.py
More file actions
36 lines (28 loc) · 999 Bytes
/
automation.py
File metadata and controls
36 lines (28 loc) · 999 Bytes
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
import openpyxl as xl
from openpyxl.chart import BarChart, Reference, PieChart
def process_workbook(filename, filename2):
workbook = xl.load_workbook(filename)
sheet = workbook['Sheet1']
# cell = sheet['a1']
# cell = sheet.cell(1, 1)
# # print(sheet.max_row)
# # print(cell.value)
for row in range(2, sheet.max_row + 1):
cell = sheet.cell(row, 3)
corrected_price = cell.value * 0.9
corrected_price_cell = sheet.cell(row, 4)
corrected_price_cell.value = corrected_price
values = Reference(sheet,
min_row=2,
max_row=sheet.max_row,
min_col=4,
max_col=4)
# chart = BarChart()
# chart.add_data(values)
# sheet.add_chart(chart, 'e2')
chartPie = PieChart()
chartPie.add_data(values)
sheet.add_chart(chartPie, 'e3')
#
workbook.save(filename2)
process_workbook('transactions.xlsx', 'transcationsPieResult.xlsx')