<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello,</p>
<p>there is two problems here</p>
<p>1/ the api of python does not seem to let me use
com.sun.star.script.Converter</p>
<p>2/ the main problem is to insert html content in odt keeping the
format so convert to string won't do it</p>
<p>sorry<br>
</p>
<div class="moz-cite-prefix">Le 27/03/2023 à 13:15, sos a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:f2aef3e9-ff34-a7ea-3045-0e646a27a4df@pmg.be">We do it
with the functions below
<br>
<br>
Function ClipboardAsText As String
<br>
Dim oClip As Variant, oClipContents As Variant, oTypes As Variant
<br>
Dim oConverter, convertedString As String
<br>
Dim i As Integer, iPlainLoc As Integer
<br>
iPlainLoc = -1
<br>
oClip =
createUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
<br>
oConverter = createUnoService("com.sun.star.script.Converter")
<br>
oClipContents = oClip.getContents()
<br>
oTypes = oClipContents.getTransferDataFlavors()
<br>
Dim msg As String
<br>
msg = "Sorry no usefull text in the ClipBoard found"
<br>
For i=LBound(oTypes) To UBound(oTypes)
<br>
If oTypes(i).MimeType = "text/plain;charset=utf-16" Then
<br>
iPlainLoc = i
<br>
Exit For
<br>
End If
<br>
Next i
<br>
If iPlainLoc >= 0 Then
<br>
convertedString =
oConverter.convertToSimpleType(oClipContents.getTransferData(oTypes(iPlainLoc)),
com.sun.star.uno.TypeClass.STRING)
<br>
ClipboardAsText=convertedString
<br>
End If
<br>
End Function
<br>
<br>
Sub CopyToClipBoard( sText )
<br>
' create SystemClipboard instance
<br>
oClip = CreateUnoService( _
<br>
"com.sun.star.datatransfer.clipboard.SystemClipboard")
<br>
oTR = createUnoListener("Tr_", _
<br>
"com.sun.star.datatransfer.XTransferable")
<br>
' set data
<br>
oClip.setContents(oTR,Null)
<br>
sTxtCString = sText
<br>
'oClip.flushClipboard() ' does not work
<br>
End Sub
<br>
<br>
Function Tr_getTransferData(aFlavor as
com.sun.star.datatransfer.DataFlavor)
<br>
' wordt pas aangeroepen als we cntrol+V doen intss is sTxtCString
reeds gezet
<br>
If (aFlavor.MimeType = "text/plain;charset=utf-16") Then
<br>
Tr_getTransferData() = sTxtCString
<br>
End If
<br>
End Function
<br>
<br>
Function Tr_getTransferDataFlavors()
<br>
Dim aFlavor As new com.sun.star.datatransfer.DataFlavor
<br>
aFlavor.MimeType = "text/plain;charset=utf-16"
<br>
aFlavor.HumanPresentableName = "Unicode-Text"
<br>
Tr_getTransferDataFlavors() = array(aFlavor)
<br>
End Function
<br>
<br>
Function Tr_isDataFlavorSupported( _
<br>
aFlavor as com.sun.star.datatransfer.DataFlavor) as Boolean
<br>
If aFlavor.MimeType = "text/plain;charset=utf-16" Then
<br>
Tr_isDataFlavorSupported = true
<br>
Else
<br>
Tr_isDataFlavorSupported = false
<br>
End If
<br>
End Function
<br>
<br>
hope it helps
<br>
<br>
Fernand
<br>
<br>
On 26/03/2023 22:26, Zorg wrote:
<br>
<blockquote type="cite">
<br>
Thanks
<br>
<br>
Ok it seem a goot way
<br>
<br>
maybe it is obvious but how can i paste the clipboard in my odt
without using dispatch
<br>
<br>
<br>
<br>
Le 26/03/2023 à 21:20, Caolán McNamara a écrit :
<br>
<blockquote type="cite">On Sun, 2023-03-26 at 12:06 +0200, Zorg
wrote:
<br>
<blockquote type="cite">... We have try using XTransferable
but without any success.
<br>
</blockquote>
I think it should be possible in headless mode to use the
clipboard
<br>
apis to copy and paste within LibreOffice. But in this case
the
<br>
clipboard is basically a fake clipboard only for the headless
<br>
libreoffice instance, one which doesn't interact with any real
system
<br>
clipboard.
<br>
<br>
So for example in your current code I see that
copy_with_format copies
<br>
into a true X clipboard via xclip so in headless more we can't
paste
<br>
from there and it has to be non headless to get that to work.
<br>
<br>
But if the LibreOffice apis to put something into the
clipboard are
<br>
used then I think it should work to "Paste" within LibreOffice
and get
<br>
that content back out, even in headless more.
<br>
<br>
f.e. in this example at
<br>
<a class="moz-txt-link-freetext" href="https://ask.libreoffice.org/t/is-there-any-way-to-copy-calc-cell-content-and-paste-something-else/32173/11">https://ask.libreoffice.org/t/is-there-any-way-to-copy-calc-cell-content-and-paste-something-else/32173/11</a>
<br>
there is:
<br>
<br>
oClip =
<br>
ctx.getServiceManager().createInstanceWithContext("com.sun.star.datatra
<br>
nsfer.clipboard.SystemClipboard", ctx)
<br>
oClip.setContents(transferable, None)
<br>
<br>
where "transferable" is implemented in that example as
something that
<br>
only supports "text/plain;charset=utf-16" so if you change
<br>
copy_with_format to something that follow the model of the
above
<br>
example implementation of an XTransferable to set a
transferable that
<br>
provides the data and its mimetype as text/html I would expect
it to
<br>
work.
<br>
<br>
</blockquote>
</blockquote>
</blockquote>
<div id="grammalecte_menu_main_button_shadow_host" style="width:
0px; height: 0px;"></div>
</body>
</html>