程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

1 line of Python code, merging 100 Excel files, so convenient?!

編輯:Python


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 ~

Requirement specification

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 .

1 Line code implementation

Let's use one line of code , Realize the above functions .

install python-office This library

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple python-office -U

1 Line code

# 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 ~

Read more


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved