-2

I have a asp.net web page that has various pieces of data on it. One of those is a standard html table. 10 columns by 5 rows. I want to place a link below the table that allows the user to click on it and it will export the data from the table into an excel sheet.

Can anyone help?

Silentbob
  • 2,805
  • 7
  • 38
  • 70
  • 1
    have you tried anything? raed anything? – Luis Tellez Feb 21 '13 at 16:22
  • yes I have for the past few hours but not getting anywhere at all. – Silentbob Feb 21 '13 at 16:38
  • 1
    You are not likely to get an answer if you just say hey i need this, how can i do it. you have to show what is not working and what have you tried. – Luis Tellez Feb 21 '13 at 16:40
  • What have you tried so far? After all, you should be able to point Excel at the webpage and it can suck the data in itself, which might be a simpler solution than generating an XLSX file on the fly – Rowland Shaw Feb 21 '13 at 16:41

2 Answers2

1

im just going to put some articles you can use or other answers but googling html table to excel you can find some answers.

html table to excel using jquery How to export html table to excel using javascript

Community
  • 1
  • 1
Luis Tellez
  • 2,785
  • 1
  • 20
  • 28
  • thanks for at least attempting to assist me, I have googled the issue but I will explore your links. As you can see from my account I am very new here so apologies if my post annoys you but I have to say you dont instill confidence in the site if you mark down a post from a new member so quickly. My experience so far of most forums towards noobs is awful. I understand we need educating on how best to post etc but at least give us a grace period. ill probably get banned or at least marked down for this. – Silentbob Feb 21 '13 at 16:51
  • The expectation on this site is that you have already tried a few things and you are stuck. Most users on SO, who have been here for a while will seem a little irritated if you ask an open-ended question that makes it sound like you haven't even tried and you think this is goog or something. There are lots of good questions/answers already posted here. You just need to persevere a little more and you will find an answer pretty easily. Hang in there user2050577. – tgolisch Feb 21 '13 at 16:54
  • i didn't downvote i just pointed you that it was not a good question and that you have to try before comming here for an answer. – Luis Tellez Feb 21 '13 at 16:59
1

If you are wanting to export the data i am presuming that the data is dynamic, from a database? On that assumption why not display the data in either a GridView or an ASP table? This way you will be better able to export the data.

If you are dynamically creating the table from code then i guess thats different, but you havent stated how your generating the page.

Exporting Controls to excel: Just change Gridview1 to the id of the control you want to export. Either your ASP table or your gridview ID.

 Dim sw As New StringWriter()
    Dim hw As New System.Web.UI.HtmlTextWriter(sw)
    Dim frm As HtmlForm = New HtmlForm()

    Page.Response.AddHeader("content-disposition", "attachment;filename=ExportFromWebPage.xls")
    Page.Response.ContentType = "application/vnd.ms-excel"
    Page.Response.Charset = ""
    Page.EnableViewState = False
    frm.Attributes("runat") = "server"
    Controls.Add(frm)
    frm.Controls.Add(GridView1)
    frm.RenderControl(hw)
    Response.Write(sw.ToString())
    Response.End()

-Edit. Ive shown my naivety here and just assumed this wouldn't work with a native html table. I thought id try it and it actually will work. Just run your table at server and give it an ID then replace gridview1 with the id you've given your HTML table.

Neil Watson
  • 2,801
  • 3
  • 18
  • 20