Despite the various Python Excel-manipulation libraries and resources, I am unable to find a specific solution.
Right now, I have a template Excel file where a table exists. I would like to write a Python program in order to populate this table. Is this possible with any of the existing Excel libraries? The template Excel file has a sheet with an empty table (1st screenshot). I want to programmatically populate the table with some data from elsewhere. e.g.
data = [("TS0001", "1.0 Administration", "Root", "vdouk", "15/09/19", 8.0, "example 1"),
("TS0002", "1.0 Administration", "Root", "vdouk", "16/09/19", 3.0, "example 2"),
("TS0003", "4.0 Simulations", "Root", "vdouk", "16/09/19", 5.0, "example 3")]
Thus, I want finally to look like the 2nd screenshot. The total entries and subtotals are computed automatically from appropriate excel cell functions (already defined). Finally, note that this table is referenced from other parts of the workbook, meaning that it is a named data source (seen in the Excel name manager), so defining a new table will cause problems elsewhere. Can someone direct me to the most appropriate solution?
Here's the working logic.
- Open an existing excel file.
- Do not change any formatting.
- Do not delete any existing data.
- Update the excel file with new rows:
- Insert all new rows just below the header row.
- Make sure this puts new rows as part of the existing table.
- Save and close the excel file.
Update
Right now, I am using openpyxl. The workaround I do is to edit the template .xlsx and add empty rows to the table. Then I write as many rows as my data tuples are by using openpyxl. The table totals seem to work, however some other excel macros seem to be breaking.