gridview 导出到EXCEL,导出数据时一条的话就能看到数据,是多条数据导出来excel里面就是空白,代码显示是有数据的,
excel 的大小都有~!

解决方案 »

  1.   

    Excel程序打开里面没内容?看你的代码怎么写的
      

  2.   

        protected void btnExport_Click(object sender, EventArgs e)
        {
    HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;//
            HttpContext.Current.Response.AppendHeader("Content-Disposition",
                "attachment;filename=" + DateTime.Now.ToShortDateString() + ".xls");
            HttpContext.Current.Response.ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword 
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            gvCustomerAnalysis.RenderControl(hw);
            HttpContext.Current.Response.Write(tw.ToString());
            HttpContext.Current.Response.End();
    }
      

  3.   

    代码是这样写的,是网上copy的~
    困扰我2天了 
      

  4.   

    在vs2005的异常跟踪里面,显示的数据都有,但就是输出到excel里面的时候就么有数据了(gridview里面有一条数据的话,就能正确的出来)
      

  5.   


        //转EXCEL
        protected void BtnExcel_Click(object sender, EventArgs e)
        {
            Export("application/ms-excel", "Detail.xls");
        }
        private void Export(string FileType, string FileName)
        {
            Response.Charset = "GB2312";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
            Response.ContentType = FileType;
            this.EnableViewState = false;
            StringWriter tw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(tw);
            GridView1.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
        }
      

  6.   

    应该是没有一下代码的原因
      public override void VerifyRenderingInServerForm(Control control)
      {
      }