By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,223 Members | 1,371 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,223 IT Pros & Developers. It's quick & easy.

Exporting HTML table to Excel

P: n/a
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()
Mar 20 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"schmidte" <sc******@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
How can I Export an HTML Table to excel?
http://www.google.co.uk/search?hl=en...rt+Excel&meta=
Mar 20 '07 #2

P: n/a
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.

"Mark Rae" wrote:
"schmidte" <sc******@discussions.microsoft.comwrote in message
news:D3**********************************@microsof t.com...
How can I Export an HTML Table to excel?

http://www.google.co.uk/search?hl=en...rt+Excel&meta=
Mar 20 '07 #3

P: n/a
"schmidte" <sc******@discussions.microsoft.comwrote in message
news:A1**********************************@microsof t.com...
because the solutions from your google post didn't work for me.
http://www.codersource.net/published..._to_excel.aspx

Scroll down to the section entitled "Format Issue when Exporting datagrid to
Excel:"
Mar 20 '07 #4

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

"Mark Rae" wrote:
"schmidte" <sc******@discussions.microsoft.comwrote in message
news:A1**********************************@microsof t.com...
because the solutions from your google post didn't work for me.

http://www.codersource.net/published..._to_excel.aspx

Scroll down to the section entitled "Format Issue when Exporting datagrid to
Excel:"
Mar 22 '07 #5

P: n/a
"schmidte" <sc******@discussions.microsoft.comwrote in message
news:80**********************************@microsof t.com...
thank you, this was exactly what I was looking for.
Hurrah!
Thanks a lot.
Welcome.
Mar 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.