从数据库导出到excel

在项目 扬中 News shenbaocreateall

//选中的id 

string cc = Request["IDcheck"];
            Response.Clear();
            Response.Buffer = true;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMdd") + ".xls");
       //这里注意编码方式    

Response.ContentEncoding = System.Text.Encoding.Default;
            Response.ContentType = "application/vnd.ms-excel";

 

 StringBuilder sb = new StringBuilder("");
            sb.Append("申请类别(创新创业)</b>");
            sb.Append("\t");
            sb.Append("申请类别(单位个人)");
            sb.Append("\t");

  sb.Append("\n");
            Response.Write(sb.ToString());

            sb.Clear();
            string[] cc_arry =cc.Split(new char[]{','});


            //for
            for(int i=0;i<cc_arry.Length ;i++)
            {
                int id = Convert.ToInt32(cc_arry[i]);
                shenbao getmodel = db.shenbaos.Find(id);

  sb.Append(getmodel.Type);
            sb.Append("\t");
            sb.Append(getmodel.PersonType);
            sb.Append("\t");
            sb.Append(getmodel.LuoHuDiQu);
            sb.Append("\t");
            sb.Append(getmodel.name);
            sb.Append("\t");

  sb.Append(getmodel.IsYouHeZuo);

//最后一个 是\n
                   sb.Append("\n");

  }
            Response.Write(sb.ToString());
            Response.End();