I need to export asp.net page toexcel 2007. when i wrote the code as below:
protected void Button2_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.ContentType =
"application/vnd.xls";
System.IO.
StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
div1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
public
override void VerifyRenderingInServerForm(Control control)
{
}
and
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="poprint.aspx.cs" Inherits="print_poprint" EnableEventValidation="false" %>
it displays message as shown
The file you are trying to open is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
when yes is clicked it opens in excel but in some other format I think for I cannot AUTOSUM or sum the values result always as zero for numbers appears as text as " 222" . even if i try to format cells with numbers it does not works.
please help as soon as you can
Thanks in advance .please resolve.