ronniepeach
New Member
I'm exporting data from a DataSet to Excel via GridView. Framework is 2.0. I'm using the following code snippet:\[code\] Generate_Sequence_Data_BAL objAttBAL = new Generate_Sequence_Data_BAL(); string PlanId = ""; PlanId = Cryptography.Decrypt(Request.QueryString[0].ToString()); //Get the data from database into datatable Response.ClearHeaders(); Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=SequenceData_" + Cryptography.Decrypt(Request.QueryString[0].ToString()) + ".xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); DataSet ds = objAttBAL.GetData(Convert.ToInt32(PlanId)); GridView GridView1 = new GridView(); GridView1.RowDataBound += GridView1_RowDataBound; GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); for (int i = 0; i < GridView1.Rows.Count; i++) { //Apply text style to each Row GridView1.Rows.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.Write(sw.ToString()); Response.Flush(); GridView1.Dispose(); Response.End();\[/code\]I have a column with data like '5E02'. Even after using the above method, it's being exported as '5.00E+02'. I have tried concatenating (') to it while retrieving from SQL, but then it shows up like ('5E02) instead of (5E02). Please help. Also suggest any other alternatives for exporting data directly to excel without gridview.PS: I have already referred this question & it's not working, so it's not a duplicate.