-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
21 lines (18 loc) · 657 Bytes
/
test.py
File metadata and controls
21 lines (18 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import openpyxl as xl
from openpyxl.chart import BarChart, Reference
def process_workbook(filename):
wb = xl.load_workbook(filename)
sheet = wb["Sheet1"]
new_head = sheet.cell(1,4)
new_head.value = "new_price"
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=4,min_col=4,max_col=4)
chart = BarChart()
chart.add_data(values)
sheet.add_chart(chart,"e2")
wb.save(filename)
process_workbook("transactions.xlsx")