Solved

exporting html table to excel is exporting whole page?

Posted on 2011-03-04
1
702 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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 …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

809 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