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. Grid To Excel

Grid To Excel

Scheduled Pinned Locked Moved ASP.NET
cssdesignhelp
4 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.
  • 4 Offline
    4 Offline
    4anusha4
    wrote on last edited by
    #1

    In my application i had headings in between the grid rows when i export the grid to excel the headings were not displayed i used the code like this Response.Clear(); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); htmlWrite.WriteLine("<b><font size=5 color=red>" + Heading.ToString() + "</font></b> <b><font size=4 color=blue>TDP IT-Department</font></b>"); //System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid(); //dg.DataSource = dv.Table; //dg.DataBind(); gv.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); help me out to solve this

    C L 2 Replies Last reply
    0
    • 4 4anusha4

      In my application i had headings in between the grid rows when i export the grid to excel the headings were not displayed i used the code like this Response.Clear(); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); htmlWrite.WriteLine("<b><font size=5 color=red>" + Heading.ToString() + "</font></b> <b><font size=4 color=blue>TDP IT-Department</font></b>"); //System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid(); //dg.DataSource = dv.Table; //dg.DataBind(); gv.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); help me out to solve this

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Not shown at all, or just not styled ?

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      4 1 Reply Last reply
      0
      • C Christian Graus

        Not shown at all, or just not styled ?

        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

        4 Offline
        4 Offline
        4anusha4
        wrote on last edited by
        #3

        not shown at all an empty row is being displayed i used the code like this to add a row to grid DataTable dt1 = dv1.ToTable(true, "nDepartmentID", "sDepartmentName"); int i = 2; // Session["i"] = ds.Tables[0].DefaultView; for (int m = 0; m <= dt1.Rows.Count - 1; m++)// foreach (DataRow dr in dt1.Rows) { DataTable dt = dv1.ToTable("dt", false); object objCount = dt.Compute("count(nDepartmentID)", "nDepartmentID in (" + int.Parse(dt1.Rows[m]["nDepartmentID"].ToString()) + ")"); if (dt.Rows.Count > 0) { GridViewRow gvRow = new GridViewRow(i, 0, DataControlRowType.DataRow, DataControlRowState.Insert); TableCell tblCell = new TableCell(); //Add Summary Row tblCell.Text = dt1.Rows[m]["sDepartmentName"].ToString(); tblCell.ColumnSpan = 6; tblCell.BorderWidth = 2; tblCell.HorizontalAlign = HorizontalAlign.Left; tblCell.ForeColor = System.Drawing.Color.Red; tblCell.Font.Bold = true; tblCell.Font.Size = 12; gvRow.Cells.Add(tblCell); gridView.Controls[0].Controls.AddAt(i, gvRow); i = i + int.Parse(objCount.ToString()) + 1; } }

        1 Reply Last reply
        0
        • 4 4anusha4

          In my application i had headings in between the grid rows when i export the grid to excel the headings were not displayed i used the code like this Response.Clear(); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite); htmlWrite.WriteLine("<b><font size=5 color=red>" + Heading.ToString() + "</font></b> <b><font size=4 color=blue>TDP IT-Department</font></b>"); //System.Web.UI.WebControls.DataGrid dg = new System.Web.UI.WebControls.DataGrid(); //dg.DataSource = dv.Table; //dg.DataBind(); gv.RenderControl(htmlWrite); Response.Write(stringWrite.ToString()); Response.End(); help me out to solve this

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          use this code. Dim attachment As String = "attachment; filename=MyFile.xls" Response.ClearContent() Response.AddHeader("content-disposition", attachment) Response.ContentType = "application/ms-excel" Dim sw As New StringWriter() Dim htw As New HtmlTextWriter(sw) Dim frm As New HtmlForm() GridViewEmployeeRegistrationDetails.Parent.Controls.Add(frm) frm.Attributes("runat") = "server" frm.Controls.Add(GridViewEmployeeRegistrationDetails) frm.RenderControl(htw) Response.Write(sw.ToString()) Response.End()

          Thanks and Regards Sujit Kr. Mandal

          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