i want to know whether the clipboard content is excel or word .. pls help m

hi all

i want to copy the content of ms excel sheet (examlpe: i have selected 6 cells as a table) and i want to paste the same in JTextPane, but i dont know how to do this, i tried much but not got anything.

excel mime type is not supported by dataflavor so pls can anyone tell me how to achieve this ?

and i dont want to use RTF mime type.

pls thanks in advance

darshan

[407 byte] By [darshangajjara] at [2007-10-2 20:27:23]
# 1
I've just checked that you can copy&paste Excel cells into Notepad. This suggests that the clipboard must contain the data in text only format as one of the flavours. So you need to chack all the possible flavours you get offered and pick the plain text one.
armalcolma at 2007-7-13 23:10:17 > top of Java-index,Java Essentials,Java Programming...
# 2

hi

thanks for reply but follow the below mentioned steps:

open excel -> select continuous cells (like table) -> copy

open word -> paste contents

so whatever result u see in the word (after pasting content) the same result should be done while pasting in JTextPane...

pls. waiting for solution

thanks

darshan

darshangajjara at 2007-7-13 23:10:17 > top of Java-index,Java Essentials,Java Programming...
# 3

Are you expecting to see a formatted table? That's what I get when I paste into Word from Excel. I'm not sure how much can be done in that regard.

If you just want to manipulate it, you can do whatever you want with the excel stuff by parsing the results:

String trstring = (String) systemClipboard

.getContents(this).getTransferData(DataFlavor.stringFlavor);

String rowstring;

String value;

// split the string on newlines and on tabs

String[] st1 = trstring.split("\n");

for (int i = 0; i < st1.length; i++) {

rowstring = st1[i];

String[] st2 = rowstring.split("\t");

for (int j = 0; j <st2.length; j++) {

value = st2[j];

// process contents

}

}

>

pthorsona at 2007-7-13 23:10:17 > top of Java-index,Java Essentials,Java Programming...
# 4

thanks for reply

but i want to show the data in tabular formate and i want to know that the clipboard content is from excel before doing any processing..

and the same way if i copy data from word then i want to know the the clipboard contet is from work before pasting..

any help , thanks in advance

darshan

darshangajjara at 2007-7-13 23:10:17 > top of Java-index,Java Essentials,Java Programming...
# 5

Word understands part of the Excel format pasted to the clipboard, but JTextPane only understands strings, so the best you can do is to take the String flavour:

In fact, I think all the available data flavours are text-only, stripped of the formatting, except for the image.

Clipboard clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();

DataFlavor[] dataFlavors=clipboard.getAvailableDataFlavors();

for(DataFlavor dataFlavor : dataFlavors)

{

if(dataFlavor==DataFlavor.stringFlavor)

{

try

{

System.out.println(clipboard.getData(dataFlavor));

}

catch (Exception ex)

{

ex.printStackTrace();

}

break;

}

}

armalcolma at 2007-7-13 23:10:17 > top of Java-index,Java Essentials,Java Programming...