Button直接调用即可
Response.ContentEncoding = Encoding.GetEncoding("gb2312");
Response.ContentType = "application/ms-excel";Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("课程信息") + ".xls");
StringBuilder builder = new StringBuilder();
//画一个网页内容
builder.Append("<html><head>");
builder.Append("<meta http-equiv=/\"Content-Language/\" content=/\"zh-cn/\">");
builder.Append("<meta http-equiv=/\"Content-Type/\" content=/\"text/html; charset=gb2312/\">");
builder.Append("</head>");
builder.Append("<table border=1>");//开始画一个导出的表格样式
//表头
builder.Append("<tr style=\"height:40px;text-align:right;\">");
builder.Append("<td valign=middle height=24>序号</td>");
builder.Append("<td valign=middle height=24>课程名称</td>");
builder.Append("<td valign=middle height=24>课程性质</td>");
builder.Append("<td valign=middle height=24>学分</td>");
builder.Append("<td valign=middle height=24>开课学年、学期</td>");
builder.Append("<td valign=middle height=24>主讲教师</td>");
builder.Append("<td valign=middle height=24>教师职务</td>");
builder.Append("<td valign=middle height=24>开课单位</td>");
builder.Append("<td valign=middle height=24>授课标识</td>");
builder.Append("</tr>");
DataTable dt = GetDt();//去除内容
for (int i = 0; i < dt.Rows.Count; i++)
{
//画内容表格
builder.Append("<tr style=\"height:40px;text-align:right;\">");builder.Append("<td valign=middle height=24>"+(i+1).ToString()+"</td>");
builder.Append("<td valign=middle height=24>" + dt.Rows[i]["C_Name"].ToString() + "</td>");
builder.Append("<td valign=middle height=24>" + dt.Rows[i]["name"].ToString() + "</td>");
builder.Append("<td valign=middle height=24>" + dt.Rows[i]["C_XueFen"].ToString() + "</td>");
builder.Append("<td valign=middle height=24>" + dt.Rows[i]["xqxn"].ToString() + "</td>");
builder.Append("<td valign=middle height=24>" + GetTeaName(dt.Rows[i]["c_id"].ToString()) + "</td>");
builder.Append("<td valign=middle height=24>" + GetTeaZhiCheng(dt.Rows[i]["c_id"].ToString()) + "</td>");
builder.Append("<td valign=middle height=24>" + dt.Rows[i]["C_KaiKeDanWei"].ToString() + "</td>");
builder.Append("<td valign=middle height=24>" + dt.Rows[i]["C_ShouKeBiaoShi"].ToString() + "</td>");
builder.Append("</tr>");
}
builder.Append("</table>");
Response.Write(builder.ToString());
Response.End();