Hi,
I'm generating a workbook dynamically and I got a Range with a formula that uses another calculated values. This is the Formula code
rangeC.Formula = $"=MIN(COUNTIF(D49:CD59,\"<=\"&{rangeB.AddressLocal})-COUNTIF(D49:CD59,\"<\"&{rangeA.AddressLocal}))";
The problem is that if I save the workbook, it takes like 14 minutes and maybe I got a timeout. But If I replace that formula with static values, it is saved instantly.
I'm using a lot if this ranges with the same formula (iteration) to generate a Chart. If I remove the chart the workbook is saved quick too.
I've tried to get the CalculatedValue of that cell but I got #VALUE!. and If I put that Formula into an XLS File works well.
Is there any bug on the CountIF function? maybe with the charts?
|
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Instantiate the Excel application object
IApplication application = excelEngine.Excel;
//Assigns default application version
application.DefaultVersion = ExcelVersion.Xlsx;
//Load the file into stream
FileStream inputStream = new FileStream("Formula.xlsx", FileMode.Open);
//Loads or open an existing workbook through Open method of IWorkbooks
IWorkbook workbook = application.Workbooks.Open(inputStream);
//Access first worksheet from the workbook
IWorksheet worksheet = workbook.Worksheets[0];
if (worksheet.CalcEngine == null)
{
//Enables the calculation support.
worksheet.EnableSheetCalculations();
}
//Specifies the maximum number of recursive calls that can be used to compute a cellvalue.
worksheet.CalcEngine.MaximumRecursiveCalls = 10000;
//maximum number of iterative calls that can be made on a cell.
worksheet.CalcEngine.IterationMaxCount = 10000;
//The CalcQuick will throw an exception when it detects a circular calculation.
worksheet.CalcEngine.ThrowCircularException = true;
//This is the number of recursive calls that can be made during calculations.
CalcEngine.MaxStackDepth = 10000;
//Dates can be used as operands in calculations
worksheet.CalcEngine.UseDatesInCalculations = true;
//Strings concatenated using the '&' operator should be returned inside double quote marks.
worksheet.CalcEngine.UseNoAmpersandQuotes = true;
//Formula returns its FormulaValue instead of repeated calculation
worksheet.CalcEngine.UseFormulaValues = true;
//IF function calculations should specifically avoid computing the non-used alternative.
worksheet.CalcEngine.AllowShortCircuitIFs = true;
FileStream stream = new FileStream("Formula_Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
workbook.SaveAs(stream);
stream.Dispose();
} |
Thanks,
I've added the code you suggested, but is still taking forever to generated the document.
I'm attaching one example of the file we are generating. The formula is on row 38, and we are using the data on row 42 to generate the Chart.
Thanks.
Hi Ramya,
I think that the problem was caused because the formula should be
rangeC.Formula = $"=MIN(COUNTIF(D49:CD59;\"<=\"&{rangeB.AddressLocal})-COUNTIF(D49:CD59;\"<\"&{rangeA.AddressLocal}))";
and NOT
rangeC.Formula = $"=MIN(COUNTIF(D49:CD59,\"<=\"&{rangeB.AddressLocal})-COUNTIF(D49:CD59,\"<\"&{rangeA.AddressLocal}))";
The change was a ;
Thanks, I will continue reviewing it.
We are using:
Syncfusion.XlsIO.Net.Core (19.4.0.47)
Syncfusion.XlsIORenderer.Net.Core (19.4.0.47)