SqlCommand cmd = new SqlCommand("export_excel", cn);
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd);
System.Data.DataTable dt = new System.Data.DataTable();
da.Fill(dt);
int k = dt.Columns.Count;
int l = dt.Rows.Count;
if (dt.Rows.Count > 0)
{
    Microsoft.Office.Interop.Excel.ApplicationClass XcelApp = new Microsoft.Office.Interop.Excel.ApplicationClass();
    XcelApp.Application.Workbooks.Add(Type.Missing);
    for (int i = 0; i < k; i++)
    {
        XcelApp.Cells[1, i + 1] = dt.Columns[i].ToString();
    }
    for (int i = 2; i <= l; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            XcelApp.Cells[i, j] = dt.Rows[i - 2][j - 1].ToString();
        }
    }
    XcelApp.Visible = true;
}
My data in SQL Server:
And this is the data in the Excel file:
The Excel file returns reversed value with database, I don't know how to handle it, hope the masters answer!


 
    