在Python中使用ctypes加载XLL库?
我们有为 Excel 制作的“内部”XLL 库。假设我们匹配XLL和python之间的32位/64位,我们可以使用ctypes来加载和使用XLL(将其视为DLL)吗?
有人做过这个吗?有任何已知问题和解决方法吗?
编辑:我尝试这样做,但到目前为止没有运气。 Excel 插件适用于 32 位 Excel,因此我认为它是一个 32 位库。
lib = ctypes.CDLL(xll)
在 64 位 python 中,我得到
c:\anaconda3\envs\py38\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
371
372 if handle is None:
--> 373 self._handle = _dlopen(self._name, mode)
374 else:
375 self._handle = handle
OSError: [WinError 193] %1 is not a valid Win32 application
在 32 位 python 中,我得到:
c:\Anaconda\envs\py39_32\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
380
381 if handle is None:
--> 382 self._handle = _dlopen(self._name, mode)
383 else:
384 self._handle = handle
FileNotFoundError: Could not find module 'C:\public\ExcelAddons\alib.0.86\alib.xll' (or one of its dependencies). Try using the full path with constructor syntax.
We have "in house" XLL libraries that we make for Excel. Assuming we match the 32-bit/64-bit ness between the XLL and python, can we use ctypes to load and use the XLL (treating it as a DLL)?
Has anybody done this? Any known issues and work arounds?
Edit: I tried doing this and no luck so far. The Excel add-on works on 32-bit excel, so I figured it was a 32 bit library.
lib = ctypes.CDLL(xll)
In 64 bit python, I get
c:\anaconda3\envs\py38\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
371
372 if handle is None:
--> 373 self._handle = _dlopen(self._name, mode)
374 else:
375 self._handle = handle
OSError: [WinError 193] %1 is not a valid Win32 application
In 32 bit python, I get:
c:\Anaconda\envs\py39_32\lib\ctypes\__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
380
381 if handle is None:
--> 382 self._handle = _dlopen(self._name, mode)
383 else:
384 self._handle = handle
FileNotFoundError: Could not find module 'C:\public\ExcelAddons\alib.0.86\alib.xll' (or one of its dependencies). Try using the full path with constructor syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论