title: how to export grid view excel data using save File Dialog whithout using datasource
body: <p>I really don't know guys if U can understand my problem but I will try to make it clear as possible, I have a DataGrid view and I don't use Entity framework to fill it with data just I've displayed direct data from my database to fill it like:</p>
  
  <pre><code>        private void load()
          {
              SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["UR2k_CS.Properties.Settings.StoreConnectionString"].ConnectionString);
              SqlDataAdapter data = new SqlDataAdapter("Select * FROM [dbo].[missingItems]", con);
              DataTable table = new DataTable();
              data.Fill(table);
              dataGridView1.Rows.Clear();
              foreach (DataRow item in table.Rows)
              {
                  int n = dataGridView1.Rows.Add();
                  dataGridView1.Rows[n].Cells[0].Value = item["RFID"].ToString();
                  dataGridView1.Rows[n].Cells[1].Value = item["name"].ToString();
                   dataGridView1.Rows[n].Cells[2].Value = item["model"].ToString();
                   dataGridView1.Rows[n].Cells[3].Value = item["category"].ToString();
                   dataGridView1.Rows[n].Cells[4].Value = item["prix"].ToString();
                   dataGridView1.Rows[n].Cells[5].Value = item["ref"].ToString();
  
              }
  </code></pre>
  
  <p>and I want to export its data into .csv file using Save File Dialog ( to make user select save place) and I found that code on the net:</p>
  
  <pre><code>private void btnExportToExcel_Click(object sender, EventArgs e)
  {
      var dia = new System.Windows.Forms.SaveFileDialog();
      dia.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
      dia.Filter = "Excel Worksheets (*.xlsx)|*.xlsx|xls file (*.xls)|*.xls|All files (*.*)|*.*";
      if(dia.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
      {
          DataTable data = null;// use the DataSource of the DataGridView here
          var excel = new OfficeOpenXml.ExcelPackage();
          var ws = excel.Workbook.Worksheets.Add("worksheet-name");
          // you can also use LoadFromCollection with an `IEnumerable&lt;SomeType&gt;`
          ws.Cells["A1"].LoadFromDataTable(data, true, OfficeOpenXml.Table.TableStyles.Light1);
          ws.Cells[ws.Dimension.Address.ToString()].AutoFitColumns();
  
          using(var file = File.Create(dia.FileName))
              excel.SaveAs(file);
      }
  }
  </code></pre>
  
  <p>but As U see Guys I don't have data source so how to fill it with my grid view data.</p>