查看单个帖子
旧 2007-11-06, 02:09 PM   #1
huangyhg
超级版主
 
huangyhg的头像
 
注册日期: 04-03
帖子: 18592
精华: 36
现金: 249466 标准币
资产: 1080358888 标准币
huangyhg 向着好的方向发展
默认 用客户端脚本,就可以导出Word和Excel

在服务器端,示范代码如下:

Response.Clear();
Response.Buffer=true;
//使用中文
Response.Charset="gb2312";
Response.AppendHeader("Content-Disposition","attachment;filename="+file+".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("gb2312");
//设置格式为Excel
Response.ContentType="application/ms-excel";
EnableViewState=false;
System.IO.StringWriter sw=new System.IO.StringWriter();
HtmlTextWriter tw=new HtmlTextWriter(sw);
dg.RenderControl(tw);
Response.Write(sw.ToString());
Response.End();

你就可以实现把指定区域导出成Excel了,呵呵!(没有客户端脚本,不需要安装任何东西)
huangyhg离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)