paste html using API

Caolán McNamara caolanm at redhat.com
Sun Mar 26 19:20:36 UTC 2023


On Sun, 2023-03-26 at 12:06 +0200, Zorg wrote:
> ... We have try using XTransferable but without any success.

I think it should be possible in headless mode to use the clipboard
apis to copy and paste within LibreOffice. But in this case the
clipboard is basically a fake clipboard only for the headless
libreoffice instance, one which doesn't interact with any real system
clipboard.

So for example in your current code I see that copy_with_format copies
into a true X clipboard via xclip so in headless more we can't paste
from there and it has to be non headless to get that to work.

But if the LibreOffice apis to put something into the clipboard are
used then I think it should work to "Paste" within LibreOffice and get
that content back out, even in headless more. 

f.e. in this example at
https://ask.libreoffice.org/t/is-there-any-way-to-copy-calc-cell-content-and-paste-something-else/32173/11
there is:

oClip =
ctx.getServiceManager().createInstanceWithContext("com.sun.star.datatra
nsfer.clipboard.SystemClipboard", ctx)
oClip.setContents(transferable, None)

where "transferable" is implemented in that example as something that
only supports "text/plain;charset=utf-16" so if you change
copy_with_format to something that follow the model of the above
example implementation of an XTransferable to set a transferable that
provides the data and its mimetype as text/html I would expect it to
work.



More information about the LibreOffice mailing list