Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Export DataGrid to Excel Problem with Code.

Export DataGrid to Excel Problem with Code.

Scheduled Pinned Locked Moved ASP.NET
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Asif Rehman
    wrote on last edited by
    #1

    Following code does not handle columns that start with + e.g. '+923339933886' is not rendered well(some kind of charmap characters shown). here is what it shows.(꺻퍎)

        HtmlForm form = new HtmlForm();
        string attachment = "attachment; filename=Employee.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter stw = new StringWriter();
        HtmlTextWriter htextw = new HtmlTextWriter(stw);
        form.Controls.Add(gvEmployee);
        this.Controls.Add(form);
        form.RenderControl(htextw);
        Response.Write(stw.ToString());
        Response.End();
    

    Please let me know what is the changes required in this code.

    T S 2 Replies Last reply
    0
    • A Asif Rehman

      Following code does not handle columns that start with + e.g. '+923339933886' is not rendered well(some kind of charmap characters shown). here is what it shows.(꺻퍎)

          HtmlForm form = new HtmlForm();
          string attachment = "attachment; filename=Employee.xls";
          Response.ClearContent();
          Response.AddHeader("content-disposition", attachment);
          Response.ContentType = "application/ms-excel";
          StringWriter stw = new StringWriter();
          HtmlTextWriter htextw = new HtmlTextWriter(stw);
          form.Controls.Add(gvEmployee);
          this.Controls.Add(form);
          form.RenderControl(htextw);
          Response.Write(stw.ToString());
          Response.End();
      

      Please let me know what is the changes required in this code.

      T Offline
      T Offline
      thatraja
      wrote on last edited by
      #2

      Hi, I think you should set the encoding to UTF-8. Have a look at this thread which has answer(4th post by user lionscub). Export DataGrid To Excel[^] Free attachment You may need this too.(For Ex, large numbers get converted to the (ugly) x.xxxxxxE-yy syntax. ) Datagrid to Excel Formatting Tip[^]

      thatraja |Chennai|India|


      Brainbench certifications
      My Dad had a Heart Attack on this day so don't...

      1 Reply Last reply
      0
      • A Asif Rehman

        Following code does not handle columns that start with + e.g. '+923339933886' is not rendered well(some kind of charmap characters shown). here is what it shows.(꺻퍎)

            HtmlForm form = new HtmlForm();
            string attachment = "attachment; filename=Employee.xls";
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            StringWriter stw = new StringWriter();
            HtmlTextWriter htextw = new HtmlTextWriter(stw);
            form.Controls.Add(gvEmployee);
            this.Controls.Add(form);
            form.RenderControl(htextw);
            Response.Write(stw.ToString());
            Response.End();
        

        Please let me know what is the changes required in this code.

        S Offline
        S Offline
        Srinivas_Kotra
        wrote on last edited by
        #3

        hi, here is the code Exporting DataGrid to Excel, Word and Text Files[^] Thanks,

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups