|
//Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2016;
//Create a workbook
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet sheet = workbook.Worksheets[0];
//Assign array formula
sheet.Range["A1:D1"].FormulaArray = "{1,2,3,4}";
//Adding a named range for the range A1 to D1
sheet.Names.Add("ArrayRange", sheet.Range["A1:D1"]);
//Assign formula array with named range
sheet.Range["A2"].Text = "SUM";
sheet.Range["B2"].FormulaArray = "Sum(ArrayRange)";
sheet.Range["A3"].Text = "MIN";
sheet.Range["B3"].FormulaArray = "Min(ArrayRange)";
sheet.Range["A4"].Text = "MAX";
sheet.Range["B4"].FormulaArray = "Max(ArrayRange)";
//Saving the Excel to the MemoryStream
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);
} |
Hi Alex,Greetings from Syncfusion support.Kindly look into the following code snippet which shows how to apply SUM/MIN/MAX formulas to array.Code snippet:
//Create an instance of ExcelEngineusing (ExcelEngine excelEngine = new ExcelEngine()){IApplication application = excelEngine.Excel;application.DefaultVersion = ExcelVersion.Excel2016;//Create a workbookIWorkbook workbook = application.Workbooks.Create(1);IWorksheet sheet = workbook.Worksheets[0];//Assign array formulasheet.Range["A1:D1"].FormulaArray = "{1,2,3,4}";//Adding a named range for the range A1 to D1sheet.Names.Add("ArrayRange", sheet.Range["A1:D1"]);//Assign formula array with named rangesheet.Range["A2"].Text = "SUM";sheet.Range["B2"].FormulaArray = "Sum(ArrayRange)";sheet.Range["A3"].Text = "MIN";sheet.Range["B3"].FormulaArray = "Min(ArrayRange)";sheet.Range["A4"].Text = "MAX";sheet.Range["B4"].FormulaArray = "Max(ArrayRange)";//Saving the Excel to the MemoryStreamMemoryStream stream = new MemoryStream();workbook.SaveAs(stream);}The working sample with the above code can be downloaded from the following link.Please let us know if it helps.Regards,Shamini