views:

47

answers:

1

I am using the excel pia's to do some writing and reading to/from excel spreadsheets, i may just be being paranoid but i have the following questions:

As far as i can tell Excel recalculates the formulas in the worksheet upon every write but...

  1. is this the case? - ie is it possible to do series of write read write read and not to read the correct recalculations (eg if its a complex formula and takes too long could i end up reading a value that has not been recalculated yet?)

  2. is there anyway to do something like:

    BeginUpdate(); write lots of values EndUpdate(); Recalculate(); readlotsofvalues ?

I have not seen any dodgy results but i would like to be able to know "for sure" ;)

+1  A: 

Some VBA functions that will work are here, to use these you can use the SpreadsheetClass in Interop. For C#, you have the Calculate() function.

Lance Roberts
thanks lance the calculate function was the one i was missing. I am still interested to know if excel offers any guarentees that the spreadsheet is consistant when you read from it just after writing to it, and similarly if there is anyway of disabling recalculation whilst i write a large number of cells.
GreyCloud
@Grey, In Excel VBA you'd set Application.Calculation to xlCalculationManual to turn off calculation and xlCalculationAutomatic to turn it back on. While in C# you have to make the calculations work, I'm not so sure how this actually works if the spreadsheet is open, and I don't know about it's consistency or if there are race conditions.
Lance Roberts
Thanks Lance, i will look into turning off the automatic calculation in excel
GreyCloud