views:

514

answers:

3

A project I am working on requires values from a C# application to update 6 values in an Excel sheet. This excel sheet then populates a named range of items and prices, driven by a number of VLOOKUP formulas and worksheets within the same Excel File.

The two columns in the range are named 'Item' & 'Price'.

'Item' is a column of items concatenated from formulas on a spreadsheet, and these appear fine in the DataTable. However, none of the values in the 'Price' column (all number values from VLOOKUP formulas) appear in the DataTable.

When loading the DataTable in C#, I can see that the two columns' types of string and double are fine. If I replace one of the formula derived values with a hard-coded value the DataTable is fine, so I guess the DataTable itself is working as expected.

If I open the Excel file after the values are passed into it, I can see that the input values went in fine and the formulas have calculated correctly.

So, the only thing I can think is causing the problem is that the formulas are not being recalculated after the values are passed into it.

Is there a way to open an excel file in C# and get it to recalculate all the formulas?

A: 

Which driver are you using to open the excel sheet? OLEDB or ODBC?

jdecuyper
sorry, OLEDB for both the update query (adding the values to the sheet) and for the select query which populates the DataTable
lazygamer
+1  A: 

Never mind,

Replaced the OLEDB update with an Excel Interop, opening the Excel file with the Interop allows the formulas to recalculate.

lazygamer
A: 

GAH. Turns out some of the users of this app may not even have Excel installed - so the Excel Interop workaround is no good.

Does anyone know of a way of getting an Excel file to recalculate cell formulas without using the Excel Interop?

lazygamer