asp.net dataset导出EXCEL 如何在EXCEL里显示标题 30
///<summary>///保存Excel的方法///</summary>///<paramname="ds">dataset对象</param>///<paramna...
/// <summary>
/// 保存 Excel 的方法
/// </summary>
/// <param name="ds">dataset 对象</param>
/// <param name="filename">名称</param>
public static void Execl(DataSet ds, string filename)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "GB2312";
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(filename));
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
上面是导出EXCEL的方法
如何在这方法里 让excel 显示标题 展开
/// 保存 Excel 的方法
/// </summary>
/// <param name="ds">dataset 对象</param>
/// <param name="filename">名称</param>
public static void Execl(DataSet ds, string filename)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "GB2312";
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(filename));
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}
上面是导出EXCEL的方法
如何在这方法里 让excel 显示标题 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询