//new ms for ExcelEngine
using (MemoryStream inStream = new MemoryStream())
{
using (Stream fs = File.Open(productFileEstimatorPath, FileMode.Open, FileAccess.Read))
{
await fs.CopyToAsync(inStream);
fs.Dispose();
}
//new excel engine
using (ExcelEngine excelEngine = new ExcelEngine())
{
inStream.Position = 0;
//open the existing workbook
IWorkbook workbook = excelEngine.Excel.Workbooks.Open(inStream);
workbook.CalculationOptions.CalculationMode = ExcelCalculationMode.Manual;
workbook.CalculationOptions.IsIterationEnabled = true;
//inputs
InputCalculationWriter(workbook, inputParams, product);
//recalc all formulas
foreach (var sheetObj in workbook.Worksheets)
sheetObj.EnableSheetCalculations();
foreach (var sheetObj in workbook.Worksheets)
sheetObj.DisableSheetCalculations();
//outputs
IWorksheet outputSheet = wb.Worksheets[(int)FileSheetNames.OUTPUT];
//export the sheet data calculated in a dataTable
DataTable outputTable = outputSheet.ExportDataTable(outputSheet.UsedRange,
ExcelExportDataTableOptions.ComputedFormulaValues | ExcelExportDataTableOptions.ColumnNames);
// Close the instance of IWorkbook
workbook.Close();
//Dispose the instance of ExcelEngine
excelEngine.Dispose();
}
inStream.Dispose();
}