导出Excel表

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学习

你可能感兴趣的:(导出Excel)