void OnButtonClicked(object sender, EventArgs args)
{
//Debug.WriteLine(annuityInPutEntry.Text);
//Create an instance of ExcelEngine.
using (ExcelEngine excelEngine = new ExcelEngine())
{
//ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
//application.DefaultVersion = ExcelVersion.Excel2007;
//File path
//PremiumCalculators
//string resourcePath = "SyncfusionExcelDemo.Employee.xlsx";
string resourcePath = "SyncfusionExcelDemo.122L085V03-AYSA.xlsm";//File with marco formulas
//"App" is the class of Portable project.
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
//Opens the workbook
IWorkbook workbook = application.Workbooks.Open(fileStream);
IWorksheet worksheet1 = workbook.Worksheets[0];
IWorksheet worksheet2 = workbook.Worksheets[1];
IWorksheet worksheet3 = workbook.Worksheets[2];
IWorksheet worksheet4 = workbook.Worksheets[3];
IWorksheet worksheet5 = workbook.Worksheets[4];
IWorksheet worksheet6 = workbook.Worksheets[5];
workbook.CalculationOptions.IsIterationEnabled = true;
worksheet1.EnableSheetCalculations();
worksheet2.EnableSheetCalculations();
worksheet3.EnableSheetCalculations();
worksheet4.EnableSheetCalculations();
worksheet5.EnableSheetCalculations();
worksheet6.EnableSheetCalculations();
//Enable the calculation of Excelsheet
ICalculationOptions cal = workbook.CalculationOptions;
cal.RecalcOnSave = true;
Debug.WriteLine("Before edit Sheet1 B55 value =" + worksheet1["C24"].DisplayText);
Debug.WriteLine("Before edit Sheet1 D55 Formula =" + worksheet1["F30"].Formula);
Debug.WriteLine("Before edit Sheet1 D55 value =" + worksheet1["F30"].DisplayText);
//Write the value Pervious value C24 cell
//Output cell F30 : formula isVLOOKUP(pt,'Table A'!$C$45:$R$74,14)
worksheet1["C24"].Number = "50000"; //edit the value
Debug.WriteLine("After edit Sheet1 B55 value =" + worksheet1["C24"].DisplayText);
Debug.WriteLine("After edit Sheet1 D55 Formula =" + worksheet1["F30"].Formula);
Debug.WriteLine("After edit Sheet1 D55 value =" + worksheet1["F30"].DisplayText);
Debug.WriteLine("After edit Sheet1 D55 value =" + worksheet2["C7"].Formula);
Debug.WriteLine("After edit Sheet1 D55 value =" + worksheet2["C7"].DisplayText);
//Create new stream to store workbook copy
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream); // App hangs when save the changes in new stream
workbook.Close();
excelEngine.Dispose();
//Save the stream into xlsx file
Xamarin.Forms.DependencyService.Get
}
}