protected void BtnExport_OnClick(object sender, EventArgs e)
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<table width='100%' border='1' cellpadding='7' cellspacing='0' style='font: normal 13px/20px Arial, Helvetica, sans-serif'>");
sb.Append("<tr>");
sb.Append("<td align='left' style='background:#E5E5E5;' valign='top' colspan='4'><b>Test</b></td>");
sb.Append("</tr>");
sb.Append("</table>");
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename="Test.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
Response.Output.Write(sb.ToString());
Response.Flush();
Response.SuppressContent = true;
}
}
catch (Exception ex)
{
CommonFunction.SiteErrorInsert(ex);
}
}
{
try
{
StringBuilder sb = new StringBuilder();
sb.Append("<table width='100%' border='1' cellpadding='7' cellspacing='0' style='font: normal 13px/20px Arial, Helvetica, sans-serif'>");
sb.Append("<tr>");
sb.Append("<td align='left' style='background:#E5E5E5;' valign='top' colspan='4'><b>Test</b></td>");
sb.Append("</tr>");
sb.Append("</table>");
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename="Test.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
using (StringWriter sw = new StringWriter())
{
HtmlTextWriter hw = new HtmlTextWriter(sw);
Response.Output.Write(sb.ToString());
Response.Flush();
Response.SuppressContent = true;
}
}
catch (Exception ex)
{
CommonFunction.SiteErrorInsert(ex);
}
}
No comments:
Post a Comment