注册 登录
编程论坛 ASP.NET技术论坛

sql 到Execl(asp.net)

makewelldone 发布于 2007-04-03 16:52, 511 次点击
谁有将sql表中数据导入execl的代码
4 回复
#2
bygg2007-04-03 17:09
找找吧,前面就有的..
#3
cyyu_ryh2007-04-03 17:21

我这是从GRIDVIEW中导出的,要添加引用

using System.IO;
using System.Text;


#region 导出报表
protected void Button6_Click(object sender, EventArgs e)
{
Export("application/ms-excel", "学生成绩报表.xls");
}
private void Export(string FileType, string FileName)
{
Response.Charset = "GB2312";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}

public override void VerifyRenderingInServerForm(Control control)
{
//必须要
}

#endregion

#4
makewelldone2007-04-03 17:47

我是从sql导入execl的

#5
cyyu_ryh2007-04-04 12:54
我想功能都差不多,你把
GridView1.RenderControl(hw);
这点改下看应该可以
1