推荐学习书目
› 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 · Dec 10, 2020 · 3070 views
    This topic created in 2123 days ago, the information mentioned may be changed or developed.

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

    应该是我问错问题了,我的问题应该是从 VB 的语法映射到 python 语法
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1199 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:39 · PVG 00:39 · LAX 09:39 · JFK 12:39
    ♥ Do have faith in what you're doing.