'Excel Table pasted into Word Document

I am trying to populate a word template with an xlsx table. This is the sample output once I save to word if the xlsx data in notes is too long then the table will not follow the specified dimensions.

Sample output:

screenshot

from win32com import client
excel = client.Dispatch("Excel.Application")

sheets = excel.Workbooks.Open(name)
work_sheets = sheets.Worksheets[0]

# work_sheets.Rows.AutoFit()
# work_sheets.Columns.WrapText = True

work_sheets.PageSetup.Orientation = 2
sheets.SaveAs(name2)
sheets.Close(True)
excel.Application.Quit()

word = client.Dispatch("Word.Application")

rowcount = self.tableview.model().rowCount()
colcount = self.tableview.model().columnCount()
doc = word.Documents.Open(target)

# Convert into PDF File
excel2 = client.Dispatch("Excel.Application")
final_copy = excel2.Workbooks.Open(name2)
final_copy_sheet = final_copy.Worksheets[0]
final_copy_sheet.Range(final_copy_sheet.Cells(1,2),final_copy_sheet.Cells(rowcount+2,colcount)).Copy()      # Selected the table I need to copy

wdRange = doc.Content
wdRange.PasteExcelTable(False, False, False)
doc.SaveAs(final_pdf_path , FileFormat=17)
doc.Close()
word.Quit()
excel2.Application.Quit()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source