GridView导出Excel和Word
2010-09-01 11:28
323 查看
using System.Drawing;
using System.IO;
using System.Text;
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
/// <summary>
/// 此方法必重写,否则会出错
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
}
导出Excel
Export("application/ms-excel", "Employee information.xls");
导出Word
Export("application/ms-word", "员工信息.doc");
using System.IO;
using System.Text;
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
/// <summary>
/// 此方法必重写,否则会出错
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
}
导出Excel
Export("application/ms-excel", "Employee information.xls");
导出Word
Export("application/ms-word", "员工信息.doc");
相关文章推荐
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- GridView导出到Excel或Word文件的C#代码
- c# gridview操作:绑定特定列、导出Excel、导出WORD
- GridView数据导出到Excel、Word
- 使用GridView控件导出数据源的数据为Excel、Word或Text
- GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- GridView 导出Excel或Word
- [转]GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- GridView导出到Excel或Word文件
- 扩展GridView控件(8) - 导出数据源的数据为Excel、Word或Text
- ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件)
- GridView导出到Excel或Word文件
- 使用ASP.NET的GridView导出/儲存資料至Excel,Word,Txt檔,Powerpoint
- GridView导出Excel与Word
- 扩展GridView控件(8) - 导出数据源的数据为Excel、Word或Text
- asp.net_GridView导出数据到Excel/Word
- GridView导出到Excel或Word文件