July 3, 2007

Export an HTML Table to Excel or Word

Is there a simple way to export a table found on a web page to Excel? Yes, the instructions below will provide a simple way to export an HTML table to Excel or Word with a single line of code.


Here’s an example of a simple html table:


Copy the table code into Notepad
Then insert one of the following lines of script at the beginning of your Notepad file:

Response.ContentType = "application/vnd.ms-excel" [if you plan to use Excel]
Response.ContentType = "application/vnd.ms-word" [if you plan to use Word]

Excel Example:

Response.ContentType = "application/vnd.ms-excel"

Save it as an .asp file (i.e., example.asp)
Open Excel and then open the *.asp file.

Here’s what the .asp file looks like in Excel:


You can now edit the file as you desire; save as an Excel file.

To export the table into Word, insert the word script at the beginning of the Notepad file (above the table code), save as an .asp file, and open in Word.

No comments: