Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Response.Clear()
       Response.Buffer = True
       Response.ContentType = "application/vnd.ms-excel"
       Response.AddHeader("Content-Disposition", "attachment; filename=UserList.xls; sheet=Sheet2")
       Response.Charset = ""
       Me.EnableViewState = False
       Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter
       Dim oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
       dgSearchResult.RenderControl(oHtmlTextWriter)
       Response.Write(oStringWriter.ToString())
       Response.End()

 

The original code I got from this very firm and I modified it to the one above.

Now the problem is with Paging Enabled, it only saves the excel file with the current page recods.

 

Is there a way I could go about getting all the records in the excel file without them being displayed on the DataGrid

 

 

Thanks

Ashutosh

Posted
Loop thru your dataset and build a tab delilimted string, then write it to your stream with the .xls file extension. I have never figured out how to write a xls from a datagrid without all the formatting junk that gets carried over from the html.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...