Exporting HTML table to Excel

Discussion in 'ASP .Net' started by =?Utf-8?B?c2NobWlkdGU=?=, Mar 20, 2007.

  1. 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()
     
    =?Utf-8?B?c2NobWlkdGU=?=, Mar 20, 2007
    #1
    1. Advertising

  2. =?Utf-8?B?c2NobWlkdGU=?=

    Mark Rae Guest

    Mark Rae, Mar 20, 2007
    #2
    1. Advertising

  3. 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" <> wrote in message
    > news:D...
    >
    > > How can I Export an HTML Table to excel?

    >
    > http://www.google.co.uk/search?hl=en&rls=GGLG,GGLG:2006-28,GGLG:en&q=ASP.NET export Excel&meta=
    >
    >
    >
     
    =?Utf-8?B?c2NobWlkdGU=?=, Mar 20, 2007
    #3
  4. =?Utf-8?B?c2NobWlkdGU=?=

    Mark Rae Guest

    Mark Rae, Mar 20, 2007
    #4
  5. 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" <> wrote in message
    > news:...
    >
    > > because the solutions from your google post didn't work for me.

    >
    > http://www.codersource.net/published/view/283/exporting_data_grid_to_excel.aspx
    >
    > Scroll down to the section entitled "Format Issue when Exporting datagrid to
    > Excel:"
    >
    >
    >
     
    =?Utf-8?B?c2NobWlkdGU=?=, Mar 22, 2007
    #5
  6. =?Utf-8?B?c2NobWlkdGU=?=

    Mark Rae Guest

    "schmidte" <> wrote in message
    news:...

    > thank you, this was exactly what I was looking for.


    Hurrah!

    > Thanks a lot.


    Welcome.
     
    Mark Rae, Mar 22, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    1
    Views:
    1,426
    Carl Prothman [MVP]
    Jan 12, 2005
  2. =?Utf-8?B?VGltX2s=?=

    Exporting datagrid to Excel Pivot Table

    =?Utf-8?B?VGltX2s=?=, Jan 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    657
    =?Utf-8?B?VGltX2s=?=
    Jan 26, 2005
  3. Gobi
    Replies:
    8
    Views:
    16,788
    mbalhoot
    May 18, 2011
  4. Doogie
    Replies:
    1
    Views:
    482
    sloan
    Nov 19, 2008
  5. M P

    Exporting HTML Table to Excel?

    M P, Jul 6, 2004, in forum: ASP General
    Replies:
    2
    Views:
    220
    Greg Griffiths
    Jul 18, 2004
Loading...

Share This Page