Solved

exporting html table to excel is exporting whole page?

Posted on 2011-03-04
1
704 Views
Last Modified: 2012-05-11
I have a html table on my page:
<table runat="Server" id="TESTTABLE">
            <tr>
                <td style="padding:0 30px 0 0;">
..................... etc etc

In my code behind then on a button click I have:
Dim filename As String = "urXlfileName.xls"
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", "attachment; filename=""" & filename & """")
        Response.ContentEncoding = System.Text.Encoding.UTF7
        Response.Charset = ""
        EnableViewState = False
        Dim strWriter As New StringWriter
        Dim htmlWriter As New System.Web.UI.HtmlTextWriter(strWriter)
        CType(TESTTABLE, HtmlTable).RenderControl(htmlWriter)
        Response.Write(strWriter)

I am getting an export to excel but it is exporting the whole page rather than just the html table.

Why is this?

Thanks
0
Comment
Question by:scm0sml
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
vbwizardry earned 500 total points
ID: 35037152
add Response.End after Response.Write(strWriter)
Response.Write(strWriter)
Response.Flush()
Response.End()

Open in new window


See if this will help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question