@Poormina, , :
protected void Buttonexcel_Click(object sender, EventArgs e)
{
try
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.Charset = "";
Response.AddHeader("content-disposition", "attachment;filename=dados.xls");
StringWriter sWriter = new StringWriter();
HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);
GridView1.RenderControl(hWriter);
string style = @"<style> .textmode {mso-number-format:General} </style>";
Response.Output.Write(sWriter.ToString());
Response.Flush();
Response.End();
}
catch (Exception ex)
{
Label1.Text = ex.ToString();
}
}
excel , "", "", :
string style = @"<style> .textmode { mso-number-format:\@; } </style>";
, , , , ITMREF_0 XXXXX.YYYY.ZZZZZ, :

12000073 , excel , 22284.01.01 , excel
EDIT: , :
string style = @"<style> TD { mso-number-format:\@; } </style>";
Response.Write(style);
excel , , ,
2:
, , excel , gridview, , "" , .
:
protected void Buttonmail_Click(object sender, EventArgs e)
{
fn_AttachGrid();
}
public void fn_AttachGrid()
{
StringWriter sWriter = new StringWriter();
HtmlTextWriter hWriter = new HtmlTextWriter(sWriter);
GridView1.RenderControl(hWriter);
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.To.Add(new MailAddress(txtto.Text));
mail.Subject = "Foi";
System.Text.Encoding Enc = System.Text.Encoding.ASCII;
byte[] mBArray = Enc.GetBytes(sWriter.ToString());
string style = @"<style> TD { mso-number-format:\@; } </style>";
Response.Write(style);
System.IO.MemoryStream mAtt = new System.IO.MemoryStream(mBArray, false);
mail.Attachments.Add(new Attachment(mAtt, "rotina.xls"));
mail.Body = "Foi detectado o seguinte problema";
SmtpClient smtp = new SmtpClient();
mail.From = new MailAddress("email_from", "name displayed");
smtp.Host = "smtp.gmail.com";
smtp.UseDefaultCredentials = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "email_from";
NetworkCred.Password = "password";
smtp.Credentials = NetworkCred;
smtp.EnableSsl = true;
smtp.Port = 587;
smtp.Send(mail);
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "anything", "alert('Enviado com sucesso.');", true);
}
- ?