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. General Programming
  3. Visual Basic
  4. exporting to excel

exporting to excel

Scheduled Pinned Locked Moved Visual Basic
htmldatabasedesignhelp
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.
  • S Offline
    S Offline
    sivaram praveen
    wrote on last edited by
    #1

    hi all, in my application im having code to convert the datagrid values to excel sheet but when it is saving it is taking .html extension instead if .xls, pls help me to sort out. Response.Clear() Response.Buffer = True Response.AddHeader("content-position", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.ms-Excel" Me.EnableViewState = False Dim stringwrite As New System.IO.StringWriter Dim htmlwrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringwrite) Dim da_GetAllBooks As SqlDataAdapter = New SqlDataAdapter("GetAllBooks_Proc", Con) da_GetAllBooks.SelectCommand.CommandType = CommandType.StoredProcedure da_GetAllBooks.Fill(_dataSet, "AllBooks(0)") Dim index As Integer = 0 For index = 0 To dg_AllBooks.Columns.Count - 1 dg_AllBooks.Columns(index).SortExpression = True Next dg_AllBooks.DataSource = (_dataSet.Tables("AllBooks")) dg_AllBooks.DataBind() dg_AllBooks.RenderControl(htmlwrite) Response.Write(stringwrite.ToString()) Response.End() help me

    P 1 Reply Last reply
    0
    • S sivaram praveen

      hi all, in my application im having code to convert the datagrid values to excel sheet but when it is saving it is taking .html extension instead if .xls, pls help me to sort out. Response.Clear() Response.Buffer = True Response.AddHeader("content-position", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.ms-Excel" Me.EnableViewState = False Dim stringwrite As New System.IO.StringWriter Dim htmlwrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringwrite) Dim da_GetAllBooks As SqlDataAdapter = New SqlDataAdapter("GetAllBooks_Proc", Con) da_GetAllBooks.SelectCommand.CommandType = CommandType.StoredProcedure da_GetAllBooks.Fill(_dataSet, "AllBooks(0)") Dim index As Integer = 0 For index = 0 To dg_AllBooks.Columns.Count - 1 dg_AllBooks.Columns(index).SortExpression = True Next dg_AllBooks.DataSource = (_dataSet.Tables("AllBooks")) dg_AllBooks.DataBind() dg_AllBooks.RenderControl(htmlwrite) Response.Write(stringwrite.ToString()) Response.End() help me

      P Offline
      P Offline
      pmarfleet
      wrote on last edited by
      #2

      Your code is confusing. You seem to be trying to i) output an Excel file and ii) display a DataGrid at the same time. You can't do both - your page can't return binary content and HTML at the same time. To dynamically build an Excel spreadsheet, do a search on CodeProject or Google for the JET OLE Provider. You should find plenty of examples.

      Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush

      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