您好,可以直接把数据读出来绑定到gridview然后导出,也可以直接用数据源导
BindExportData();
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=catiProjectlist.xls");
Response.Charset = "GB2312";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
========================================================================
///
/// 导出所有的
///
///
///
protected void btnAllExcel_Click(object sender, EventArgs e)
{
List
StringWriter sw = new StringWriter();
sw.WriteLine("code\trgn_nm\tsubrgn_nm\tgrid_cd\tpref_nm\tcity_id\tcity_std_loc_nm\tstor_id\tstor_nm\tstor_tel\tstor_addr\tcat_type_nm\tmall_nm\tmall_addr\trep_nm\trep_tel\trep_email\tfwFeedBacker\tfwFeedBackConter\tfwFeedBackRemark\tfwFeedBackDate\tintelConter\tintelDate\tstatus\tlast_upd_dtm\tisSeccess\tisFWBackFile");
foreach (tb_diy_store diy in list)
{
sw.WriteLine(diy.Code
+ "\t" + diy.Rgn_nm
+ "\t" + diy.Subrgn_nm
+ "\t" + diy.Grid_cd
+ "\t" + diy.Pref_nm
+ "\t" + diy.City_id
+ "\t" + diy.City_std_loc_nm
+ "\t" + diy.Stor_id
+ "\t" + diy.Stor_nm
+ "\t" + diy.Stor_tel
+ "\t" + diy.Stor_addr
+ "\t" + diy.Cat_type_nm
+ "\t" + diy.Mall_nm
+ "\t" + diy.Mall_addr
);
}
sw.Close();
Response.AddHeader("Content-Disposition", "attachment;filename=DIY-Investigations.xls");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding = Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
}
从数据库导出到数据文件,打开Excel,导入数据文件。