通过C#将SqlServer中存储过程查询出的结果到出到Excel???

gpz_dalian 2007-01-15 02:10:13
通过C#编写代码
调用SqlServer中存储过程
将查询出的结果到出到Excel!
应该如何写代码
请高手指点一下?
多谢了!!!
...全文
315 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyoyidl 2007-12-28
  • 打赏
  • 举报
回复
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();
gangzichh 2007-04-29
  • 打赏
  • 举报
回复
mark
honkerhero 2007-01-15
  • 打赏
  • 举报
回复
据说第一个给的方法较快,第二个次之
bitpolar 2007-01-15
  • 打赏
  • 举报
回复
学习
竹林听雨2005 2007-01-15
  • 打赏
  • 举报
回复
绑定数据的不要我再搞定了吧?
竹林听雨2005 2007-01-15
  • 打赏
  • 举报
回复
//要求:有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();
glacier111 2007-01-15
  • 打赏
  • 举报
回复
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字符串放到这个字符串里

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧