Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 在循环外部注册xll加载项_Loops_Xlwings - Fatal编程技术网

Loops 在循环外部注册xll加载项

Loops 在循环外部注册xll加载项,loops,xlwings,Loops,Xlwings,这段代码需要6分钟来做一些计算,循环2K xlsx文件,其中包含39 X 10个股票基本面数据单元格。我想知道是否可以通过在循环开始之前注册xll加载项来加快速度。如果我手动运行一个接一个的stock,我就不必继续重新安装addin import xlwings as xw app = xw.App(visible=False) # ?Workaround possible to place registration here stocks = next(os.walk(path5))[2]

这段代码需要6分钟来做一些计算,循环2K xlsx文件,其中包含39 X 10个股票基本面数据单元格。我想知道是否可以通过在循环开始之前注册xll加载项来加快速度。如果我手动运行一个接一个的stock,我就不必继续重新安装addin

import xlwings as xw

app = xw.App(visible=False)
# ?Workaround possible to place registration here
stocks = next(os.walk(path5))[2]
for stock in stocks:
    wb = xw.Book(path5 + stock)
    wb.app.api.RegisterXLL('C:/Users/Owner/AppData/Roaming/Microsoft/AddIns/vsoft15.xll')
    ws = wb.sheets[0]
    // do stuff

当然,您也不必在每个循环中实例化book对象:

将xlwings作为xw导入
app=xw.app(可见=False)
wb=xw.Book(路径5+库存)
wb.app.api.RegisterXLL('C:/Users/Owner/AppData/Roaming/Microsoft/AddIns/vsoft15.xll'))
ws=wb.sheets[0]
stocks=next(os.walk(path5))[2]
对于库存:
#dostuff:ws['A1'].value