使用win32com访问Excel文件时出现问题 [英] Issue in using win32com to access Excel file

查看:1077
本文介绍了使用win32com访问Excel文件时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家!
我一直在使用Python中的win32com.client模块来访问包含VBA宏的Excel文件的单元格.
代码 xl = win32com.client.gencache.EnsureDispatch("Excel.Application") 中的一条语句抛出了错误:
AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x6' has no attribute 'MinorVersion'
是否有人遇到过类似的情况?如果可以,对此可以采取什么补救措施? (我已经查看了GitHub上win32com的源代码,但从中没有多大意义.)

everyone!
I have been using the win32com.client module in Python to access cells of an Excel file containing VBA Macros.
A statement in the code xl = win32com.client.gencache.EnsureDispatch("Excel.Application") has been throwing an error:
AttributeError: module 'win32com.gen_py.00020813-0000-0000-C000-000000000046x0x1x6' has no attribute 'MinorVersion'
Has anyone faced a similar situation and, if yes, what can a possible remedy for this? (I've had a look at the source code for win32com on GitHub, but haven't been able to make much sense from it.)

推荐答案

如果我要确保python启动一个新的excel实例(例如,访问我的xlsm文件中的宏),我将使用

If I want to make sure that python starts a new excel instance (for instance to access macros in my xlsm files), I use

xlApp = win32com.client.DispatchEx("Excel.Application")

这样,我可以关闭应用程序而不会损害已经打开的实例.

That way I can close the application without hurting the instance that was already open.

否则,我可以简单地使用

Otherwise, I could simply use

xlApp = win32com.client.Dispatch("Excel.Application")

这对您有用吗?

这篇关于使用win32com访问Excel文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆