通过C#将SqlServer中存储过程查询出的结果到出到Excel???
通过C#编写代码
调用SqlServer中存储过程
将查询出的结果到出到Excel!
应该如何写代码
请高手指点一下?
多谢了!!!
------解决方案--------------------public static void GenerateByHtmlString(string Typename, string TempHtml)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Charset = "utf-8 ";
string Filename = Typename + ".xls ";
HttpContext.Current.Response.AppendHeader( "Content-Disposition ", "online;filename= " + Filename);
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding( "utf-8 ");
HttpContext.Current.Response.ContentType = "application/ms-excel ";
//this.EnableViewState = false;
HttpContext.Current.Response.Write(TempHtml);
HttpContext.Current.Response.End();
}
Typename 文件名
TempHtml 将数据配置成HTML字符串放到这个字符串里
------解决方案--------------------//要求:有datagrid控件,Boyd_Dg1,将数据先绑定至Boyd_Dg1即可,
Response.Clear();
Response.Buffer= true;
Response.Charset= "GB2312 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=boyd_Reporter.xls ");
Response.ContentEncoding=System.Text.Encoding.GetEncoding( "GB2312 ");//设置输出流为简体中文
Response.ContentType = "application/ms-excel ";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo( "ZH-CN ",true);
System.IO.StringWriter oStringWriter=new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter=new System.Web.UI.HtmlTextWriter(oStringWriter);
this.Boyd_Dg1.Font.Size=10; //设置输出报表文字大小为10号,偏小
this.Boyd_Dg1.BorderStyle=System.Web.UI.WebControls.BorderStyle.Double;
this.Boyd_Dg1.BorderColor=Color.Black;
this.Boyd_Dg1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
------解决方案--------------------Response.Clear();
Response.Buffer= true;
Response.Charset= "GB2312 ";
Response.AppendHeader( "Content-Disposition ", "attachment;filename=boyd_Reporter.xls ");
Response.ContentEncoding=System.Text.Encoding.GetEncoding( "GB2312 ");//设置输出流为简体中文
Response.ContentType = "application/ms-excel ";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo( "ZH-CN ",true);
System.IO.StringWriter oStringWriter=new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter=new System.Web.UI.HtmlTextWriter(oStringWriter);
this.Boyd_Dg1.Font.Size=10; //设置输出报表文字大小为10号,偏小
this.Boyd_Dg1.BorderStyle=System.Web.UI.WebControls.BorderStyle.Double;
this.Boyd_Dg1.BorderColor=Color.Black;
this.Boyd_Dg1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();