Skip to content

Commit 991f0c2

Browse files
committedOct 5, 2019
Added python script for merging excel files
Added Excel_Files_Merger script to project list Added Github link
1 parent a277217 commit 991f0c2

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from openpyxl import load_workbook
2+
from openpyxl import Workbook
3+
import os
4+
5+
6+
# Read data from active worksheet and return it as a list
7+
def reader(file):
8+
global path
9+
abs_file = os.path.join(path, file)
10+
wb_sheet = load_workbook(abs_file).active
11+
rows = []
12+
# min_row is set to 2, ignore the first row which contains headers
13+
for row in wb_sheet.iter_rows(min_row=2):
14+
row_data = []
15+
for cell in row:
16+
row_data.append(cell.value)
17+
rows.append(row_data)
18+
return rows
19+
20+
21+
# You can replace these with your own headers for the table
22+
headers = ['Nume', 'Prenume', 'Titlu', 'Editura', 'Cota', 'Pret', 'An']
23+
# Unified excel name
24+
workbook_name = input('Unified Workbook name ')
25+
book = Workbook()
26+
sheet = book.active
27+
# Specify path
28+
path = input('Path: ')
29+
# Get all files from folder
30+
files = os.listdir(path)
31+
for file in files:
32+
rows = reader(file)
33+
for row in rows:
34+
sheet.append(row)
35+
book.save(filename=workbook_name)

‎Excel_Files_Merger/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Excel Files Merger
2+
A simple script that excel files with similar table structure from a given path as input and creates a unified excel workbook.
3+
4+
## Libraries Required
5+
1. openpyxl
6+
`$pip install openpyxl`
7+
8+
## Usage
9+
A sample script 'Combine excel files into 1.py' has been provided to show the usage of the Excel Merger. When the scipt is run, it will ask for the name of the Unified Workbook and the path of the folder containing the excel files that need to be merged.

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ So far, the following projects have been integrated to this repo:
2424
| [Crypt socket](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Crypt_Socket)|[Willian GL](https://github.com/williangl) |
2525
|[Current City Weather](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Current_City_Weather) |[Jesse Bridge](https://github.com/jessebridge) |
2626
|[Directory organizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Directory-organizer) | [Athul P](https://github.com/athulpn) |
27+
|[Excel Files Merger](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Excel_Files_Merger) | [Andrei N](https://github.com/Andrei-Niculae)|
2728
|[Excel to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Excel_to_ListofList) | [Nitish Srivastava](https://github.com/nitish-iiitd)|
2829
|[File explorer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File-Explorer-Dialog-Box) | [Nikhil Kumar Singh](https://github.com/nikhilkumarsingh)|
2930
|[Flash card quizzer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Flash-card-Challenge) |[Utkarsh Sharma](https://github.com/Utkarsh1308) |

0 commit comments

Comments
 (0)