-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkSpelling.m
27 lines (26 loc) · 1.05 KB
/
checkSpelling.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function suggestion = checkSpelling(word)
%CHECKSPELLING uses MSWord to correct spelling
% CHECKSPELLING(WORD) checks the spelling of WORD and returns spelling
% suggestions as a cell array. If WORD is spelled correctly, CHECKSPELLING
% will return empty brackets. If no suggestions are found. CHECKSPELLING
% returns 'no suggestions'.
%Start the Word ActiveX Server and check the spelling of WORD
h = actxserver('word.application');
h.Document.Add;
correct = h.CheckSpelling(word);
if correct
suggestion = []; %return empty if spelled correctly
else
%If incorrect and there are suggestions, return them in a cell array
if h.GetSpellingSuggestions(word).count > 0
count = h.GetSpellingSuggestions(word).count;
for i = 1:count
suggestion{i} = h.GetSpellingSuggestions(word).Item(i).get('name');
end
else
%If incorrect but there are no suggestions, return this:
suggestion = 'no suggestions';
end
end
%Quit Word to release the server
h.Quit