Jan 10, 2012, 1:59 PM
Error Export DataTable to Excel
i need Help...
i try to export a simple datatable and reporting error Status Code: 200Status Text: BADRESPONSE: missing } in XML expression.
in diferents times the valor missing } change for ; > . )...
the code using is:
i try to export a simple datatable and reporting error Status Code: 200Status Text: BADRESPONSE: missing } in XML expression.
in diferents times the valor missing } change for ; > . )...
the code using is:
objDataSetGrid4 = objInventario.ListarPronosticos();
DataTable dt = objDataSetGrid4.Tables[0];
//Create a dummy GridView
System.Web.UI.WebControls.GridView GridView1 = new System.Web.UI.WebControls.GridView();
GridView1.AllowPaging = false;
GridView1.DataSource = dt;
GridView1.DataBind();
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition",
"attachment;filename=DataTable.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
for (int i = 0; i < GridView1.Rows.Count; i++)
{
//Apply text style to each Row
GridView1.Rows[i].Attributes.Add("class", "textmode");
}
GridView1.RenderControl(hw);
//style to format numbers to string
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
Last edited by geoffrey.mcgill; Jan 10, 2012 at 5:44 PM.
Reason: please use [CODE] tags