前台:
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
protected void Button2_Click(object sender, EventArgs e)
{//清除客户端当前显示
Response.Clear();
//作为附件输出,filename=FileFlow.xls 指定输出文件的名称,注意其扩展名和指定文件类型相符,可以为:.doc .xls .txt .htm
Response.AddHeader("content-disposition", "attachment;filename=qaErroranalysis.xls"); //显示标头
//设置显示的字和内容要存的形式
Response.Charset = "gb2312";
Response.ContentType = "application/vnd.xls";
//Response.ContentType = "application/octet-stream";(此句适合任何文件类型)
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
stringWrite.WriteLine(
Literal1.Text
);
Response.Write(stringWrite.ToString());
Response.End();
}