Copy table to clipboard

Posted on 2004-11-04
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
    LVL 5

    Accepted Solution

    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.

    Author Comment

    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
    LVL 5

    Expert Comment

    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

    Thanks alot eyeh8u

    It works perfectly

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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
    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…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now