سؤال

أرغب في ملء الإشارات المرجعية MSWOR من برنامج نصي بيثون. لا يمكنني العثور على هذه الوظائف في WIN32COM (MSWORD) أو في Pyuno (OpenOffice).

هل يعرف أحد كيفية استخدام الإشارات المرجعية من بيثون؟

هل كانت مفيدة؟

المحلول

لا تجد الوظائف في Win32com، تجدها في الوثائق لكائن COM الذي تستخدمه. في هذه الحالة سيكون Word.Application.

يمكنك ان ترى بعض عينة رمز Python يستخدم كائن COM هذا لإنشاء إشارة مرجعيةس.

الأحدث تم العثور على مرجع نموذج كائن Word هنا في 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