Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you Print the wavy lines generated by Spell check in writer?

As per google group, this macro can be used to print mis-spelled words in MS office.

https://groups.google.com/g/microsoft.public.word.spelling.grammar/c/OiFYPkLAbeU

Is there similar option in libre-office writer?

like image 888
shantanuo Avatar asked Sep 21 '25 10:09

shantanuo


1 Answers

In response to your above comment, it is straightforward to modify the above subroutine to do that instead of drawing wavy lines. The code below opens a new Writer document and writes into it a list of the misspelled words together with the alternatives that the spellchecker suggests:

Sub ListMisSpelledWords

    ' From OOME Listing 315 Page 336
    GlobalScope.BasicLibraries.loadLibrary( "Tools" )
    Dim sLocale As String
    sLocale = GetRegistryKeyContent("org.openoffice.Setup/L10N", FALSE).getByName("ooLocale")

    ' ooLocale appears to return a string that consists of the language and country
    ' seperated by a dash, e.g. en-GB
    Dim nDash As Integer
    nDash = InStr(sLocale, "-")

    Dim aLocale As New com.sun.star.lang.Locale
    aLocale.Language = Left(sLocale, nDash - 1)
    aLocale.Country = Right(sLocale, Len(sLocale) -nDash )

    Dim oSource As Object 
    oSource = ThisComponent

    Dim oSourceCursor As Object
    oSourceCursor = oSource.getText.createTextCursor()
    oSourceCursor.gotoStart(False)
    oSourceCursor.collapseToStart()

    Dim oDestination As Object
    oDestination = StarDesktop.loadComponentFromURL( "private:factory/swriter",  "_blank", 0, Array() )

    Dim oDestinationText as Object
    oDestinationText = oDestination.getText()

    Dim oDestinationCursor As Object
    oDestinationCursor = oDestinationText.createTextCursor()

    Dim oSpeller As Object
    oSpeller = createUnoService("com.sun.star.linguistic2.SpellChecker")

    Dim oSpellAlternatives As Object, emptyArgs() as new com.sun.star.beans.PropertyValue
    Dim sMistake as String, oSpell As Object, sAlternatives() as String, bTest As Boolean, s As String, i as Integer

    Do

        oSourceCursor.gotoEndOfWord(True)
        sMistake = oSourceCursor.getString()

        bTest = oSpeller.isValid(sMistake, aLocale, emptyArgs())

        If Not bTest Then
            oSpell = oSpeller.spell(sMistake, aLocale, emptyArgs())
            sAlternatives = oSpell.getAlternatives()
            s = ""
            for i = LBound(sAlternatives) To Ubound(sAlternatives) - 1
                s = s & sAlternatives(i) & ", "
            Next i
            s = s & sAlternatives(Ubound(sAlternatives))
            oDestinationText.insertString(oDestinationCursor, sMistake & ":  " & s & Chr(13), False)
        End If    

    Loop While oSourceCursor.gotoNextWord(False)

End Sub
like image 128
Howard Rudd Avatar answered Sep 23 '25 20:09

Howard Rudd