python—我想更改代码,以便将excel表插入word文档的主体中,而不是插入到文件的末尾

pgx2nnw8  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(185)

我使用此代码在word文档的末尾插入excel表。我想更改它,以便可以在word文档的最后一段之前插入表格。我该怎么做?

from win32com import client
excel = client.Dispatch("Excel.Application")
word = client.Dispatch("Word.Application")
doc = word.Documents.Open(r"C:\Users\crist\word_automation\Summary_template\Summary_output.docx")
book = excel.Workbooks.Open(r"C:\Users\crist\word_automation\Summary_template\summary3.xlsx")
sheet = book.Worksheets(1)
sheet.Range("A1:G40").Copy()    
wdRange = doc.Content
wdRange.Collapse(0)
wdRange.PasteExcelTable(False, False, False) 
book.SaveAs(r"C:\Users\crist\word_automation\Summary_template\summary3.xlsx")
book.Close()
excel.Quit()

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题