从 Python 运行 Excel 宏(但 Excel 进程保留在内存中)
使用以下 python 方法,我调用 Excel 宏。当我让它工作时我很高兴,但是我想知道每次执行此操作时我都可以看到一个与我使用宏的 .XLA 同名的 Windows 临时/锁定文件。
class XlaMakeUnmake:
__configFile = 'xla_svn.cfg'
__vbaTools = 'makeProtected.xla'
__entries = {}
def __init__(self):
self.__readConfig()
def __newDirs(self, dir):
try:
os.makedirs(dir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
### WILL ONLY WORK FOR UNPROTECTED
'''
filePath: path of XLA to unmake
outputDir: folder in which the lightweight xla and its components will be pushed to
'''
def unmake(self, filePath, outputDir):
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = 0
self.__newDirs(outputDir)
xl.Application.Run("'" + os.getcwd() + os.sep + self.__vbaTools + "'!Unmake", filePath, outputDir)
当我打开任务管理器时,我可以看到 Excel 进程仍在运行...如何在工作完成后以干净的方式杀死它? xl.Application.Run
是否正在启动对宏的异步调用?在这种情况下,这可能会很棘手......
谢谢大家! ;)
with the following python method, I make a call to an Excel macro. I was happy when I got that to work, however I was wondering everytime I was executing this I could see a Windows temporary/lock file of the same name as the .XLA I was using the Macro from.
class XlaMakeUnmake:
__configFile = 'xla_svn.cfg'
__vbaTools = 'makeProtected.xla'
__entries = {}
def __init__(self):
self.__readConfig()
def __newDirs(self, dir):
try:
os.makedirs(dir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
### WILL ONLY WORK FOR UNPROTECTED
'''
filePath: path of XLA to unmake
outputDir: folder in which the lightweight xla and its components will be pushed to
'''
def unmake(self, filePath, outputDir):
xl = win32com.client.Dispatch("Excel.Application")
xl.Visible = 0
self.__newDirs(outputDir)
xl.Application.Run("'" + os.getcwd() + os.sep + self.__vbaTools + "'!Unmake", filePath, outputDir)
When I open the task manager, I can see that an Excel process is still running... How to kill it but in a clean fashion when the job is done ? Is xl.Application.Run
launching an asynchronous call to the Macro ? In which case it might be tricky...
Thanks guys !! ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不懂Python,但你需要使用:
I don't know Python, but you need to use: