word|伺服器 本文討論的問題與下列方面相關:
Microsoft Word 97 for Windows
Microsoft Visual InterDev, version 6.0
Microsoft Internet Information Server version 4.0
概要
本文描述了如何使用Microsoft Word在Web頁面ASP檔案中添加拼字檢查功能。
詳細的步驟
按照下列步驟建立ASP應用程式:
1、在Web伺服器所在機器上,啟動Microsoft Visual Interdev 6.0,選擇File/New Project。
2、在“新工程”對話方塊的名字編輯域中,輸入“WebSpell”,然後雙擊新Web工程表徵圖。
3、在接著出現的Web工程嚮導對話方塊中,輸入或者選擇你的Web伺服器名字。將工作模式預設為Master,點擊Next,再點擊
“finish”。
4、在Visual InterDev建立工程完成後,開啟工程菜單,選擇“添加Web Item\HTML頁面”,命名為“CheckSpelling”,
然後點擊Open。
5、添加的HTML頁面預設狀態下以設計檢視開啟。在頁面上拖出一個HTML文本地區,放置一個HTML提交按鈕,根據你的愛好
進行布局,在頁面上輸入一些文字,告訴使用者在文本域中輸入需要進行拼字檢查的文字。
6、選擇頁面上的所有對象(CTRL+A),然後從Visual InterDev的 HTML菜單中選擇Form,將對象包裹在表單中。
7、點擊當前視窗底部的源碼功能頁面,切換到源碼顯示視圖。修改HTML開放< FORM >標記的action屬性值為
results.asp。
8、開啟Project菜單,選擇“添加Web Item\Active Server Page”,命名為“results”,然後點擊“Open”。
9、對於新頁面,切換到源碼視圖,在<BODY>標記之間輸入下面的代碼:
<!-- 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>")