Copy table to clipboard

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?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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: and combine the two techniques.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kobi_abAuthor Commented:
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
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.
kobi_abAuthor Commented:
Thanks alot eyeh8u

It works perfectly

By the way my mother's brother name is not Bob :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.