导入Excel:

将GridView中内容导入到Excel(或Word)中   Response.Clear();
将GridView中内容导入到Excel(或Word)中    Response.Buffer 
= true;
将GridView中内容导入到Excel(或Word)中    Response.Charset 
= "GB2312";
将GridView中内容导入到Excel(或Word)中    Response.AppendHeader(
"Content-Disposition""attachment;filename=FileName.xls");
将GridView中内容导入到Excel(或Word)中    
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
将GridView中内容导入到Excel(或Word)中
    Response.ContentEncoding = System.Text.Encoding.UTF7;
将GridView中内容导入到Excel(或Word)中    Response.ContentType 
= "application/ms-excel";//设置输出文件类型为excel文件。 
将GridView中内容导入到Excel(或Word)中
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
将GridView中内容导入到Excel(或Word)中    System.Web.UI.HtmlTextWriter oHtmlTextWriter 
= new System.Web.UI.HtmlTextWriter(oStringWriter);
将GridView中内容导入到Excel(或Word)中    
this.GridView1.RenderControl(oHtmlTextWriter);
将GridView中内容导入到Excel(或Word)中    Response.Output.Write(oStringWriter.ToString());
将GridView中内容导入到Excel(或Word)中    Response.Flush();
将GridView中内容导入到Excel(或Word)中    Response.End();

导入Word:

将GridView中内容导入到Excel(或Word)中   Response.Clear();
将GridView中内容导入到Excel(或Word)中    Response.Buffer 
= true;
将GridView中内容导入到Excel(或Word)中    Response.Charset 
= "GB2312";
将GridView中内容导入到Excel(或Word)中    Response.AppendHeader(
"Content-Disposition""attachment;filename=FileName.xls");
将GridView中内容导入到Excel(或Word)中    
// 如果设置为 GetEncoding("GB2312");导出的文件将会出现乱码!!!
将GridView中内容导入到Excel(或Word)中
    Response.ContentEncoding = System.Text.Encoding.UTF7;
将GridView中内容导入到Excel(或Word)中    Response.ContentType 
= "application/ms-excel";//设置输出文件类型为excel文件。 
将GridView中内容导入到Excel(或Word)中
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
将GridView中内容导入到Excel(或Word)中    System.Web.UI.HtmlTextWriter oHtmlTextWriter 
= new System.Web.UI.HtmlTextWriter(oStringWriter);
将GridView中内容导入到Excel(或Word)中    
this.GridView1.RenderControl(oHtmlTextWriter);
将GridView中内容导入到Excel(或Word)中    Response.Output.Write(oStringWriter.ToString());
将GridView中内容导入到Excel(或Word)中    Response.Flush();
将GridView中内容导入到Excel(或Word)中    Response.End();

相关文章: