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

推荐订阅源

Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
J
Java Code Geeks
L
LangChain Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
B
Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog

博客园 - 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;
}