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 data from datatable to Excel

Export data from datatable to Excel

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

    Hi all, Can any one tell me how to export the data from datatable to excel without using Microsoft.office.tools..... and formating the cells in the excel like in one cell entering 2-3 values etc. Thanks in advance..

    A K 2 Replies Last reply
    0
    • S sarang_k

      Hi all, Can any one tell me how to export the data from datatable to excel without using Microsoft.office.tools..... and formating the cells in the excel like in one cell entering 2-3 values etc. Thanks in advance..

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      sarangkhandare wrote:

      Can any one tell me how to export the data from datatable to excel

      Have a look

      sarangkhandare wrote:

      formating the cells in the excel like in one cell entering 2-3 values

      I don't understand this point. Can you be please more specific? Thank you!

      cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net

      1 Reply Last reply
      0
      • S sarang_k

        Hi all, Can any one tell me how to export the data from datatable to excel without using Microsoft.office.tools..... and formating the cells in the excel like in one cell entering 2-3 values etc. Thanks in advance..

        K Offline
        K Offline
        Kapil Thakur
        wrote on last edited by
        #3

        give a linkbutton "export to excel" and do the following code on its click event Dim Grid As New System.Web.UI.WebControls.GridView Try       Grid.AutoGenerateColumns = True       Grid.RowStyle.Wrap = True       Grid.AlternatingRowStyle.Wrap = True       Grid.DataSource = [YOUR DATASET]       Grid.DataBind()       -- header style required by you for excel       Grid.HeaderRow.Cells(0).Width = 200       Grid.HeaderRow.Style("font-family") = "Verdana"       Grid.HeaderRow.Style("font-size") = "12px"       Grid.HeaderRow.Font.Bold = True       Grid.HeaderRow.ForeColor = Color.White       Grid.HeaderRow.BackColor = Color.Blue       For Each row As System.Web.UI.WebControls.GridViewRow In Grid.Rows             -- row style required by you for excel             row.Cells(0).Width = 100             row.Style("font-family") = "Verdana"             row.Style("font-size") = "12px"             row.Style("text-align") = "left"       Next       Response.Clear()       Response.AddHeader("content-disposition", "attachment;filename=" & [YOUR PREFERRED FILE NAME] & ".xls")       Response.Charset = ""       Response.Cache.SetCacheability(HttpCacheability.NoCache)       Response.ContentType = "application/vnd.xls"       Dim stringWrite As New System.IO.StringWriter()       Dim htmlWrite As New HtmlTextWriter(stringWrite)       Grid.RenderControl(htmlWrite)       Response.Write(stringWrite.ToString())       Response.End() Catch ex As Exception Finally       Grid.Dispose()       Grid = Nothing End Try

        Regards, Kapil Thakur (Where's there is Kapil , there is a way) - thakur.kapil@gmail.com

        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