简体   繁体   English

xlwings可以在后台运行excel吗?

[英]can xlwings run excel in the background?

I run a Python XLWings code where multiple Excel files are called sequentially. 我运行Python XLWings代码,其中依次调用了多个Excel文件。 Although the code closes each Excel after dealing with it (and no more than 1 excel is open at any given moment), the process becomes increasingly slow. 尽管代码在处理完每个Excel后都将其关闭(并且在任何给定时刻打开的Excel均不超过1个),但是该过程变得越来越慢。 Memory tests show that residual processes remain after closing excel files. 内存测试表明,关闭excel文件后,残留过程仍然存在。

Is there a smoother way to do this? 有没有更流畅的方法可以做到这一点? Can maybe XLWings call these Excel files in background mode, without spending time and memory on loading the interface? 也许XLWings可以在后台模式下调用这些Excel文件,而无需花费时间和内存来加载界面?

Thank you for your help. 谢谢您的帮助。

Yes, xlwings does also allow you to keep the Excel application invisibly in the background. 是的, xlwings还允许您将Excel应用程序隐藏在后台。 For this you must use an xlwings.App object with input parameter visible=False . 为此,您必须使用输入参数visible=Falsexlwings.App对象。

Simple example: 简单的例子:

import xlwings as xw

app = xw.App(visible=False)
book = app.books[0]
sheet = book.sheets[0]

sheet.range('A1').value = 73913

book.save('book.xlsx')
app.kill()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM