Skip to content

Commit 68cd951

Browse files
committed
Automation in excel files
1 parent f9cfa25 commit 68cd951

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Automation_Excel/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# Automation in Excel Files
3+
4+
A small Python application will take an Excel file (.xlsx) as input and will update specific rows and columns, then add a graph to it and save it into a new file.
5+
6+
## Installation
7+
8+
Install the openpyxl
9+
10+
11+
12+
```bash
13+
pip install openpyxl
14+
```
15+
16+
17+
18+

Automation_Excel/automation.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import ValuesView
2+
import openpyxl as xl
3+
from openpyxl.chart import BarChart, Reference
4+
5+
def processing(filename):
6+
wb = xl.load_workbook(filename)
7+
sheet = wb['Sheet1']
8+
cell = sheet.cell(1, 2)
9+
print(sheet.max_row)
10+
for i in range(2, sheet.max_row+1):
11+
print(sheet.cell(i, 3).value)
12+
new_cell = sheet.cell(1, 4)
13+
new_cell.value = "new cell"
14+
for i in range(2, 5):
15+
new_values = sheet.cell(i, 4)
16+
new_values.value = int(input(""))
17+
Values = Reference(
18+
sheet,
19+
min_row = 1,
20+
max_row = 5,
21+
min_col = 1,
22+
max_col = 5
23+
)
24+
chart = BarChart()
25+
chart.add_data(Values)
26+
sheet.add_chart(chart, 'a5')
27+
wb.save(filename)
28+
29+
30+
filename = input("enter the name of the file: ")
31+
processing(filename)

0 commit comments

Comments
 (0)