Fills doc first table with data from excel by headers.
This Python script fills a table in a Microsoft Word document with data from an Excel workbook. The script takes four command-line arguments: the name of the Excel file, the name of the Word file, the row number to start reading from in the Excel file, and the number of rows to read.
The script uses the openpyxl library to open the Excel workbook and the docx library to load the Word document. It then gets the first table in the document and the header row of the table. The header row should contain temporary words that will be replaced with data from the Excel worksheet.
The script then loops through the specified rows in the Excel worksheet and adds a new row to the Word table for each row in the worksheet. It replaces the temporary words in the header row with data from the current row of the Excel worksheet using the eval() function, which evaluates a string as a Python expression. Before the eval() function is called, the script also replaces the Unicode quote characters in the temporary words with the appropriate ASCII quote characters to avoid any issues with encoding.
Finally, the modified Word document is saved with a filename starting with "0".