private void ExpertControl(DocumentType type)
{
Response.Clear();
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
if (type == DocumentType.Word)
{
Response.ContentType = "application/ms-word";
Response.AppendHeader("content-disposition", "attachment;filename=visit.doc");
}
else if(type == DocumentType.Excel)
{
Response.ContentType = "application/ms-excel";
Response.AppendHeader("content-disposition", "attachment;filename=visit.xls");
}
this.Page.EnableViewState = false;
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
this.DataGrid1.RenderControl(htmlWriter);
//输出
Response.Write(writer.ToString());
Response.End();
}
//文档类型
public enum DocumentType
{
Word,
Excel
}