HOWTO: Server-Side Spell Checking Using Microsoft Word and ASPID: Q214545
|
This article demonstrates how you can use Microsoft Word to add spelling check functionality to your Web pages using ASP.
Follow the steps below to build the ASP application:
<!-- Page header -->
<p><center><font size=+4 color=red>Spelling Results</font></center><hr>
<!-- Show user the text they entered -->
<p>The text you entered was:<p>
<font color=blue><%=Request("TEXTAREA1")%></font><p><hr><p>
<!-- Begin server-side script to check spelling errors -->
<%
' Don't allow other sessions to re-enter :)
do while(Application("WordInUse") = 1)
loop
Application("WordInUse") = 1
' Get Word references created in global.asa.
dim wdApp
set wdApp = Application("WordApp")
dim wdDoc
set wdDoc = Application("WordDoc")
' Clear current contents.
dim wdRange
set wdRange = wdApp.Selection.Range
wdRange.WholeStory
wdRange.Delete
set wdRange = Nothing
' Add the text the web user entered.
dim txt
txt = Request("TEXTAREA1")
wdApp.Selection.TypeText CStr(txt)
' Check spelling without prompting.
'wdDoc.CheckSpelling , , 0
' Get spelling errors collection.
dim wdErrors
set wdErrors = wdDoc.SpellingErrors
%>
<% ' Handle no-error condition.
if wdErrors.Count = 0 then
%>
There were no spelling errors.
<%
' Otherwise build a table of suggestions.
else
%>
<!-- Build a table to show errors & suggestions -->
<font color=red>There were <%=wdErrors.Count%> spelling error(s).</font><p>
<TABLE border=1 cellPadding=1 cellSpacing=1 width=75%>
<TR>
<TD><b><font size=+1>Word</font></b></TD>
<TD><b><font size=+1>Suggestions</font></b></TD></TR>
<%
for each wdError in wdErrors
' Write the word in question.
Response.Write("<TR><TD>")
Response.Write(wdError.Text)
Response.Write("</TD><TD>")
' Get spelling suggestions for it.
dim wdSuggestions
set wdSuggestions = wdApp.GetSpellingSuggestions(wdError.Text)
if wdSuggestions.Count <> 0 then
' a comma-separated list of suggestions.
dim strSuggestions
strSuggestions = ", "
for each wdSuggestion in wdSuggestions
strSuggestions = strSuggestions & wdSuggestion.Name & ", "
next
' Remove extra comma & space.
strSuggestions = Right(strSuggestions, len(strSuggestions)-2)
' Write out suggestions.
Response.Write(strSuggestions)
else
Response.Write("None.")
end if
set wdSuggestions = Nothing
Response.Write("</TD></TR>")
next
end if
' Release references.
set wdErrors = nothing
set wdDoc = nothing
set wdApp = nothing
' We're done, allow other sessions to continue.
Application("WordInUse") = 0
%>
Sub Application_OnStart()
' Launch Word.
dim wdApp
set wdApp = CreateObject("Word.Application")
set Application("WordApp") = wdApp
' Add a document.
set Application("WordDoc") = wdApp.Documents.Add
' Release reference.
set wdApp = nothing
End Sub
Sub Application_OnEnd()
' Get Automation references.
dim wdApp
set wdApp = Application("WordApp")
dim wdDoc
set wdDoc = Application("WordDoc")
' Tell Word to shutdown.
wdDoc.Saved = true
wdApp.Quit
' Release references.
set Application("WordDoc") = Nothing
set Application("WordApp") = Nothing
set wdDoc = nothing
set wdApp = nothing
End Sub
net stop w3svc
net start w3svc
Additional query words: getspellingsuggestions iis pws grammar
Keywords : kbole kbASP kbASPObj kbAutomation kbInternet kbVBScript kbVisID kbWord kbGrpDSO kbInetDev
Version : WINDOWS:6.0,97; winnt:4.0
Platform : WINDOWS winnt
Issue type : kbhowto
Last Reviewed: June 16, 1999