日本国产亚洲-日本国产一区-日本国产一区二区三区-日本韩国欧美一区-日本韩国欧美在线-日本韩国欧美在线观看

當前位置:雨林木風下載站 > 技術開發教程 > 詳細頁面

運用ASP與Word進行服務器端拼寫檢查

運用ASP與Word進行服務器端拼寫檢查

更新時間:2022-05-02 文章作者:未知 信息來源:網絡 閱讀次數:

編譯 甘冀平(2000-09-26)

本文討論的問題與下列方面相關:

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>")

   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

%>

10、在Visual InterDev 工程瀏覽窗口中,雙擊Global.asa文件,在< SCRIPT >標記之間添加下面2段子程序:

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

11、最后,在工程瀏覽窗口中用鼠標右鍵單擊CheckSpelling.htm文件,選擇“設置為初始頁面”。

12、從File菜單中選擇“保存所有”(CTRL+SHIFT+S),再從Build菜單中選擇“Build”(Control-Shift+B)。

現在可以進行測試了,在客戶端輸入“http:///WebSpell/CheckSpelling.htm”。

在Web頁面的文本域中輸入一些文字,點擊“Submit”,然后就可以看到results.asp對你輸入的文字報告一些錯誤拼寫和
建議。

工程的工作流程
當用戶首次瀏覽到CheckSpelling.htm頁面時,Application_OnStart()事件被觸發。這個過程啟動Microsoft Word,為拼寫檢查做準備,保存應用和文檔對象到2個ASP應用程序級別的變量中。這使頁面變得很有效率,因為你可以再次調用Word的同一實例,而不是為每一次拼寫檢查要求都執行多次實例。接著,當用戶點擊按鈕Submit時,result.asp頁面通過ASP的Request對象獲取輸入值,然后利用存儲的Microsoft Word對象來執行拼寫檢查。result.asp注意了當多個用戶會話同時使用同一實例時可能發生的問題,如果一個用戶正在使用,就進行調度處理。

注意:一旦一個Web用戶登錄了工程文件,Web服務器就會有一個WinWord.exe進程在后臺運行,它將處理拼寫檢查的請求。當應用程序發生OnEnd()事件時,ASP應用程序才會釋放這個實例,而OnEnd()事件只有當Web服務停止時才被觸發。可以通過運行下列的命令來停止并重新啟動Web服務:

net stop w3svc

net start w3svc


溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

主站蜘蛛池模板: 欧美日韩精品免费一区二区三区 | 国内一区二区三区精品视频 | 美国一级特级毛片片aa视频 | 国产三级精品三级在线观看 | 久久精品视频3 | 国产色婷婷免费视频 | 亚洲视频中文字幕在线 | 亚洲国产欧美在线 | 久久爱成人网 | 欧美v日本| 久久综合伊人 | 可以免费看的欧美性视频 | 国产午夜精品免费一二区 | 国产成人一区二区三区精品久久 | 在线观看视频中文字幕 | 国产精品久久久久久久久久98 | 天天怕天天怕天天怕 | 久本草在线中文字幕亚洲欧美 | 日本久久网 | 一区二区三区舞蹈区 | 色综合天天综合给合国产 | 国产高清视频在线播放 | 天天躁日日躁狠狠躁综合 | 蜜桃视频www在线观看免费视频 | 欧美性巨大 | 四虎伦理| 欧美日在线观看 | 欧美精彩狠狠色丁香婷婷 | 69香蕉视频 | 呦呦视频在线观看 | 亚洲国产精品悠悠久久琪琪 | 久久国产精彩视频 | 国内精品久久久久影院免费 | 蜜桃视频在线播放 | 亚洲欧美一区二区三区久本道 | 在线观看ww | 人久热欧美在线观看量量 | 国内性经典xxxxx | 欧美v日本| 久久久亚洲欧洲日产国码二区 | 2018天天干天天射 |