缺失功能

如果你希望xlwings中有一个新功能,可以这么做:

  1. Most importantly, open an issue on GitHub. Adding functionality should be user driven, so only if you tell us about what you’re missing, it’s eventually going to find its way into the library. By the way, we also appreciate pull requests!

  2. Workaround: in essence, xlwings is just a smart wrapper around pywin32 on Windows and appscript on Mac. You can access the underlying objects by calling the api property:

    >>> sheet = xw.Book().sheets[0]
    >>> sheet.api
    <COMObject <unknown>>  # Windows/pywin32
    app(pid=2319).workbooks['Workbook1'].worksheets[1]  # Mac/appscript
    

    This works accordingly for the other objects like sheet.range('A1').api etc.

    底层对象几乎提供了所有可以用VBA处理的东西,使用pywin32语法(和VBA很类似)或者appscript语法(不像VBA)可以处理。 不过这种变通方法,除了不好看,而且一定要记住 这会让你的代码依赖于平台(!) 也就是说,即便选择了方案2),你还是应该根据方案1)的建议,到Github上提出一个问题,以便你需要的功能能够出现在新的xlwings库里面(那可是跨平台的,而且是用Python的哦)。

举例:使用VBA Range.WrapText 的变通办法

# Windows
sheet.range('A1').api.WrapText = True

# Mac
sheet.range('A1').api.wrap_text.set(True)