Mise à jour de MS Word (ou Open Office) marque-pages avec Python
Question
Je voudrais remplir signets MSWord à partir d'un script python. Je ne peux pas trouver de telles fonctions dans win32com (MSWord) ou dans pyuno (OpenOffice).
Quelqu'un sait comment utiliser les signets de Python?
La solution
Vous ne trouvez pas les fonctions win32com, vous les trouverez dans la documentation de l'objet COM que vous utilisez. Dans ce cas, ce serait Word.Application.
Vous pouvez voir certains exemples de code Python qui utilise cet objet COM créer un signet s.
Le plus récent Modèle Objet de référence se trouve ici à MSDN
Autres conseils
Regardez cet exemple pour votre problème:
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])
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow