软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络编程 > ASP.NET > ASP.NET将DataSet导出成Excel表格

ASP.NET将DataSet导出成Excel表格

  烈火网(LieHuo.Net)教程 C#中操作Excel的方法很多,这里通过Response输出流的方式导到浏览器端成excel文件。

  方法代码: 

以下为引用的内容:
public void ExportResult(DataSet ds,string excelName)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/vnd.ms-xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
dg.RenderControl(htmlWrite);
HttpContext.Current.Response.AddHeader
    ("content-disposition", "attachment;filename="+HttpUtility.UrlEncode(excelName))
    HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
    相关阅读
    栏目导航
    推荐软件