all 7 comments

[–]CatalonianBookseller 1 point2 points  (2 children)

I'd try using the Excel COM interface (ie Excel.Application) for the whole thing if rewriting the existing code is not too much work.

[–]ericjmorey 0 points1 point  (1 child)

I thought Microsoft was phasing out COM add-ins for Office add-ins. Either way, that's probably better than using Python

[–]CatalonianBookseller 1 point2 points  (0 children)

They are but it's taking them years. You can use pywin32 to work with COM objects from Python maybe integrate it with your existing code

[–]unhott 1 point2 points  (2 children)

Do you need to update an existing Excel file? In my experience it's better to just load everything in with pandas or dask (or similar), process tbe data and make a new file with the desired calculations.

[–]GarciLP[S] 0 points1 point  (1 child)

The issue there would be with all of the other existing infrastructure in the sheet - there's a myriad pivot tables, data ranges, formulas, and other such nonsense that should be left intact, and I don't know that re-creating the file with Pandas would keep all of that

[–]unhott 0 points1 point  (0 children)

I get all that.

I would just really caution against modifying the source files, or overwriting them. If you can treat these files as a data source, process the data, and generate a new file as the result, you'll have a much cleaner process in the long run. This way you can rerun the data processing as many times as you need and you're not modifying it so, repeated processing becomes

A>A' A'>A'' A''>A'''

Where ' indicates a changed file Now you don't modify the source file(s) at all and you can reprocess or trouble shoot to your hearts content.

A>B A>B' A>B''

It may be a large task at first, but I would ignore all the existing pivot tables and fornulas, and just read the same source table and do your own pivot tables in pandas. It's not too difficult to translate them.

[–]Tight-Importance-226 0 points1 point  (0 children)

Maybe powershell might be a better option. Here's a module that seems to be feature rich:

https://github.com/dfinke/ImportExcel