I need to be able to recalculate individual sheets but couldn't find any method in the source code that does this. I have a subclass of the ExcelFile class so I created a new method with the following code:
procedure TInterfacedXlsFile.RecalcActiveSheet; var ws: TSheet; sheetIndex: integer; begin sheetIndex := self.ActiveSheet; ws := TryCast<TSheet>.Convert(InternalWorkbook.Sheets[sheetIndex - 1]); ws.Cells.Recalc(self, sheetIndex); end;
However, this doesn't appear to work - any better ideas?
sorry, there is no way to calculate a single sheet, and it would't be trivial to implement, because when a formula in a sheet references another sheet (say you have =Sheet2!a1 in sheet1), the calculation engine automatically jumps to calculating the cell in sheet2.
Why do you want to calculate a single sheet? Is it for performance reasons?
Yes it's for performance reasons - my app is primarily based on
custom worksheet functions and the user needs control over
re-calculation at a worksheet level. Also, I'm trying to keep it as
Excel-like as possible, so they can do Shift + F9 to recalc the active
sheet.
I see that there's a RecalcCell
method - I could probably put together a custom dependency graph for the
worksheet and call RecalcCell multiple times - does this sound
feasible?
RecalcExpression looks like it might also be helpful. In the source there's mention of a demo DocExamples but I can't find that anywhere in the Flexcel folder.