NinetyNine's Treasure

| 积淀*育创新 智慧创造价值|

导航

导出Excel表

Posted on 2007-08-07 02:08  (NineTyNine)  阅读(468)  评论(0编辑  收藏  举报
DataSet ds = (DataSet)Session["ds"];//Session["ds"]为接口
DataTable dt=ds.Tables[0];     
StringWriter sw
=new StringWriter();  
sw.WriteLine(
"货品单号,货品名称,货品数量,货品价格,提供商,货品仓库,付款方式,够入部门,够入时间,操作人,状态");     
foreach(DataRow dr in dt.Rows)     
{     
    sw.WriteLine(dr[
"danhao"]+","+dr["capname"]+","+dr["total"]+","+dr["price"]+","+dr["offername"]+","+dr["Wname"]+","+dr["paytype"]+","+dr["deptname"]

+","+dr["indate"]+","+dr["operator"]+","+dr["Fname"]);     
}
     
sw.Close();     
Response.AddHeader(
"Content-Disposition","attachment;filename=gdzc.csv");     
Response.ContentType
="application/ms-excel";     
Response.ContentEncoding
=System.Text.Encoding.GetEncoding("GB2312");     
Response.Write(sw);     
Response.End(); 
NinetyNine学习