PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

How to export dynamically generated html table to Excel Sheet

 
 
=?Utf-8?B?U21pdGhhIEJhdmFuZGxh?=
Guest
Posts: n/a
 
      11th Aug 2005
I have an aspx page("for generating report") in which i have 4 table
tags("<table></table>" for heading of report etc.) and the rows and cells to
them are dynamically created based on the values retrieved from database in
the form od dataset which results 4 tables. For ex:
Dim HeaderRow = New HtmlTableRow
Dim HeaderCell = New HtmlTableCell
HeaderCell.Height = "5"
HeaderCell.Attributes.Add("ALIGN", "center")
HeaderCell.Attributes.Add("CLASS", "ins-popupheader")
HeaderCell.InnerText = ds.Tables(0).Rows(0)("Title") & " -
Content Report"
HeaderRow.Cells.Add(HeaderCell)
tblHeader.Rows.Add(HeaderRow)

Now the problem is.... I have an anchor tag on my report page "Export as
CSV" on click of which I need to export the contents of the page to an Excel
sheet.
I tried with the following code:

Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader("Content-Disposition",
"attachment;filename=Ebom.xls")

Dim dsExport As DataSet = Session("Contentds")
Dim tw As New System.IO.StringWriter
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Dim dgGrid As New DataGrid

Dim i As Integer = 0
For Each table As DataTable In dsExport.Tables
dgGrid.DataSource = dsExport.Tables(i)
dgGrid.DataBind()
dgGrid.RenderControl(hw)
i = i + 1
Next

' Write the HTML back to the browser.
Response.Write(tw.ToString())

' End the response.
Response.End()

It generates an Excel sheet but the format is not clear and I am missing
some contents of my report page. I request if any one can help me in directly
exporting the contents of my report page to Excel.
A quick response is appreciated........
Thanking in anticipation
--smitha
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to update an excel sheet dynamically from another excel sheet? Mona Microsoft Excel Misc 3 12th Jul 2008 04:42 PM
Dynamically generated Table Rows Dissappear Bijoy Naick Microsoft ASP .NET 3 30th Nov 2004 01:46 AM
dynamically generated html =?Utf-8?B?a2V2d2FzaA==?= Microsoft Frontpage 6 24th Nov 2004 04:51 PM
Re: Directing dynamically generated html content to word from ASP.NET Steve C. Orr [MVP, MCSD] Microsoft ASP .NET 0 3rd Jun 2004 07:36 AM
How to insert dynamically generated HTML into the <body> of an ASP.NET page? Rick Spiewak Microsoft ASP .NET 5 1st Aug 2003 01:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:02 AM.