I would like to paste from Excel to a cell in CALC using the system clipboard (in code). I want to use the HTML Format DataFlavor so that cell attributes are preserved.
I have the necessarry components to get the data from the clipboard:
Code: Select all
// query for the interface XClipboard from the Clipboard service
XClipboard xClipboard = (XClipboard) UnoRuntime.queryInterface(XClipboard.class, oClipboard);
//Get the transferable
XTransferable xTransferable = xClipboard.getContents();
//Get the DataFlavor I want: "HTML Format"
DataFlavor[] dataFlavors = xTransferable.getTransferDataFlavors();
DataFlavor selectedFlavor=null;
for (DataFlavor dataFlavor: dataFlavors) {
if (dataFlavor.HumanPresentableName.equals("HTML Format")) {
selectedFlavor=dataFlavor;
break;
}
}
//Get the data matching my selected DataFlavor- can print this out, so I know it is correct
Object data = xTransferable.getTransferData(selectedFlavor)
//Where do I go from here ???
Nothing about actually pasting it into cells - while preserving attributes.
Any help appreciated - thanks.