Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT:</strong> Try .csv format. It works for me.</p> <pre><code>protected void btnExport_Click(object sender, EventArgs e) { HttpContext context = HttpContext.Current; context.Response.Clear(); string filename = "testExportToCSV"; DataTable table1 = new DataTable("Customers"); DataRow row1, row2, row3; DataColumn colName = new DataColumn("CustomerName", System.Type.GetType("System.String")); DataColumn colCity = new DataColumn("City", System.Type.GetType("System.String")); table1.Columns.Add(colName); table1.Columns.Add(colCity); row1 = table1.NewRow(); row1["CustomerName"] = "aa"; row1["City"] = "ss"; table1.Rows.Add(row1); row2 = table1.NewRow(); row2["CustomerName"] = "bb"; row2["City"] = "sdd"; table1.Rows.Add(row2); row3 = table1.NewRow(); row3["CustomerName"] = "cc"; row3["City"] = "dfgfgf"; table1.Rows.Add(row3); //foreach (System.Data.DataColumn column in table1.Columns) //{ for (int i = 0; i &lt; table1.Columns.Count; i++) { context.Response.Write(table1.Columns[i].ColumnName.ToString().Replace(",", string.Empty) + ","); } context.Response.Write(Environment.NewLine); //} foreach (System.Data.DataRow row in table1.Rows) { for (int i = 0; i &lt; table1.Columns.Count; i++) { context.Response.Write(row[i].ToString().Replace(",", string.Empty) + ","); } context.Response.Write(Environment.NewLine); } context.Response.ContentType = "text/csv"; context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + ".csv"); context.Response.End(); } </code></pre> <p><strong>EDIT 1:</strong></p> <p>i had work on your issue but i have found that its <code>security issue</code> and its became bad impact on your <code>system's security if we modify it</code>.</p> <pre><code>Key: HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security Value: (DWORD)"ExtensionHardening" = [0 = Disable check; 1 = Enable check and prompt; 2 = Enable check, no prompt deny open] Default setting if value not present is 1 (enable and prompt). </code></pre> <p>You can refer whole article from this link: <a href="http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx" rel="nofollow">http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/03/11/excel-2007-extension-warning.aspx</a></p> <p><strong>EDIT 2:</strong> <code>Steps to Modify Registry...</code></p> <ol> <li>Click <strong>Start Menu</strong> </li> <li>In Search Program and files type <strong>run</strong></li> <li>Then type <strong>REGEDIT</strong>, press OK</li> <li>HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security</li> </ol> <p>Hope, it will helps you. !! Thanks.</p> <p>If it solves your problem then mark it as answer so that other can also refer it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload