首页 > 解决方案 > 在 Python 中使用 COM 的 MS Word 表对象“不可索引”

问题描述

我正在尝试使用 COM 接口自动适应 word 文档中存在的所有表的内容。我面临“表格对象不可索引”的问题。如何使用python win32从word文档中获取表格对象?

代码(不工作):

def TableAutoFit():
    MsWord = Sys.OleObject["Word.Application"]  #using TestComplete and not win32com.Both use COM objects.
    if MsWord.ActiveDocument.Tables.Count > 0:
        MsWord.Browser.Target = 7
        for table in MsWord.ActiveDocument.Range().Tables:
            table.AutoFitBehavior(1)

标签: pythonms-wordcomword-table

解决方案


推荐阅读