Introduction

There are a few articles, including some from Microsoft, explaining how to use Microsoft Office’s spellchecker in other applications through automation and .NET. However, the Microsoft Office suite is expensive, so here is a method using the spellchecker in OpenOffice 2.3.0. Microsoft Office provides a dialog box, but OpenOffice doesn't, so we have to make our own. Not a problem. This example is written with Visual C# 2008 Express.

Using the Code

The finished program won't start unless OpenOffice is installed on the target machine. The LoadSpellChecker() function does what’s necessary to load the modules into memory. mxSpell is a class member of type XSpellChecker.

In the spellchecking function, the Regex breaks the text in the TextBox into words for checking, and each word is fed in turn into XSpellChecker.spell(). This returns null if there is no alternative spelling suggestion - we take that to mean a correctly spelt word. Otherwise it returns a list of possible alternatives.

These alternatives are loaded into the ListBox in SpellCheckDlg, so that the user can decide what to do: replace the word, ignore the correction or quit the spellchecker - according to what is returned by the dialog. nCorrections keeps a count of corrections made, and this is subsequently displayed in the Label msg.

Points of Interest

It is not necessary to use the OpenOffice SDK in order to compile, but if you want to read the DevelopersGuide.pdf, you'll probably have to download the SDK. You'll need references in Visual Studio to the following DLLs:

I referenced all the dlls in 3.0 and it compiles, but I get a System.Runtime.InteropServices.SEHException when it runs. The line of code that is causing it is, "XComponentContext context = uno.util.Bootstrap.bootstrap();". When I capture the exception, it gives me a message, "External component has thrown an exception."