[Solved] Remove red line words from document

Discuss the word processor
Post Reply
drxssive
Posts: 3
Joined: Tue Jun 19, 2018 2:51 pm

[Solved] Remove red line words from document

Post by drxssive »

Hi guys,

I want to remove red line/incorrect/misspelled words from my OpenOffice document. Can someone guide me how to do this? Is there any Macro I can use? I need to solve this problem as fast as possible so, please answer ASAP :(

Regards
Dr X
Last edited by drxssive on Wed Jun 20, 2018 2:57 am, edited 1 time in total.
OpenOffice 4 on Windows 10
FJCC
Moderator
Posts: 9231
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove red line words from document

Post by FJCC »

The menu Tools -> Spelling and Grammar should do what you want. It will take you to each location of a marked word, where you can accept one of the suggested changes or you can directly type the correct word in the box where the word is shown in red within its context in the document. You can choose to change just the one occurrence of the misspelled word or all of them if you made the same mistake several times.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
drxssive
Posts: 3
Joined: Tue Jun 19, 2018 2:51 pm

Re: Remove red line words from document

Post by drxssive »

Hi,

Ty for your reply. I am not looking to manually do this. I have a document of about 300k words, and it has a lot of misspelled words. I can't do all of this manually. Is there any through which I can do this automatically? I just want to remove those words, not to correct them or replace them.

Regards
Dr X
OpenOffice 4 on Windows 10
FJCC
Moderator
Posts: 9231
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove red line words from document

Post by FJCC »

I don't know of any way to do that other than writing a custom spell check macro, which would take several days of study, at least. Even for a very long document, going through it manually would be faster. I will continue to look around for an answer but I am not hopeful. Spell checking is not usually used to remove words.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
Posts: 9231
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Remove red line words from document

Post by FJCC »

Try this macro, a very slightly modified version of the code here by hubert lambert

Code: Select all

    sub highlight_spell_errors(optional container)
        if ismissing(container) then
            container = thiscomponent
        end if

        ' get text object
        T = container.Text

        ' get text cursor
        cursor = T.createTextCursor()

        ' get spell checker service
        lsm = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
        spellchecker = lsm.getSpellchecker()

        ' bypassing an uno api bug which confuse between XSpellChecker and XSpellChecker1
        reflector = createUnoService("com.sun.star.reflection.CoreReflection")
        xspellchecker = reflector.forName("com.sun.star.linguistic2.XSpellChecker")
        isvalid = xspellchecker.getMethod("isValid")

        ' iterate through all words
        dim props() as new com.sun.star.beans.PropertyValue
        do
            cursor.gotoStartOfWord(False)
            cursor.gotoEndOfWord(True)
            word = cursor.String
            if not isValid.invoke(spellchecker, array(word, cursor.CharLocale, props())) then
                'cursor.CharBackColor = 16776960
                cursor.String = "" ' FJCC
            end if 
            cursor.gotoNextWord(False)
            if cursor.isEndOfParagraph then
                cursor.gotoNextParagraph(False)
            end if
  
        loop while T.compareRegionEnds(T, cursor) <> 0

        ' check sub texts
        frames = container.TextFrames
        for each frame in frames
            on error resume next
            highlight_spell_errors(frame)
        next frame
        tables = container.TextTables
        for n = 0 to tables.Count -1
            table = tables(n)
            cellnames = tables(n).CellNames
            for each cellname in cellnames
                cell = table.getCellByName(cellname)
                highlight_spell_errors(cell)
            next cellname
        next n
    end sub
The document has to end with an empty paragraph or the macro gets stuck in an endless loop. Make a back up copy of the document first!
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
drxssive
Posts: 3
Joined: Tue Jun 19, 2018 2:51 pm

Re: [Solved] Remove red line words from document

Post by drxssive »

Worked perfectly for me. Thank you so much for help, much much appreciated :super:.

Regards
Dr X
OpenOffice 4 on Windows 10
Post Reply