/// <summary>
 ///
 /// </summary>
 /// <param name="_workbook"></param>
 /// <param name="filename"></param>
 /// <param name="saveType"></param>
 /// <param name="response"></param>
 /// <param name="DownloadType"></param>
 /// <param name="contentType"></param>
 /// <returns></returns>
 public static XlsResult SaveAsActionResult(this ExcelEngine _engine, IWorkbook _workbook, string filename, ExcelSaveType saveType, HttpResponse response, ExcelDownloadType DownloadType, ExcelHttpContentType contentType)
 {
     return(new XlsResult(_engine, _workbook, filename, response, DownloadType, contentType));
 }
        private async void btnGenerateExcel_Click(object sender, RoutedEventArgs e)
        {
            StorageFile storageFile;

            if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
            {
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.Desktop;
                savePicker.SuggestedFileName      = "Edit";
                if (rdBtnXls.IsChecked.Value)
                {
                    savePicker.FileTypeChoices.Add("Excel Files", new List <string>()
                    {
                        ".xls"
                    });
                }
                else if (rdBtnXltm.IsChecked.Value)
                {
                    savePicker.FileTypeChoices.Add("Excel Files", new List <string>()
                    {
                        ".xltm"
                    });
                }
                else
                {
                    savePicker.FileTypeChoices.Add("Excel Files", new List <string>()
                    {
                        ".xlsm",
                    });
                }
                storageFile = await savePicker.PickSaveFileAsync();
            }
            else
            {
                StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                if (rdBtnXls.IsChecked.Value)
                {
                    storageFile = await local.CreateFileAsync("Edit.xls", CreationCollisionOption.ReplaceExisting);
                }
                else if (rdBtnXltm.IsChecked.Value)
                {
                    storageFile = await local.CreateFileAsync("Edit.xltm", CreationCollisionOption.ReplaceExisting);
                }
                else
                {
                    storageFile = await local.CreateFileAsync("Edit.xlsm", CreationCollisionOption.ReplaceExisting);
                }
            }

            if (storageFile == null)
            {
                return;
            }

            //Step 1 : Instantiate the spreadsheet creation engine.
            ExcelEngine excelEngine = new ExcelEngine();
            //Step 2 : Instantiate the excel application object.
            IApplication application = excelEngine.Excel;

            Assembly  assembly     = typeof(EditMacro).GetTypeInfo().Assembly;
            string    resourcePath = "Syncfusion.SampleBrowser.UWP.XlsIO.XlsIO.Tutorials.Samples.Assets.Resources.Templates.EditMacroTemplate.xltm";
            Stream    fileStream   = assembly.GetManifestResourceStream(resourcePath);
            IWorkbook workbook     = await application.Workbooks.OpenAsync(fileStream);

            workbook.Version = ExcelVersion.Excel2016;

            #region VbaProject
            //Access Vba Project from workbook
            IVbaProject vbaProject = workbook.VbaProject;
            IVbaModule  vbaModule  = vbaProject.Modules["Module1"];
            vbaModule.Code = vbaModule.Code.Replace("xlAreaStacked", "xlLine");
            #endregion


            #region Saving the workbook
            ExcelSaveType type = ExcelSaveType.SaveAsMacro;

            if (storageFile.Name.EndsWith(".xls"))
            {
                workbook.Version = ExcelVersion.Excel97to2003;
                type             = ExcelSaveType.SaveAsMacro;
            }
            else if (storageFile.Name.EndsWith(".xltm"))
            {
                type = ExcelSaveType.SaveAsMacroTemplate;
            }

            await workbook.SaveAsAsync(storageFile, type);

            workbook.Close();
            excelEngine.Dispose();
            #endregion

            #region Launching the saved workbook
            MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully.");

            UICommand yesCmd = new UICommand("Yes");
            msgDialog.Commands.Add(yesCmd);
            UICommand noCmd = new UICommand("No");
            msgDialog.Commands.Add(noCmd);
            IUICommand cmd = await msgDialog.ShowAsync();

            if (cmd == yesCmd)
            {
                // Launch the saved file
                bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile);
            }
            #endregion
        }