Export the data in excel format

Below is the code.

private void Save(string detail)
    {
        Response.ContentType = "application/ms-excel";
        Response.AddHeader("content-disposition", "attachment; filename=Data.xls");
        Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
        Response.Write("<head>");
        Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\">");
        Response.Write("<!--[if gte mso 9]>");
        Response.Write("<xml>");
        Response.Write("<x:ExcelWorkbook>");
        Response.Write("<x:ExcelWorksheets>");
        Response.Write("<x:ExcelWorksheet>");      
        Response.Write("<x:Name>Personal Detail</x:Name>");
        Response.Write("<x:WorksheetOptions>");      
        Response.Write("<x:Panes>");
        Response.Write("</x:Panes>");
        Response.Write("</x:WorksheetOptions>");
        Response.Write("</x:ExcelWorksheet>");
        Response.Write("</x:ExcelWorksheets>");
        Response.Write("</x:ExcelWorkbook>");
        Response.Write("</xml>");
        Response.Write("<![endif]-->");
        Response.Write("</head>");
        Response.Write("<body>");
        Response.Write(detail);
        Response.Write("</body>");
        Response.Write("</html>");
        // --------------------------------  
        Response.End();
    }

Comments