C# Snippets


getCalculationSetting

public static ExcelCalculationSetting getCalculationSetting(Excel.Application excelApp)
{
try
{
ExcelCalculationSetting calcSetting = null;

if (excelApp != null)
{
calcSetting = new ExcelCalculationSetting(excelApp.Calculation, excelApp.Iteration, excelApp.MaxIterations);
}
else
{
calcSetting = null;
}
return calcSetting;
}
catch (System.Exception ex)
{
ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
return null;
}
}


setCalculationMode

public static void setCalculationMode(Excel.Application excelApp, ExcelCalculationSetting calculationSetting)
{
try
{
if (calculationSetting == null)
{
return;
}

if (excelApp.Calculation != calculationSetting.getCalculationMode())
{
excelApp.Calculation = calculationSetting.getCalculationMode();
// excelApp.Calculation = Excel.XlCalculation.xlCalculationSemiautomatic;
}

if (excelApp.Iteration != calculationSetting.getIterationFlag())
{
excelApp.Iteration = calculationSetting.getIterationFlag();
// excelApp.Iteration = true;
}

if (excelApp.MaxIterations != calculationSetting.getMaxIterations())
{
excelApp.MaxIterations = calculationSetting.getMaxIterations();
excelApp.MaxIterations = 1;
}
}
catch (System.Exception ex)
{
ExceptionHandling.MessageShow(System.Reflection.MethodBase.GetCurrentMethod(), ex);
}
}


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top