V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
QianGu
V2EX  ›  Python

怎么查看 pywin32 的 API 文档

  •  
  •   QianGu · 2020-12-10 14:15:13 +08:00 · 1773 次点击
    这是一个创建于 1226 天前的主题,其中的信息可能已经有所发展或是发生改变。

    因为其他的常用 package 无法满足需求,只能使用 com,但是貌似 com 的接口和 pywin32 不是完全一致,求问怎么查看 pywin32 提供的 API 接口呢,官网没有提供文档,dir()help() 也不够用。

    举个例子

    app = DispatchEx('Excel.Application')
    book = app.Workbooks.Open('my_file.xls)
    sheet = book.Worksheets('sheet1')
    # calculate coordinates
    sheet.Shapes.AddLine(x1, y1, x2, y2)
    

    我想设置 line 的属性,但是不知道相关接口是什么。

    8 条回复    2020-12-10 15:11:57 +08:00
    ysc3839
        1
    ysc3839  
       2020-12-10 14:24:55 +08:00 via Android
    我没用过 pywin32,只用过 comtypes,印象中后者可以看 IDispatch 的函数列表的。
    或者可以直接看 Excel 的文档。
    krixaar
        2
    krixaar  
       2020-12-10 14:33:25 +08:00
    https://docs.microsoft.com/en-us/office/vba/api/excel.shapes.addline
    Excel 的话,直接看 VBA 的文档得了,估计用起来差不多。
    imn1
        3
    imn1  
       2020-12-10 14:36:26 +08:00   ❤️ 1
    google: "pywin32.chm"
    QianGu
        4
    QianGu  
    OP
       2020-12-10 14:46:12 +08:00
    @ysc3839 我遇到的问题就是 pywin32 的接口和 Excel 的文档接口似乎不一样,Excel 的文档里面是 VB 接口,照着类似的语法写 python 报错了,但是又没有途径知道 pywin32 提供准确的接口,基本都是靠猜来写的。
    还是说,这个例子中的 sheet 的属性、方法这些接口本身已经不是 pywin32 的了?
    QianGu
        5
    QianGu  
    OP
       2020-12-10 14:47:56 +08:00
    @krixaar 确实,我就是看着 VB 猜着写 python,可以 addline 但是不会改属性 :(
    ysc3839
        6
    ysc3839  
       2020-12-10 14:49:24 +08:00 via Android   ❤️ 1
    @QianGu 我之前用 comtypes,看 Excel 的 VBA 文档,似乎没什么问题……
    个人还是推荐用 comtypes,pywin32 带了一大堆东西,太重了。
    QianGu
        7
    QianGu  
    OP
       2020-12-10 15:03:06 +08:00
    @ysc3839 谢谢~我试试
    QianGu
        8
    QianGu  
    OP
       2020-12-10 15:11:57 +08:00
    @imn1 谢谢,pywin32 的文档本身有在线的,也有离线的,就在 package 目录下面。
    StackOverflow 上也有相同的问题,
    https://stackoverflow.com/questions/5481686/why-cant-i-find-any-pywin32-documentation-resources

    应该是我问错问题了,我的问题应该是从 VB 的语法映射到 python 语法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   899 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 21:08 · PVG 05:08 · LAX 14:08 · JFK 17:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.