Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy HTML Table to Clipboard

Status
Not open for further replies.

MadJock

Programmer
May 25, 2001
318
GB
Hi,

I'm trying to copy the contents of an HTML table to the clipboard in such a manner that it can be pasted into Excel, preserving rows and columns. At the moment, it's just one big lump of text.

I've had a good search of this site and google (where I got the copy to clipboard from) but have not turned up anything table related.

Here's my code to date (working except not in table format):

Code:
			function ClipBoard() 
            {
                var rowcount = document.getElementById('grdResults').rows.length;
                var copy = '';
                for(var i = 0; i< rowcount; i++){
                    copy += document.getElementById('grdResults').rows[i].innerHtml;
                }
                window.clipboardData.setData('Text', copy);
            }

I can guarantee that the browsers using my page will be IE6 or above.

Any help much appreciated!

Thanks,

Graeme

"Just beacuse you're paranoid, don't mean they're not after you
 
Sorry, solved this myself (didn't include Tek-Tips FAQ in search).

For anyone interested code becomes:

Code:
function Clipboard(){
 var textRange = document.body.createTextRange();
 textRange.moveToElementText(grdResults);
 textRange.execCommand("Copy");
}

"Just beacuse you're paranoid, don't mean they're not after you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top