2024年3月7日发(作者:)

repeater把数据导出到Excel

方法一:

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

string attachment = "attachment; filename=";

ontent();

der("content-disposition", attachment);

tType = "application/octet-stream";

Control(htw);

(ng());

();

();

方法二:

StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

HtmlTextWriter htw = new HtmlTextWriter(sw);

Page page = new Page();

HtmlForm form = new HtmlForm();

ViewState = false;

EventValidation = false;

erInitialize();

(form);

(Repeater1);

Control(htw);

();

= true;

tType = "application/ms-excel";

der("Content-Disposition", "attachment;filename="

+ ode("", 8).ToString());

t = "UTF-8";

tEncoding = t;

(ng());

();

分页Repeater导出数据到Excel

1.导出Repeater中的数据时,导出的数据必须是完整的数据块,例如:完整的table。

2.如果导出的数字按科学计数法显示则在那列加入样式:style="format:@"即可。

er导出到Excel的代码(C#):

public static void ReportToExcel(l ctl)

{

tEncoding = 8;

tType = "application/ms-excel";

t = "gb2312";

Header("Content-Disposition", "attachment;filename=" + ode("", 8).ToString());

StringWriter sw = new StringWriter();

HtmlTextWriter htw = new HtmlTextWriter(sw);

Control(htw);

(ng());

();

}

4.如果支持分页,并且页面不是回发的情况下,可以用如下方法调用:

string where = ("{0} and PayState=1", whereSQL);//根据需要,重新拼写where条件

DataTable dt = DesignerList(where,

orderSQL, 1, recordCount); //recordCount为记录的总条数

urce = dt;

nd();

ReportToExcel(Repeater1);