数据绑定到Repeater1 ,下面是将Repeater1的内容导出的示例代码
System.IO.StringWriter sw
=
new
System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw
=
new
System.Web.UI.HtmlTextWriter(sw);
this
.Repeater1.RenderControl(hw); Response.Clear(); Response.ContentType
=
"
application/vnd.ms-excel
"
; Response.Charset
=
""
; Page.EnableViewState
=
false
; Response.AppendHeader(
"
Content-Disposition
"
,
"
attachment;filename=Teacher.xls
"
); Response.Write(
"
<html><head><meta http-equiv=Content-Type content=\
"
text
/
html; charset
=
GB2312\
"
><title> Copyright by SDU</title></head><body><center>
"
); Response.Write(sw.ToString()); Response.Write(
"
</center></body></html>
"
); Response.End();
说明:当字符型的数字串导出到excel的时候,经常自动变为科学记数法表示,解决的方法,绑定到Repeater1的时候如此:
<
td style
=
"
vnd.ms-excel.numberformat:@
"
><%
# DataBinder.Eval(Container.DataItem,
"
shenfenzheng
"
)
%></
td
>
转载于:https://www.cnblogs.com/powerlc/archive/2005/08/27/223989.html
相关资源:repeater,和GridView导出数据到Excel或是word