#-*- coding:utf-8 -*-
import os
import openpyxl
import pandas as pd
from pandas.core.frame import DataFrame
cellnames = ["A1","D10","L10","C11"]#指定文件单元格的位置
path = r"E:/test/" #目录路径
wb = openpyxl.Workbook()
nsh=[]
FileNames=os.listdir(path)
for fn in FileNames:
fullfilename=os.path.join(path,fn)
print(fullfilename)
wb = openpyxl.load_workbook(fullfilename)
sh = wb["sheet1"]
arr = [sh[n].value for n in cellnames]
wb.close()
print(arr)
nsh.append(arr)
dataframe=pd.DataFrame(nsh)
dataframe.columns=['A1','x','y','test1']#对应单元格读取的列名
dataframe.to_excel('E:/test/输出文件1.xlsx')#输出路径
批量提取多个excel文件指定单元格内容,并汇总到一个新excel文件里
原文作者:hhhsy217
原文地址: https://blog.csdn.net/hhhsy217/article/details/120652757
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
原文地址: https://blog.csdn.net/hhhsy217/article/details/120652757
本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。