【发布时间】:2021-01-17 04:10:37
【问题描述】:
我开发了一个脚本,它使用 xlwings 打开大量受保护(不受密码保护,只是受保护)的 excel 文件,读取每个文件中的一列并将其写入字典,然后关闭。它可以正常工作而不会产生任何错误,但是速度非常慢。 有没有比我下面的代码更快的方法?
import xlwings as xw
def unprotect_xls(filename, date):
workbook = xw.Book(filename)
sheet = workbook.sheets['Table1']
error_length[date] = dict(zip(range(1,21), sheet['BN7:BN26'].value))
workbook.close()
#### not working example ####
file_names = ['file1', 'file2', ..., 'file999']
dates = ['date1', ...]
new_files = len(file_names)
# make dict
error_length = {}
# open excel in background
app = xw.App(visible=False)
#fill dict
for i in range(new_files):
unprotect_xls(file_names[i], dates[i])
app.quit()
【问题讨论】:
标签: python excel protected xlwings