|
static void Main(string[] args)
{
ExcelEngine excelEngine = new ExcelEngine();
var excelApplication = excelEngine.Excel;
using (var embedStream = EmbeddedFiles.OpenFile(EmbeddedFiles.ExcelDocumentName))
xlsxWorkbook = excelApplication.Workbooks.Open(embedStream, ExcelOpenType.Automatic);
worksheet = xlsxWorkbook.Worksheets.First();
var maxSize = 10000000;
var thread = new Thread(GetCalculatedValue, maxSize);
thread.Start();
thread.Join();
}
private static void GetCalculatedValue()
{
worksheet = xlsxWorkbook.Worksheets[0];
worksheet.EnableSheetCalculations();
worksheet.CalcEngine.UseFormulaValues = true;
worksheet.CalcEngine.AllowShortCircuitIFs = true;
worksheet.CalcEngine.MaximumRecursiveCalls = 10000;
worksheet.CalcEngine.IterationMaxCount = 10000;
worksheet.CalcEngine.ThrowCircularException = true;
CalcEngine.MaxStackDepth = 10000;
foreach (IRange cell in worksheet.UsedRange.Cells.Where(r => r.HasFormula))
{
try
{
// Trigger formula to update
string dummy = worksheet.CalcEngine.PullUpdatedValue(cell.AddressLocal);
}
catch (Exception e)
{
Debug.WriteLine("Failed to update cell with formula: " + cell.Formula + " at " + cell.AddressLocal);
}
}
} |