Exporting HTML table to Excel

G

Guest

Hi

How can I Export an HTML Table to excel?
My goal is a button, and when the user clicks this button a popup appears
asking the user to 'open' or 'save' the generated Excel file.

Actually I'm exporting by rendering my table to an htmlwriter and sending
this to excel. This is working nearly perfect. There's a problem with Excel's
auto-formatting of cells.
Excel is changing the content of my cells. '1.23' is getting 'Jan 23',
'true' gets 'TRUE' and so on. Always if Excel recognizes a format it knows,
it changes the content.
How can I prevent Excel from doing this?
I want my content 'as is'. Means it shouldn't be changed.
If I need to change my export (creating a excel workbook and sheet in
asp.net) I need at least the coding framework to get one cell filled, because
all my attempts in doing this went to an exception :(

Here's the actual piece of code I'm using:

Dim sw As System.IO.StringWriter = New System.IO.StringWriter
Dim hw As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(sw)
Dim str_temp As String = "attachment;filename=dtsReport_" &
System.DateTime.Today.Month & "-" & System.DateTime.Today.Day & "-" &
System.DateTime.Today.Year & ".xls"
Response.Clear()
Response.AddHeader("content-disposition", str_temp)
Response.ContentType = "application/ms-excel"

tbl_temp.RenderControl(hw)
Response.Write(sw.ToString())
Response.End()
 
G

Guest

thanks for the reply.
but in my Post there was a little bit more precise question. With google I
find how to simply export the data. As you see in my post, I am actually able
to export my data.
The problem is, that it isn't correctly formatted. Means the strings
themselves aren't correct, because Excel auto-formats them after reading my
export.
And if it's necessary to create the complete sheet via vb.net and send the
sheet or xls to the client, I need a good and clean example, which simply
fills one cell and sends the generated data via response to the client.
because the solutions from your google post didn't work for me.
 
G

Guest

thank you, this was exactly what I was looking for. Damn, I googled so long
just for a simple Style.
Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top