博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
项目--简单导出CSV文件
阅读量:5343 次
发布时间:2019-06-15

本文共 1943 字,大约阅读时间需要 6 分钟。

//导出    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;    }

  

转载于:https://www.cnblogs.com/buzi521/p/3830159.html

你可能感兴趣的文章
数和二叉树的基本概念和类型
查看>>
Oracle 基础学习(二) SQL基础查询
查看>>
弹出提示框,大面板
查看>>
poj2975(nim游戏取法)
查看>>
每天进步一点点010
查看>>
九度OJ 1535 重叠的最长子串
查看>>
【Swing 1】paint / paintComponent的区别和背景颜色设置的三种方法
查看>>
Analyzer中进行货币转换
查看>>
获取元素属性get_attribute
查看>>
视觉设计师的进化
查看>>
Python/jquery
查看>>
WPF之Binding
查看>>
【BZOJ】【2132】圈地计划
查看>>
vue中的小坑
查看>>
[转] Android OkHttp完全解析 是时候来了解OkHttp了
查看>>
软件开发设计原则
查看>>
完成评论功能
查看>>
Pod和Namespace的基本介绍
查看>>
软件工程作业---单元测试
查看>>
python学习笔记15(面向对象编程)
查看>>