码迷,mamicode.com
首页 > 其他好文 > 详细

项目--简单导出CSV文件

时间:2014-07-08 00:26:18      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   文件   os   

    //导出
    protected void BtnOutPut_Click(object sender, EventArgs e)
    {
        //角色
        InitialRoles();
        DataTable dt = DBClass.GetDataTable(string.Format(@"SELECT * FROM {0} Order By SN desc", View(Where)));
        StringWriter sw = new StringWriter();
        //4S店不能看到总部价格等相关字段
        if (UMRoleNames.Contains("4S"))
        {
            sw = Get4SStr(dt);
        }
        else
        {
            sw = GetAdminStr(dt);
        }

        sw.Close();
        Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv");
        Response.ContentType = "application/ms-excel";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        Response.Write(sw);
        Response.End();
    }
 //4S店拼接
    protected StringWriter Get4SStr(DataTable dt)
    {
        StringWriter sw = new StringWriter();				
        sw.WriteLine(@"采购订单号,区域,4S店名,品牌,零件编码,零件名称,车型代码,数量,4S成本价,总部采购单价,总部采购合计,4S店节约金额,供应商,要求到货日期,实际到货日期,4S采购折扣");
        foreach (DataRow dr in dt.Rows)
        {
            sw.WriteLine(dr["SN"].ToString()
                + "," + dr["FirstArea"].ToString()
                + "," + dr["ShopName"].ToString()
                + "," + dr["ShopBrand"].ToString()
                + "," + "‘" + dr["PNO"].ToString()
                + "," + dr["PName"].ToString()
                + "," + dr["PCarNumber"].ToString()
                + "," + dr["BuyNumber"].ToString()
                + "," + dr["PSRP"].ToString()
                + "," + dr["AdminPrice"].ToString()
                + "," + dr["SUM4SPrice"].ToString()
                + "," + dr["ThriftProfit4S"].ToString()
                + "," + dr["OOffer"].ToString()
                + "," + dr["OJiaoHuoDate"].ToString()
                + "," + dr["RealReachDate"].ToString()
                + "," + dr["Discount4S"].ToString()
                );
        }
        return sw;
    }

  

项目--简单导出CSV文件,布布扣,bubuko.com

项目--简单导出CSV文件

标签:des   style   blog   color   文件   os   

原文地址:http://www.cnblogs.com/buzi521/p/3830159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!