Exporting HTML table to Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?c2NobWlkdGU=?=

    #1

    Exporting HTML table to Excel

    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.Strin gWriter = New System.IO.Strin gWriter
    Dim hw As System.Web.UI.H tmlTextWriter = New HtmlTextWriter( sw)
    Dim str_temp As String = "attachment;fil ename=dtsReport _" &
    System.DateTime .Today.Month & "-" & System.DateTime .Today.Day & "-" &
    System.DateTime .Today.Year & ".xls"
    Response.Clear( )
    Response.AddHea der("content-disposition", str_temp)
    Response.Conten tType = "applicatio n/ms-excel"

    tbl_temp.Render Control(hw)
    Response.Write( sw.ToString())
    Response.End()
  • Mark Rae

    #2
    Re: Exporting HTML table to Excel

    "schmidte" <schmidte@discu ssions.microsof t.comwrote in message
    news:D37EA29B-4153-4D93-AAED-E8C2118FD446@mi crosoft.com...
    How can I Export an HTML Table to excel?



    Comment

    • =?Utf-8?B?c2NobWlkdGU=?=

      #3
      Re: Exporting HTML table to Excel

      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" <schmidte@discu ssions.microsof t.comwrote in message
      news:D37EA29B-4153-4D93-AAED-E8C2118FD446@mi crosoft.com...
      >
      How can I Export an HTML Table to excel?
      >

      >
      >
      >

      Comment

      • Mark Rae

        #4
        Re: Exporting HTML table to Excel

        "schmidte" <schmidte@discu ssions.microsof t.comwrote in message
        news:A1093077-B76A-4346-96FA-7A0F7FEE619C@mi crosoft.com...
        because the solutions from your google post didn't work for me.


        Scroll down to the section entitled "Format Issue when Exporting datagrid to
        Excel:"


        Comment

        • =?Utf-8?B?c2NobWlkdGU=?=

          #5
          Re: Exporting HTML table to Excel

          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" <schmidte@discu ssions.microsof t.comwrote in message
          news:A1093077-B76A-4346-96FA-7A0F7FEE619C@mi crosoft.com...
          >
          because the solutions from your google post didn't work for me.
          >

          >
          Scroll down to the section entitled "Format Issue when Exporting datagrid to
          Excel:"
          >
          >
          >

          Comment

          • Mark Rae

            #6
            Re: Exporting HTML table to Excel

            "schmidte" <schmidte@discu ssions.microsof t.comwrote in message
            news:808BC8BB-255E-4A84-B3D9-907413870C8D@mi crosoft.com...
            thank you, this was exactly what I was looking for.
            Hurrah!
            Thanks a lot.
            Welcome.


            Comment

            Working...