会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
HuaZi4995 工 作 笔 记
路漫漫其修远兮!!!
博客园
首页
新随笔
联系
订阅
管理
将datagrid里的资料导入到excel
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
;
}
posted on
2006-12-08 21:21
huazi4995
阅读(
215
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部