数据导出
时间:2011-05-19 来源:双魂人生
我们知道在系统或者网站的后台管理中,有时候为了需要,不如打印,查看详细数据等,需要将列别中的信息导出来,可以导入到excel或者word等里去
导出代码:
View Code protected void Button1_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "打印报表.excl");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
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();
}
数据都来源于GridView1中,FileType可以根据需要修改类型.....
相关阅读 更多 +