//导出excel表格
public void OutExcel(DataSet ds,string fileName)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + DateTime.Now.ToString("yyyyMMdd") + ".xls");
Response.ContentType = "application/vnd.ms-excel";
//Response.ContentType = "application/vnd.ms-word";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "";
this.EnableViewState = false;
StringWriter oStringWriter = new StringWriter();
HtmlTextWriter oHtmlTextWriter = new HtmlTextWriter(oStringWriter);
DataGrid dg = new DataGrid();
dg.DataSource = ds; //数据源DataSet/DataTable/List<>/IList
dg.DataBind();
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
标签: C#或者asp.net到处excel表格代码
摘要:C#或者asp.net到处excel表格代码