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

导出EXCEL

时间:2014-06-29 14:28:54      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:http   get   文件   数据   os      

 private void CreateExcel()
        {
            string header = string.Empty;
            string line = string.Empty;

            try
            {
               
                dltDataBind();

                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "utf-8";
                Response.AppendHeader("Content-Disposition", "attachment;filename=orginfo.xls");
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                header = "拜访时间\t" +"机构名\t" +"所在地\t" + "客户类别\t" +"销售方式\t" +"拜访方式\t" + "销售员\t" +"是否集体培训\t" + "拜访人\t" + "撰写人\t" + "最后修改时间\t";

                Response.Write(header.ToString());

                DataTable dt = ds.Tables[0];

                int rows = 1;
                //逐行处理数据   
                foreach (DataRow dr in dt.Rows)
                {

                    line = string.Empty;//dt.Rows.IndexOf(dr);

                    //在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
                    line = rows.ToString() + "\n" + DealWithValue(dr["bfqssj"]).ToString() + "\t" +
                        DealWithValue(dr["org_name"]).ToString() + "\t" +
                        DealWithValue(dr["org_area"]).ToString() + "\t" +
                        DealWithValue(dr["khlb"]).ToString() + "\t" +
                        DealWithValue(dr["sale_process"]).ToString() + "\t" +
                        DealWithValue(dr["bffs"]).ToString() + "\t" +
                        DealWithValue(dr["saler"]).ToString() + "\t" +
                        DealWithValue(dr["ass_saler"]).ToString() + "\t" +
                         DealWithValue(dr["is_jtpx"]).ToString() + "\t" +
                          DealWithValue(dr["unames"]).ToString() + "\t" +
                           DealWithValue(dr["operater"]).ToString() + "\t" +
                            DealWithValue(dr["op_date"]).ToString() + "\t" +  
                        "\n";

                    rows = rows +1;
                    //当前行数据写入HTTP输出流
                    Response.Write(line);
                }

                //写缓冲区中的数据到HTTP头文件中
                Response.End();

            }

            catch (Exception ex)
            {
                Console.Write(ex.ToString());
            }
        }  
       
        protected void btnoutex_Click1(object sender, EventArgs e)
        {
            CreateExcel();
        }

导出EXCEL,布布扣,bubuko.com

导出EXCEL

标签:http   get   文件   数据   os      

原文地址:http://www.cnblogs.com/liupengfei19940119/p/3755712.html

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