惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
C
Check Point Blog
P
Proofpoint News Feed
H
Help Net Security
月光博客
月光博客
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
U
Unit 42
美团技术团队
I
InfoQ
A
About on SuperTechFans

博客园 - huazi4995

prototype.js开发笔记 JS应用 java环境配置 关于梅花雪的js树 - huazi4995 - 博客园 MagicAjax的使用 - huazi4995 - 博客园 div+css制作的选项卡 - huazi4995 - 博客园 关于word文档的数据库存取 SQL查询语句精华使用简要 - huazi4995 - 博客园 身份证号码验证-支持新的带x身份证 c#常用函数和方法集汇总 动态创建层 C#操作Word文档(Office 2007) datagrid控件使用技巧大集合 网站设计常用技巧 jsp编程技巧 ArrayList的使用方法(转载) js中的小技巧 ajax+xml数据岛,增加编辑与删除按钮 利用webservice实现省、市的无刷新
将datagrid里的资料导入到excel
huazi4995 · 2006-12-08 · via 博客园 - huazi4995

private void DG_TO_Excel()
{
            Response.clear();
            Response.Buffer
=true;
            Response.Charset
="GB2312";
            Response.AppendHeader(
"content-Disposition","attachment;filename=FileName.xls");
            Response.contentEncoding
=System.Text.Encoding.GetEncoding("GB2312");
            Response.ContentType
="application/vnd.ms-excel";
//Response.ContentType="application/vnd.ms-word"; //导到word
            
Response.Charset="";
            
this.EnableViewState=false;
            System.Io.StringWriter str
=new System.Io.StringWriter();
            System.Web.UI.HtmlTextWriter htw
=new System.Web.UI.HtmlTextWriter(str);
//this.ClearControls(DataGrid1);
            
DataGrid1.RenderControl(htw);
            Response.write(str.ToString());
            Response.End();
}

Private wid clearcontrols(control control)
{
for(int i=control.controls.Count-1; i>=0;i--)
{
clearControls(control.controls[i])
{
if(!(control is Tablecell))
{
if(control.GetType().Getproperty("SelectedItem")!=null)
Literalcontrol literal
=new LiteralControl);
control.Parent.Controls.Add(literal);
try
{
literal.Text
=(string)control.GetType().Getproperty("SelectedItem").GetValue(control.null);
}

catch
{
throw;
}

control.Parert.Controls.Remove(control);
}

else if(control.GetType().Getproperty("Text")!=null)
{
LiteralControl literal
=new LiteralControl();
control.Parent.controls.Add(literal);
literal.Text
=(string)control.GetTypel().Getproperty("Text").GetValue(control,null)
control.parent.Controls.Remove(control);
}

}

return;
}