Question

I would like to try and make a program which does the following, preferably in Python, but if it needs to be C# or other, that's OK.

  1. Writes data to an excel spreadsheet
  2. Makes Excel recalculate formulas etc. in the modified spreadsheet
  3. Extracts the results back out

I have used things like openpyxl before, but this obviously can't do step 2. Is the a way of recalculating the spreadsheet without opening it in Excel? Any thoughts greatly appreciated.

Thanks,

Jack

Was it helpful?

Solution

You need some sort of UI automation with which you can control a UI application such as Excel. Excel probably exposes some COM interface that you should be able to use for what you need. Python has the PyWin32 library which you should install, after which you'll have the win32com module available.

See also:

If you don't necessarily have to work with Excel specifically and just need to do spreadsheet using Python, you might want to look at http://manns.github.io/pyspread/.

OTHER TIPS

you could you pandas for reading in the data, using python to recalculate and then write the new files.

For pandas it's something like:

#Import Excel file
xls = pd.ExcelFile('path_to_file' + '/' + 'file.xlsx')
xls.parse('nyc-condominium-dataset', index_col='property_id', na_values=['NA'])

so not difficult. Here the link to pandas.

Have fun!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top