急!如何在导出的Excel中加标题
如何在导出的Excel中加标题 --------------------编程问答-------------------- BindTotalInfo();Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=GiftSale.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/ms-excel";
this.EnableViewState = true;
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
stringWrite.WriteLine("赠送消费明细表"); //Excel标题
GViewSaleDetail.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
//Response.End();
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End(); --------------------编程问答-------------------- 把要输出的样子,全部显示到页面上,然后把整页输出! --------------------编程问答-------------------- 我是把数据库中的一张表导出 --------------------编程问答-------------------- LblTitle.RenderControl(htmlWrite); --------------------编程问答-------------------- 你是用的什么方法啊?贴上来看看! --------------------编程问答-------------------- DataGrid dgExcel=new DataGrid();
sql="select * from tnc_htgldjb ";
da.g_dbothercomand(sql,"misdb");
dgExcel.DataSource=ds.Tables["temp_#"].DefaultView;
dgExcel.DataBind();
//将DataGrid导出到Excel
UserFunc uf=new UserFunc();
uf.OutToExcel(dgExcel,"合同登记"); --------------------编程问答-------------------- 在报表中加个标题不行吗?为什么要这么复杂? --------------------编程问答-------------------- 不做报表
就是把datagrid中内容直接导出excel
想加个标题
如何修改导出的表啊? --------------------编程问答-------------------- OutToExcel()这个方法的内容? --------------------编程问答-------------------- 给你这样的思路
点导出的时候先把GV加上一行,再导出~~ --------------------编程问答-------------------- public void OutToExcel(DataGrid dg,string tableName)
{
tableName=tableName+DateTime.Now.Year+DateTime.Now.Month+DateTime.Now.Day+".xls";
//System.Web.HttpContext.Current.System.Web.HttpContext.Current.Response
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.Buffer= false;
//用gb2312和utf-8会出现乱码
System.Web.HttpContext.Current.Response.Charset="utf-7";
//System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+tableName);
System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+System.Web.HttpUtility.UrlEncode(tableName,System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-7");
//设置输出文件类型为excel文件。
System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
dg.EnableViewState = false;
dg.AllowPaging=false;
dg.AllowSorting=false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
dg.RenderControl(oHtmlTextWriter);
System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString());
System.Web.HttpContext.Current.Response.End();
} --------------------编程问答-------------------- 我写的是把数据库中的表导出来
和gv没什么关系把 --------------------编程问答-------------------- 怎么才能把已经导出的excel加上标题呢? --------------------编程问答-------------------- 在datagrid中先加标题行(合并单元格,再把标题写进去),然后再用你的方法到出到excel
补充:.NET技术 , ASP.NET