copy table to clipboard

Hi, I want to copy all the rows of a table in the clipboard by a menu option, I cretated this method:
Table table = new Table();…
private void copyToClipBoard(Item item) {
String str = new String[item[0]
StringBuffer strb = new StringBuffer();
int arrayLimit = item[0]
.getItemPropertyIds().size() - 1;
for (int i = 0; i < table.getColumnHeaders().length; i++) {
String tab = “\t”;
if (i == arrayLimit) {
tab = System.getProperty(“line.separator”);

  • tab);
    for (int i = 0; i < item.length; i++) {
    int j = 0;
    for (Iterator iterator = item[i]
    .getItemPropertyIds().iterator(); iterator
    .hasNext():wink: {
    String tab = “\t”;
    if (j == arrayLimit) {
    tab = System.getProperty(“line.separator”);
    Object object = (Object);
    = (String) object;
    ).getValue() + tab);
    String script = “clipboardData.setData("Text", "”+strb.toString()+“")”;

I know that I could use java.awt.Toolkit but I use this script because the table must be copied on the client’s side, the problem is that the script doesn’t work for a multi-line string, is there another way to copy multi-line text on client’s side?. I really appreciate any help, thanks

You may need to quote the content better for executing it in JavaScript. For example, you may not have a newline in the middle of a string literal in JavaScript, but you have to use \n (\n at Java level). Also quote characters in the string to be copied to clipboard would probably mess things up, etc.

Also, I think the clipboardData is specific to IE. For wider browser support, you may need a solution that uses Flash for doing the copying. There’s a CopyToClipboard add-on, but it’s reportedly broken.

Hi Marko, you were right. As you can see on my code I had this: tab = System.getProperty(“line.separator”). I changed that for: tab = “\n”, now it works fine, thank you so much for your help.

PD: You also were right about this solution is just for IE and although for the time being I will use this solution, I will search for wider browser support. Thanks again.

looks promising. Would be really cool if integrated with the Vaadin table. There just aren’t enough rainy days for all the fun add-ons we could write.

Hi, the copyToClipboard add-on worked fine for me, now I can access to the system clipboard from my application using IE, FF and Chrome :smiley: