最近工作中需要提取几千个excel表中的指定区域的数据,如图提取此sheet中红色区域部分数据:
红色区域在每个文件中的行列都相同
只提取BH32 sheet页中的内容
求大神帮助!
https://blog.csdn.net/heavenmark/article/details/73518853
import os
import openpyxl
cellnames = ["A1", "B2", "C3"]
path = r"F:\提取名称-test.20221101.zbt" # 目录路径
newbook = openpyxl.Workbook()
nsh = newbook.active
FileNames = os.listdir(path)
for fn in FileNames:
fullfilename = os.path.join(path, fn)
print(fullfilename)
book = openpyxl.load_workbook(fullfilename)
sh = book.active
arr = [sh[n].value for n in cellnames]
book.close()
print(arr)
nsh.append(arr)
newbook.save(r'E:\数据汇总文件.xlsx')
print("读取完成!!!")