title: How to export datatable to excel in c# windows application
body: <p>I found some code through googling that allows me to export a data table to excel file. i successfully export the file from database table and save it in my document 
  My coding is:</p>
  
  <pre><code>  using System;
    using System.Data.OleDb;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;
    using System.Data;
  
  namespace ImportFile
  
  {
  public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
      }
      String connection = "SERVER=******;"DATABASE=dbd;"UID=root;"PASSWORD=pws;"Convert Zero Datetime = True";
   private void BExport_Click(object sender, EventArgs e)
      {
          DateTime dat = DateTime.Now;
          int time = dat.Hour;
          int time1 = dat.Minute;
          int time2 = dat.Second;
          int month = dat.Month;
          int day = dat.Day;
          MySqlConnection connection1 = new MySqlConnection(connection);
          connection1.Open();
          MySqlCommand command = new MySqlCommand ("SELECT * FROM TABLE_Name",connection1);     
          MySqlDataAdapter dataadpter = new MySqlDataAdapter(command);
          DataTable datatable = new DataTable("TABLE_NAME");
          dataadpter.Fill(datatable);
          datatable.WriteXml("C:\\Users\\Downloads\\agent.xlsx" + time + " - " + time1 + " - " + time2 + " - " + day + " - " + month + "");
          MessageBox.Show("export data");
  
        }
       }
     }
  </code></pre>
  
  <p>my problem is that when i download file(click import button)its not download an <strong>excel file</strong> its just an <strong>normal file</strong>.</p>
  
  <p>how i download it as <strong>excel file</strong> . if any one know this.... <strong>help me</strong> </p>