Hello everyone , This is Wang Feng, a programmer .
Let's start with good news ,python-office Office automation
Our official website is online , Click through https://www.python-office.com
Open source projects today python-office Released a new feature :
1 Line code , Merge multiple... You specify Excel file .
This article gives you a detailed introduction to ~
There is a teacher , Now there is the whole school 1 grade 12 All the students in the class , altogether 12 Transcripts Excel file
, Now the teacher wants to merge them into one file : In grade one .xlsx
in , Each class as a separate sheet Deposit . As shown in the figure ,
You can rest assured here , Even if the format of each table 、 The content is different , It can also be merged without damage . Here is an example of merging class grades , Just for better understanding .
Let's use one line of code , Realize the above functions .
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple python-office -U
# Import this library :python-office, Shorthand for officeimport office#1 Line code , Verify whether the binding is successful office.excel.merge2excel(dir_path=r'C:\ Programmer Wanfeng \excel-merge\excel',output_file='test.xlsx')# Parameter function :# dir_path = Folder location , It is recommended to merge multiple excel Put the files in the same folder .# output_file = Finally merged excel Where are the documents 、 What's the name , Can not fill , The default is :merge2excel.xlsx
Run the above code directly , You can get a merged excel Documents ~
Let's try ~
If there is something I didn't make clear , Or there are problems in the process of use , Welcome to communicate with me in the comment area ~