/// <summary> /// Exports data grid to Excel /// </summary> /// <param name="type"></param> public void ExportAction(object parameter, object view, object dialogService = null, object exService = null) //ExportCommand { string fn; try { if (dialogService is ISaveFileDialogService) { ISaveFileDialogService saveFileDialogService = dialogService as ISaveFileDialogService; IExportService exportService = exService as IExportService; TableView tv = view as TableView; Enum.TryParse(parameter.ToString(), out ExportType type); switch (type) { case ExportType.PDF: saveFileDialogService.Filter = "PDF files|*.pdf"; if (saveFileDialogService.ShowDialog()) { fn = saveFileDialogService.GetFullFileName(); } exportService.ExportToPDF(tv, saveFileDialogService.GetFullFileName()); break; case ExportType.XLSX: saveFileDialogService.Filter = "Excel 2007 files|*.xlsx"; if (saveFileDialogService.ShowDialog()) { exportService.ExportToXLSX(tv, saveFileDialogService.GetFullFileName()); } break; } } } catch (Exception ex) { MessageBox.Show("Error exporting data:" + ex.Message); } }
public static bool ShowDialog(this ISaveFileDialogService service, Action <CancelEventArgs> fileOK = null, IFileInfo fileInfo = null) { VerifyService(service); return(service.ShowDialog(fileOK, fileInfo.With(x => x.DirectoryName), fileInfo.With(x => x.Name))); }