I want to copy Excel data (e.g. tables or specific range) and paste it at the end of a MS Word document's paragraph without replacing its text. The aforementioned process should be done by using Python and ideally by using pywin32 (win32com.client).
The below code works great, but the Excel data can only be pasted at the beginning of the Word document:
def copy_from_excel_paste_to_word(word_filename, excel_filename):
# Word init
word = client.Dispatch("Word.Application")
word.Visible = True
report = word.Documents.Open(word_path)
wdRange = report.Content
# Excel init
excel = client.Dispatch("Excel.Application")
checklist = excel.Workbooks.Open(excel_path)
sheet = checklist.Worksheets("Names")
sheet.Range("B2:D15").Copy()
# Paste Excel data at the beginning of the doc, while keeping doc data
wdRange.Collapse(1)
wdRange.PasteExcelTable(False, False, False) # ? How can i specify the paste location ?
# Save and quit
word.ActiveDocument.Close(SaveChanges=True)
excel.Quit()
word.Quit()
for rng in report.StoryRangesand then scan therngfor specific identifiers