-
public string SpellCheck( string strSource)
-
{
-
StringBuilder strResult =
new StringBuilder
( );
-
_Application objWord =
new Microsoft.
Office.
Interop.
Word.
Application ( );
-
ProofreadingErrors objErrors;
-
SpellingSuggestions wdSuggestions;
-
object t = Missing.Value;
-
object nt = Missing.Value;
-
object dt = Missing.Value;
-
object v = true;
-
Document objDocument = objWord.Documents.Add ( ref t, ref nt, ref dt, ref v);
-
objWord.Selection.TypeText (strSource);
-
objErrors = objDocument.SpellingErrors;
-
if (objErrors.Count != 0 )
-
{
-
foreach (Range objError in objErrors)
-
{
-
object cd = Missing.Value;
-
object iu = Missing.Value;
-
object md = Missing.Value;
-
object sm = Missing.Value;
-
object cd2 = Missing.Value;
-
object cd3 = Missing.Value;
-
object cd4 = Missing.Value;
-
object cd5 = Missing.Value;
-
object cd6 = Missing.Value;
-
object cd7 = Missing.Value;
-
object cd8 = Missing.Value;
-
object cd9 = Missing.Value;
-
object cd10 = Missing.Value;
-
wdSuggestions = objWord.GetSpellingSuggestions (objError.Text,
-
ref cd, ref iu, ref md, ref sm, ref cd2, ref cd3, ref cd4,
-
ref cd5, ref cd6, ref cd7, ref cd8, ref cd9, ref cd10);
-
if (wdSuggestions.Count < 1 )
-
{
-
strResult.Append ( "無拼字建議!" );
-
}
-
else
-
{
-
int intCounter = 0;
-
foreach (SpellingSuggestion wdSuggestion in wdSuggestions)
-
{
-
intCounter++;
-
strResult.Append (wdSuggestion.Name );
-
if (intCounter < wdSuggestions.Count )
-
{
-
strResult.Append ( "," );
-
}
-
}
-
}
-
}
-
}
-
else
-
{
-
strResult.Append ( "無拼字錯誤!" );
-
}
-
object sc = 0;
-
object of = Missing.Value;
-
object rd = Missing.Value;
-
objWord.Quit ( ref sc, ref of, ref rd);
-
objErrors = null;
-
wdSuggestions = null;
-
objDocument = null;
-
objWord = null;
-
return strResult.ToString ( );
-
}