首页 > 解决方案 > 查找类似于 xlwings 包的 PyWin32 方法

问题描述

目前我正在使用 xlwings 打开我的 Excel 工作簿,并且可以使用“查找”方法捕获特定单元格中的数据。但是,xlwings 打开 Excel 需要花费很多时间,我想将 xlwings 包替换为 PyWin32 包,以用于我的开发。

但我找不到像 xlwings 一样的方法。有什么方法可以在 Excel 中捕获数据,例如可以在 PyWin32 中实现的 xlwings。

感谢你的帮助。

下面是 xlwings 中的代码示例:

find_location = wbook.api.Cells.Find(What='car',
                          LookAt=xlwings.constants.LookAt.xlWhole
                          LookIn=xlwings.constants.FindLookIn.xlFormulas,
                          SearchOrder=xlwings.constants.SearchOrder.xlByColumns,
                          SerchDirection=xlwings.constants.SearchDirection.xlNext,
                          MatchCase = False)

标签: pythonexcelpywin32xlwingsvba

解决方案


我第一次来这里是为了寻找 pywin32 lookat xlwhole。所以我没有测试上述查询的所有部分。但我确实测试了“LookAt”,并阅读了 Microsoft 的 Excel Range.Find 方法,我相信所有部件的工作机会都很好。

What、LookAt、LookIn、Searchorder、SearchDirection 和 MatchCase 都是 Microsoft 标准 Range.Find 调用参数的一部分(因此也是 Cells.Find 的一部分)。Pywin32 似乎缺少的只是常量。

从 Microsoft 文档中,声明“LookAt=1”给出与“LookAt=xlwings.constants.LookAt.xlWhole”相同的结果。

这样的发现使用 pywin32 运行良好。


推荐阅读