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. Problem in writing from a datagrid to Excel..

Problem in writing from a datagrid to Excel..

Scheduled Pinned Locked Moved ASP.NET
helpdesign
2 Posts 2 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.
  • B Offline
    B Offline
    Balagurunathan S
    wrote on last edited by
    #1

    Hi all.. I have a aspx page with a datagrid holding values in it..I need to write the datagrid values in the excel for which i use the following code.. Private Sub btnexcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexcel.Click Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.Public) Response.ContentType = "application/vnd.xls" Dim stringWrite As New System.IO.StringWriter Dim htmlwrite As New System.Web.UI.HtmlTextWriter(stringWrite) dtgdisplay.RenderControl(htmlwrite) Response.Write(stringWrite.ToString()) Response.End() End Sub Everything is ok..But the datagrid contains column and rows with numeric values(16 digits).So when i write it in excel i am getting them in scientific format..Even when i am formatting the cells ,i couldn't the exact values which are in the datagrid.. Someone help in this regard...

    Balaguru

    M 1 Reply Last reply
    0
    • B Balagurunathan S

      Hi all.. I have a aspx page with a datagrid holding values in it..I need to write the datagrid values in the excel for which i use the following code.. Private Sub btnexcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexcel.Click Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.Public) Response.ContentType = "application/vnd.xls" Dim stringWrite As New System.IO.StringWriter Dim htmlwrite As New System.Web.UI.HtmlTextWriter(stringWrite) dtgdisplay.RenderControl(htmlwrite) Response.Write(stringWrite.ToString()) Response.End() End Sub Everything is ok..But the datagrid contains column and rows with numeric values(16 digits).So when i write it in excel i am getting them in scientific format..Even when i am formatting the cells ,i couldn't the exact values which are in the datagrid.. Someone help in this regard...

      Balaguru

      M Offline
      M Offline
      Mayank Parmar
      wrote on last edited by
      #2

      Try this - This code is in c# and you need to use your way to get datatable instead over sqlhepler. ----------------------- string sql = 'Select * from user_MASTER'; DataTable dt = SqlHelper.ExecuteDatatable(SqlHelper.ConnectionString, CommandType.Text, sql); Response.AddHeader("Content-Disposition", "inline;filename=Final.xls"); int i; for (int icol = 0; icol < dt.Columns.Count; icol++) { Response.Write(dt.Columns[icol].ToString() + "\t"); } Response.Write("\n"); foreach (DataRow dr in dt.Rows) { for (i = 0; i < dt.Columns.Count; i++) { Response.Write(dr[i].ToString() + "\t"); } Response.Write("\r"); } Response.End();

      Regards, Mayank Parmar Senior Software Engineer Amba Tech Gandhinagar, India

      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