說明:path是你全部文件存放的目錄,先去循環全部的文件內容,而後寫入到test.xls文件裏linux
import os path = 'file' # path=r'D:\file' for filename in os.listdir(path): fullname = os.path.join(path, filename) # 若是是linux系統導出來的數據用utf-8,若是是windows則用gbk f1 = open(fullname, encoding='gbk') for i in f1: if "電子郵箱" in i: continue with open('test.xls',encoding='gbk',mode='a+')as f2: f2.write(i) f2.close() f1.close()