本文介绍了将数据集导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将数据集导出到excel.我试过了,但是没有生成任何文件..
I want to export dataset to excel. I tried but it is not generating any file..
public void ExportDataSetToExcel(DataSet ds, string filename)
{
HttpResponse response = HttpContext.Current.Response;
// first let's clean up the response.object
response.Clear();
response.Charset = "";
// set the response mime type for excel
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
// create a string writer
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// instantiate a datagrid
DataGrid dg = new DataGrid();
dg.DataSource = ds.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();
}
}
}
推荐答案
public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
{
}
另请参考以下链接:
http://toniyojackson.blogspot.in/2010/10/gridview-export-to- excel.html [ ^ ]
Also refer below link:
http://toniyojackson.blogspot.in/2010/10/gridview-export-to-excel.html[^]
这篇关于将数据集导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!