You could try this:
UPDATE : here is a slightly modified version (also attached)
function wordsChecked = checkWordsSpelling( words )
if ischar( words )
if any( words == ' ' )
words = strsplit( words, ' ' ) ;
else
words = {words} ;
end
end
h = actxserver( 'word.application' ) ;
h.Document.Add ;
words = words(:) ;
nWords = numel( words ) ;
for wId = 1 : nWords
isCorrect = h.CheckSpelling( words{wId,1} ) ;
words{wId,2} = isCorrect ;
if isCorrect
words{wId,3} = false ;
continue ;
end
nSug = h.GetSpellingSuggestions( words{wId,1} ).count;
words{wId,3} = nSug > 0 ;
if nSug > 0
for sId = 1 : nSug
words{wId,4}{sId} = ...
h.GetSpellingSuggestions( words{wId,1} ).Item(sId).get( 'name' ) ;
end
end
end
h.Quit
wordsChecked = cell2table( words, 'VariableNames', {'original', 'isCorrect', 'hasSuggestion', 'suggestion'} ) ;
end
With that, you can do the following:
>> checked = checkWordsSpelling( 'Helloo' )
checked =
original isCorrect hasSuggestion suggestion
________ _________ _____________ _______________________________
'Helloo' false true 'Hello' 'Halloo' 'Hellos'
>> checked = checkWordsSpelling( 'Helloo Wolrd Hello' )
checked =
original isCorrect hasSuggestion suggestion
________ _________ _____________ __________
'Helloo' false true {1x3 cell}
'Wolrd' false true {1x2 cell}
'Hello' true false []
>> checked.suggestion{2}
ans =
'World' 'Word'
>> checked = checkWordsSpelling( {'Helloo', 'Wolrd'} )
checked =
original isCorrect hasSuggestion suggestion
________ _________ _____________ __________
'Helloo' false true {1x3 cell}
'Wolrd' false true {1x2 cell}
Hope it helps!
Best Answer