我想从Python脚本中填写MSWORD书签。我在Win32COM(MSWORD)或PYUNO(OpenOffice)中找不到此类功能。

有人知道如何使用Python的书签吗?

有帮助吗?

解决方案

您找不到Win32COM中的功能,而是在使用的COM对象的文档中找到它们。在这种情况下,这将是Word.Application。

你可以看到 一些使用此com对象创建书签的示例Python代码s。

最近的 单词对象模型参考可在MSDN找到

其他提示

查看此示例有关您的问题:

def addText(self, bookmark):
    self.wordApp.ActiveDocument.Bookmarks(bookmark).Select()
    self.wordApp.Selection.TypeText(self.some_text)

# from pandas data frame into word table 
def addTable(self, bookmark, df):
    self.wordApp.ActiveDocument.Bookmarks(bookmark).Select()
     table = location.Tables.Add(location, len(df) + 1, len(df.columns), 1, 1)
    table.AutoFormat(40)
    for i, item in enumerate(df):
        table.Cell(1, i + 1).Range.InsertAfter(item)
        table.Cell(1, i + 1).Range.ParagraphFormat.Alignment = 1
    sel.SelectRow()
    sel.BoldRun()
    table.Rows(1).HeadingFormat = True
    for c in range(2, len(df) + 2):
        for r in range(1, len(df.columns) + 1):
            table.Cell(c, r).Range.ParagraphFormat.Alignment = 1
            if pd.isnull(df.ix[c - 2][r - 1]):
                continue
            table.Cell(c, r).Range.InsertAfter(df.ix[c - 2, r - 1])
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top