[英]Updating MS Word (or Open Office) bookmarks with Python
我想從python腳本中填充MSWord書簽。 我在win32com(MSWord)或PyUno(OpenOffice)中找不到此類功能。
有誰知道如何使用Python中的書簽?
在win32com中找不到這些功能,而是在您正在使用的COM對象的文檔中找到它們。 在這種情況下,它將是Word.Application。
您可以看到一些使用此COM對象創建書簽的Python示例代碼 。
查看此示例以解決您的問題:
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 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.