Using Spellchecker

From Apache OpenOffice Wiki
Jump to: navigation, search

The interface used for spell checking is Accessing the spell checker through the LinguServiceManager and initializing the mxSpell object is done by:

  /** Get the SpellChecker to be used.
  public boolean GetSpell()
      if (mxLinguSvcMgr != null)
          mxSpell = mxLinguSvcMgr.getSpellChecker();
      return mxSpell != null;

Relevant properties

The properties of the LinguProperties service evaluated by the spell checker are:

Spell-checking Properties of Description
IsIgnoreControlCharacters Defines if control characters should be ignored or not.
IsUseDictionaryList Defines if the dictionary-list should be used or not.
IsGermanPreReform Defines if the new German spelling rules should be used for German language text or not.
IsSpellUpperCase Defines if words with only uppercase letters should be subject to spellchecking or not.
IsSpellWithDigits Defines if words containing digits or numbers should be subject to spellchecking or not.
IsSpellCapitalization Defines if the capitalization of words should be checked or not.

Changing the values of these properties in the LinguProperties affect all subsequent calls to the spell checker. Instantiate a instance and change it by calling The changes affect the whole office unless another modifies the properties again. This is done implicitly when changing the linguistic settings through Tools - Options - Language Settings - Writing Aids.

The following example shows verifying single words:

  // test with correct word
  String aWord = "horseback";
  boolean bIsCorrect = mxSpell.isValid( aWord, aLocale, aEmptyProps );
  System.out.println( aWord + ": " + bIsCorrect );
  // test with incorrect word
  aWord = "course";
  bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps );
  System.out.println( aWord + ": " + bIsCorrect );

The following example shows spelling a single word and retrieving possible corrections:

  aWord = "house";
  XSpellAlternatives xAlt = mxSpell.spell( aWord, aLocale, aEmptyProps );
  if (xAlt == null)
      System.out.println( aWord + " is correct." );
      System.out.println( aWord + " is not correct. A list of proposals follows." );
      String[] aAlternatives = xAlt.getAlternatives();
      if (aAlternatives.length == 0)
          System.out.println( "no proposal found." );
          for (int i = 0; i < aAlternatives.length; ++i)
              System.out.println( aAlternatives[i] );

For a description of the return types interface, refer to

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages