-2

I'm trying to create a rudimentary glossary macro for a LibreOffice/OpenOffice .odt file. It will go to the end of the document and paste a list of selected words(found by regex) as a unique set (no doubles)

Where I'm falling down is that once the text has been copied to the clipboard, I need to assign the contents to a variable so that I can create a set.

In OpenOffice's implementation of BASIC, how does one assign the contents of the clipboard to a new variable?

To be clear: I don't need the Paste function, I need to manipulate the contents of the clipboard as an Object before calling Paste

A rough draft of what I'm trying to do is:

dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())

rem -------------- PROBLEM IS BELOW -------
Dim oModuleUICommandDescription As Object, myText$(),aCommand
myText = thisComponent.currentSelection(0)

rem -------------- PROBLEM IS ABOVE -------

rem -------------- Followed by an array comparison to get a unique set

i = FreeFile()
Open "/path/to/my/BASIC.txt" For Output As i
Print #i, myText.string
Close #i
  • 1
    Did you google: *OpenOffice BASIC, assign the contents of the clipboard* One of the results: https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=93562 You really need to learn to google! – StureS Apr 28 '21 at 14:24
  • Hello, yes, I had Googled it and I had read that very result. However, as far as I can see, it doesn't do at all what I'm asking, which is to assign the result of Copy to a variable. What you've posted, executes Copy and the execute Paste, but before that, I need to assign to a variable, apply an operation and output it to a text file, rather than Paste – user14050185 May 19 '21 at 15:04
  • Then you need to continue your research. This is not a programming service where you state your requirements and debugged ready-to-use code is returned. You need to put in the efforts required yourself. – StureS May 19 '21 at 15:46
  • Where did I ask for a full piece of ready-to-use code? If you took the time to read my question, you would see I'm asking for a single operation that I can't determine how to do or if it's possible. If you took the time to read the Google result you posted, you would see that that it doesn't contain the operation I'm searching for. If you can see the line which does that, please feel free to enlighten me and I'll upvote the answer.Here is an example of you answering a similar request usefully https://stackoverflow.com/questions/65578682/how-to-find-the-lenght-of-the-word-in-c/65578890#65578890 – user14050185 May 20 '21 at 19:07
  • It took me 10 seconds to find a solution in Google with *paste clipboard to variable openOffice* – StureS May 21 '21 at 06:27
  • If you're talking about the link you posted, that's not a solution. You clearly either haven't understood the question or just don't know how to do it. – user14050185 May 21 '21 at 09:34
  • A pity you weren't bothered to show any result StureS, might have saved me a few days' effort. – user14050185 May 21 '21 at 11:55

1 Answers1

0

So, as far as I can see the answer is that there isn't a simple built-in way to do this.

However, it is possible by using a custom created function posted here(not mine) https://wiki.documentfoundation.org/Macros/Writer/005

and using that function to assign contents to the variable.

The upper sub here relies on the function defined below it.

Sub WriteClipboardtoTxtFile()
    Dim sText As String
    Dim myTextFile As String
    Dim i%
    findAllTags_Switches()
    rem  ###########     ASSIGNMENT OCCURS JUST BELOW
    sText= (getClipboardText)
    rem ################ ASSIGNMENT OCCURS JUST ABOVE
    sText = Replace (sText," ",Chr(10))
    rem Replace white spaces with returns
    MsgBox(sText)
    i = FreeFile()
    Open "/path/to/my/file" For Output As i
    Print #i, sText
    Close #i
    
    
End Sub ' InsertClipboardTexttoVariable


Function getClipboardText() As String
    '''Returns a string of the current clipboard text'''

    Dim oClip As Object ' com.sun.star.datatransfer.clipboard.SystemClipboard
    Dim oConverter As Object ' com.sun.star.script.Converter
    Dim oClipContents As Object
    Dim oTypes As Object
    Dim i%

    oClip = createUnoService("com.sun.star.datatransfer.clipboard.SystemClipboard")
    oConverter = createUnoService("com.sun.star.script.Converter")
    On Error Resume Next
    oClipContents = oClip.getContents
    oTypes = oClipContents.getTransferDataFlavors

    For i = LBound(oTypes) To UBound(oTypes)
        If oTypes(i).MimeType = "text/plain;charset=utf-16" Then
            Exit For
        End If
    Next

    If (i >= 0) Then
        On Error Resume Next
        getClipboardText = oConverter.convertToSimpleType _
            (oClipContents.getTransferData(oTypes(i)), com.sun.star.uno.TypeClass.STRING)
    End If

End Function ' getClipboardText

To use in the OpenOffice macro editors, copy and paste the code in so that the new function can be called.