StringBuilder sbd = new StringBuilder();
sbd.Append("<table id='tb1' width='60%' border='1' cellspacing='0' cellpadding='0' style='text-align:center'>"); //头
sbd.Append("<h2 style='text-align:center'>标题</h2>");//标题
sbd.Append("<tbody><tr style='text-align:center'><td rowspan='2'>序号</td><td rowspan='2'>姓名</td>);//
sbd.AppendFormat("<td>{0}</td><td>{1}</td><td>{2}</td>", tb1,tb2,tb3);//内容,占位
sbd.Append("</tbody>");
sbd.Append("</table>");//结尾
sbd.Append("<table width='60%'>");//两段内容
sbd.Appendt("</br><tr><td colspan='3'><span style='font-size:30px'>统计</span></td></tr>");//内容
sbd.Append("</table>");//结尾
string strTable = sbd.ToString();//转换
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(“表名”) + ".xlsx");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";//其他类型转换百度
HttpContext.Current.Response.Write(strTable);
HttpContext.Current.Response.End();
Table转变为Excel
最新推荐文章于 2024-04-23 13:07:47 发布