Thursday, May 26, 2011

Convert Number to Text When Export to Excel in .Net

//Put this line in itemdatabound or rowdatabound
e.Item.Cells[1].Attributes.Add("class", "text");

//In Export to excel button onclick()
dg.RenderControl(htmlWrite);

//Write these 2 lines after render control & before Response.write command
string style = @"<style> .text { mso-number-format:\@; } </style> ";
Response.Write(style);
//

response.Write(stringWrite.ToString());
response.End();

No comments: