Note that there are some explanatory texts on larger screens.

plurals
  1. POFormat error while exporting to excel from gridview in asp.net
    primarykey
    data
    text
    <p>I Tried a few solutions mentioned in the site like <code>Using System.Microsoft.Office.Excel</code> and <code>Excel = System.Microsoft.Office.Excel</code>, but it dint work.... Here, I'm trying to get the data in a table and download to a file in the specified location in the server in .xls format and then giving the users a link to download the file. this is the code for export `</p> <pre><code>protected void btnExcelExport_Click(object sender, EventArgs e) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using( HtmlTextWriter htw = new HtmlTextWriter(sw)) { // Create a form to contain the grid Table table = new Table(); // get gridlines from gridview table.GridLines = GridView2.GridLines; if (GridView2.HeaderRow != null) { table.Rows.Add(GridView2.HeaderRow); } foreach (GridViewRow row in GridView2.Rows) { table.Rows.Add(row); } if (GridView2.FooterRow != null) { table.Rows.Add(GridView2.FooterRow); } // render the table into the htmlwriter table.RenderControl(htw); } var myRootPath = Server.MapPath("~"); var docPath = Path.GetFullPath(Path.Combine(myRootPath, "/Compare/c.xls")); File.WriteAllText(docPath, sw.ToString()); } dwndlink.Visible = true; } </code></pre> <p>And when this is code for linkbutton: </p> <pre><code> protected void dwnlink(object sender, EventArgs e) { var webRootPath = Server.MapPath("~"); var docPath = Path.GetFullPath(Path.Combine(webRootPath, "/Compare/c.xls")); string name = Path.GetFileName(docPath); Response.AppendHeader("content-disposition", "attachment; filename=" + name); Response.ContentType = "Application/vnd.ms-excel"; Response.TransmitFile(docPath); Response.End(); } </code></pre> <p>so when the user opens the downloaded file, gives a warning as its not in the same extension. Why is this happening..?? </p> <p>I tried working with the solutions provided in various sites, but to no avail...</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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