- private void btnExportExcel_Click(object sender, EventArgs e)
- {
- string filePath = GetFileNameToSave();
- if (string.IsNullOrEmpty(filePath))
- {
- return;
- }
- pivotGrid.ExportToXlsx(filePath);
- ActionNotifier.Information("Exported file Excel.");
- System.Diagnostics.Process.Start(filePath);
- }
- static string GetFileNameToSave()
- {
- string fNameDefault = String.Format("{0}.{1}.xlsx", "Export", DateTime.Now.ToString("yy.MM.dd_hh.mm"));
- using (SaveFileDialog dlgSave = new SaveFileDialog { Title = "Export Excel", Filter = "Excel file |*.xlsx ", FileName = fNameDefault })
- {
- dlgSave.OverwritePrompt = true;
- dlgSave.RestoreDirectory = true;
- if (dlgSave.ShowDialog() != DialogResult.OK || !dlgSave.CheckPathExists)
- return null;
- dlgSave.AddExtension = true;
- string fileName = dlgSave.FileName.Trim();
- if (!fileName.EndsWith(".xlsx"))
- fileName += ".xlsx";
- return fileName;
- }
- }
Loading
Đạt LữPosted Sep 22, 2017, 12:04 AM