Đạt Lữ

Đạt Lữ

  • NA
  • 8
  • 594

[what's my wrong? and why my file excel don't create file?]

Sep 21 2017 9:58 PM
  1. private void btnExportExcel_Click(object sender, EventArgs e)  
  2.      {  
  3.            
  4.          string filePath = GetFileNameToSave();  
  5.   
  6.          if (string.IsNullOrEmpty(filePath))  
  7.          {  
  8.                return;  
  9.   
  10.               
  11.          }  
  12.         pivotGrid.ExportToXlsx(filePath);  
  13.          ActionNotifier.Information("Exported file  Excel.");  
  14.   
  15.          System.Diagnostics.Process.Start(filePath);  
  16.      }  
  17.   
  18.      static string GetFileNameToSave()  
  19.      {  
  20.          string fNameDefault = String.Format("{0}.{1}.xlsx""Export", DateTime.Now.ToString("yy.MM.dd_hh.mm"));  
  21.          using (SaveFileDialog dlgSave = new SaveFileDialog { Title = "Export Excel", Filter = "Excel file |*.xlsx ", FileName = fNameDefault })  
  22.          {  
  23.                
  24.              dlgSave.OverwritePrompt = true;  
  25.              dlgSave.RestoreDirectory = true;  
  26.              if (dlgSave.ShowDialog() != DialogResult.OK || !dlgSave.CheckPathExists)  
  27.                
  28.                  return null;  
  29.                    
  30.              dlgSave.AddExtension = true;  
  31.   
  32.                
  33.                
  34.              string fileName = dlgSave.FileName.Trim();  
  35.               
  36.              if (!fileName.EndsWith(".xlsx"))  
  37.                  fileName += ".xlsx";  
  38.                
  39.              return fileName;  
  40.          }  
  41.      }  
  42.       

 


Answers (1)