我开发了一个脚本,它使用xlwings打开大量受保护(不受密码保护,只受保护)的excel文件,读取每个文件中的一列并将其写入dict,然后关闭。它工作时不会产生任何错误,但速度很慢。 有没有比下面的代码更快的方法
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()
您是否考虑过使用}非常好,但是如果您只需要批量读取单元格值,那么阅读器库可能更适合
openpyxl
或xlrd
执行此任务?您还可以使用pandas.read_excel
函数,该函数在引擎盖下使用这些包中的一个^如果您需要与Excel交互,{相关问题 更多 >
编程相关推荐