public static async void Export(this GridView gridView, StorageFile storageFile) { SfDataGrid dataGrid = FindDescendantChildByType(gridView, typeof(SfDataGrid)) as SfDataGrid; if (dataGrid == null) { return; } var excelEngine = dataGrid.ExportCollectionToExcel(dataGrid.View, ExcelVersion.Excel2007, exportingHandler, cellsExportingHandler, false); var workBook = excelEngine.Excel.Workbooks[0]; await workBook.SaveAsAsync(storageFile); var msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); var yesCmd = new UICommand("Yes"); var noCmd = new UICommand("No"); msgDialog.Commands.Add(yesCmd); msgDialog.Commands.Add(noCmd); var cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } }
public static async void Export(this GridView gridView) { ExcelEngine excelEngine; SfDataGrid dataGrid = FindDescendantChildByType(gridView, typeof(SfDataGrid)) as SfDataGrid; if (dataGrid == null) { return; } excelEngine = dataGrid.ExportCollectionToExcel(dataGrid.View, ExcelVersion.Excel2007, exportingHandler, cellsExportingHandler, true); FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.Desktop; savePicker.SuggestedFileName = "Sample"; IWorkbook workBook = excelEngine.Excel.Workbooks[0]; if (workBook.Version == ExcelVersion.Excel97to2003) { savePicker.FileTypeChoices.Add("Excel File (.xls)", new List <string>() { ".xls" }); } else { savePicker.FileTypeChoices.Add("Excel File (.xlsx)", new List <string>() { ".xlsx" }); } var storageFile = await savePicker.PickSaveFileAsync(); if (storageFile != null) { workBook.ActiveSheet.SetRowHeightInPixels(1, 42); await workBook.SaveAsAsync(storageFile); workBook.Close(); excelEngine.Dispose(); 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); IUICommand cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } } }