求助!!!asp.net导出Excel的问题!!!!急急急急急急急!!!!! 最近在做一B/S的系统,其中有一部分要求客户端能够获取服务器数据库上的数据并保存在Excel文件中。具体就是读取数据库服务器上的表,然后导入Excel文件并能控制列宽~谁给个代码啊~~或者发个简单的可运行的demo给我~我的mail:[email protected],谢谢啦!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我写过的一个例子,可能需要你修改一下protected void btn_excel_Click(object sender, EventArgs e) { Response.Clear(); string excelname = "96447"; Response.AddHeader("content-disposition", "attachment;filename="+excelname+".xls"); Response.Charset = "gb2312"; Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); GV_Daily.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); GV_Daily.AllowPaging = true; GV_BindData(); }下面这个自定义函数必须写: public override void VerifyRenderingInServerForm(Control control) { // Confirms that an HtmlForm control is rendered for } 在要保存的ASPX页面第一行加这一段试试 <% Response.Buffer= true; Response.Charset="GBK"; Response.AppendHeader("Content-Disposition","attachment;filename=tablefile.xls"); Response.ContentEncoding=System.Text.Encoding.GetEncoding("GBK"); Response.ContentType = "application/ms-excel"; this.EnableViewState = false; %>和楼上的原理一样,只不过我这个是放在页面文件头的。 非常感谢楼上2位!!我是想把数据库里的表填充到dataset里,然后直接从dataset里导出到Excel文件中,不用gridview等控件~再次感谢~ winform中怎么样windows player播放器里面同步歌词? UltraGrid合并单元格? 使用 Visual C# .NET 打印 RichTextBox 控件的内容 的问题 跪求C#与研华采集卡通讯程序?? 导出到Excel表中,数据超过了65536时,怎么处理呀?谢谢啦! 关于线程的问题 菜鸟一个,请教大家一个问题 窗口名为变量时,要带参数地实例化,超难! 能不能对用DataView.RowFilter()筛选条件后的记录进行操作?如删除.. 求救!!江湖救急!!在一个工程里序列化的文件,在另外一个工程里反序列化出错!!!!! 如何正常连接2个数据库 C#IO问题
{
Response.Clear();
string excelname = "96447";
Response.AddHeader("content-disposition", "attachment;filename="+excelname+".xls");
Response.Charset = "gb2312";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GV_Daily.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
GV_Daily.AllowPaging = true;
GV_BindData();
}
下面这个自定义函数必须写:
public override void VerifyRenderingInServerForm(Control control)
{
// Confirms that an HtmlForm control is rendered for
}
<%
Response.Buffer= true;
Response.Charset="GBK";
Response.AppendHeader("Content-Disposition","attachment;filename=tablefile.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GBK");
Response.ContentType = "application/ms-excel";
this.EnableViewState = false;
%>和楼上的原理一样,只不过我这个是放在页面文件头的。