if (DropDownList2.SelectedValue == "导出为word格式")
{ Response.Clear(); Response.BufferOutput = true; //设定输出的字符集 Response.Charset="GB2312"; //假定导出的文件名为FileName.doc Response.AppendHeader("ContentDisposition","p_w_upload;filename=FileName.doc"); Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312"); 设置导出文件的格式 Response.ContentType="application/ms-word";StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);gvPersonList.RenderControl(htw);
Response.Write(sw.ToString());Response.End();
} if (DropDownList2.SelectedValue == "导出为excel格式") { Response.ClearContent(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AddHeader("content-disposition", "p_w_upload; filename=excel.xlsx"); Response.ContentType = "application/ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gvPersonList.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); }