Python으로 MS Word (또는 Open Office) 북마크 업데이트
문제
Python 스크립트에서 Msword 북마크를 채우고 싶습니다. Win32com (Msword) 또는 Pyuno (OpenOffice)에서 그러한 기능을 찾을 수 없습니다.
파이썬에서 북마크를 사용하는 방법을 아는 사람이 있습니까?
해결책
Win32com에서 기능을 찾지 못하며 사용중인 COM 객체에 대한 문서에서 찾을 수 있습니다. 이 경우 Word.application입니다.
너는 볼 수있어 이 COM 객체를 사용하여 북마크를 만드는 일부 샘플 파이썬 코드에스.
다른 팁
문제는이 예를 살펴보십시오.
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])
제휴하지 않습니다 StackOverflow