How would you copy multiple rows of data like this <tr><td>cell 1</td><td>cell 2</td></tr> <tr><td>cell 3</td></td>cell 4</td></tr> into user’s clipboard, ready to be pasted in Excel (one <td> pair will go to one cell in Excel)
I have something like this in mind:
$('#copy').click(function(){
var data = $('datatable tr:visible').text();
alert("you have copied these data: " + data + "now you can paste them in Excel");
});
Nothing in data variable in the alert box. Pretty much stuck here..
If you want to paste the data in Excel, you’ll probably need each row in a different line, each column separated by tabs. Example:
Working example at jsFiddle (adapted from OP code)
As for copying to clipboad, see this question for more info.
Update: Copying from browser to clipboard is a complicated and potentially insecure operation, and AFAIK does not work consistently between browsers and operating systems. Maybe it’s better to just drop the text in a
textarea, selected, and request the user toCtrl+Cit. But it’s up to you.