mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Added python script for merging excel files
Added Excel_Files_Merger script to project list Added Github link
This commit is contained in:
parent
a27721725a
commit
991f0c2e88
35
Excel_Files_Merger/Combine excel files into 1.py
Normal file
35
Excel_Files_Merger/Combine excel files into 1.py
Normal file
|
@ -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)
|
9
Excel_Files_Merger/README.md
Normal file
9
Excel_Files_Merger/README.md
Normal file
|
@ -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.
|
|
@ -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) |
|
| [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) |
|
|[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) |
|
|[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)|
|
|[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)|
|
|[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) |
|
|[Flash card quizzer](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Flash-card-Challenge) |[Utkarsh Sharma](https://github.com/Utkarsh1308) |
|
||||||
|
|
Loading…
Reference in New Issue
Block a user