[Last Call] Learn how to a build a cloud-first strategyRegister Now


Copy table to clipboard

Posted on 2004-11-04
Medium Priority
Last Modified: 2008-01-09
Hi all,

I have a page with html table in it.

I want to add a button that will select and copy the table to the clipboard,

How can I do that?
Question by:kobi_ab
  • 2
  • 2

Accepted Solution

eyeh8u earned 500 total points
ID: 12493913
This will work in IE:
window.clipboardData.setData("Text", document.all['tableid'].innerHTML);

ASsuming you want to copy the HTML of the table. To include the table tag I would do:

<div id="tableid">

Then the <table>...</table> part will be copied to the clipboard.

To be cross-browser, you need to look at something like this: http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20233392.html and combine the two techniques.

Author Comment

ID: 12493996
Hi eyeh8u and all

I want to paste the table in Excel, so i need the data in a table format and not the html

Expert Comment

ID: 12494060
Today, Microsoft are smiling on you.


Select that text (with your mouse cursor, manualy, no javascript magic for you here)

And paste it into a new Excel spreadsheet. Excel natively understands HTML and imports that into four clean cells in the document.

SO the javascript would allow you to select the table into your clipboard automagicaly, then you will have the <table>..</table> in your clipboard, paste it into Excel and bob is your mother's brother.

Author Comment

ID: 12494172
Thanks alot eyeh8u

It works perfectly

By the way my mother's brother name is not Bob :-)

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question