使用ASP和Word進行伺服器端拼字檢查

來源:互聯網
上載者:User
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>")



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.