首页 > 其他 > 详细

导出EXCEL

时间:2014-05-29 07:53:51      阅读:408      评论:0      收藏:0      [点我收藏+]

 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://www.cnblogs.com/liupengfei19940119/p/3755712.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!