diff --git a/Excel_Files_Merger/Combine excel files into 1.py b/Excel_Files_Merger/Combine excel files into 1.py new file mode 100644 index 0000000..689fa4e --- /dev/null +++ b/Excel_Files_Merger/Combine excel files into 1.py @@ -0,0 +1,35 @@ +from openpyxl import load_workbook +from openpyxl import Workbook +import os + + +# Read data from active worksheet and return it as a list +def reader(file): + global path + abs_file = os.path.join(path, file) + wb_sheet = load_workbook(abs_file).active + rows = [] + # min_row is set to 2, ignore the first row which contains headers + for row in wb_sheet.iter_rows(min_row=2): + row_data = [] + for cell in row: + row_data.append(cell.value) + rows.append(row_data) + return rows + + +# You can replace these with your own headers for the table +headers = ['Nume', 'Prenume', 'Titlu', 'Editura', 'Cota', 'Pret', 'An'] +# Unified excel name +workbook_name = input('Unified Workbook name ') +book = Workbook() +sheet = book.active +# Specify path +path = input('Path: ') +# Get all files from folder +files = os.listdir(path) +for file in files: + rows = reader(file) + for row in rows: + sheet.append(row) + book.save(filename=workbook_name) diff --git a/Excel_Files_Merger/README.md b/Excel_Files_Merger/README.md new file mode 100644 index 0000000..6753902 --- /dev/null +++ b/Excel_Files_Merger/README.md @@ -0,0 +1,9 @@ +# Excel Files Merger +A simple script that excel files with similar table structure from a given path as input and creates a unified excel workbook. + +## Libraries Required +1. openpyxl +`$pip install openpyxl` + +## Usage +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. \ No newline at end of file diff --git a/README.md b/README.md index cbd22ec..08c961e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ So far, the following projects have been integrated to this repo: | [Crypt socket](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Crypt_Socket)|[Willian GL](https://github.com/williangl) | |[Current City Weather](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Current_City_Weather) |[Jesse Bridge](https://github.com/jessebridge) | |[Directory organizer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Directory-organizer) | [Athul P](https://github.com/athulpn) | +|[Excel Files Merger](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Excel_Files_Merger) | [Andrei N](https://github.com/Andrei-Niculae)| |[Excel to List](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Excel_to_ListofList) | [Nitish Srivastava](https://github.com/nitish-iiitd)| |[File explorer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/File-Explorer-Dialog-Box) | [Nikhil Kumar Singh](https://github.com/nikhilkumarsingh)| |[Flash card quizzer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Flash-card-Challenge) |[Utkarsh Sharma](https://github.com/Utkarsh1308) |