btaylor507
btaylor507

Reputation: 211

Copy excel formatted data to clipboard from web

I'm looking to provide a button on my page, that when clicked, would copy (excel formatted) data to the users clipboard and they are able to paste in excel with values separated by columms. Is this possible, maybe jquery? I have a understanding and experience with OOP.

Any help would be great.

Upvotes: 5

Views: 2635

Answers (2)

btaylor507
btaylor507

Reputation: 211

function ClipBoard()
{
var tab      = "    ";
var ticket   = $('#Userid').text();
var queue    = $('#queue').text();
var customer = $('#customer').text();
var res      = $('#res').text();

var str      = ticket+tab+queue+tab+customer+tab+res;

$('#holdtext').append(str);
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}

Using Jquery and inserting tabs in-between each var will format for excel. This only works in IE though.

<TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>
<span id="ticket">767-45</span><br />
<span id="queue">john_doe</span><br />
<span id="customer">Citibank</span><br />
<span id="res">jan_doe</span><br />
<BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON> 

Upvotes: 0

MatRt
MatRt

Reputation: 3534

It seems to be difficult to find a simple solution in JS which is cross browser (It is simple for IE but not for other browser), so you can take a look at ZerClipboard which is a good solution using Javascript and Flash.

ZeroClipboard

Upvotes: 3

Related Questions