ASP教程之用ASP创立Word文件
强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。word|创立|wordUsingActiveServerPagestoBuildMicrosoftWordDocumentsByGardinerB.Jones
Background
BuildDoc.aspisanActiveServerPage(ASP)thatreadstheoutputofa
Webpageform,andcreatesasoutputaMicrosoftWorddocumentcontai
ningatableofchangeddatawithintheform.Formsarenolongerlimi
tedtocontainingstaticinformation.Withdatabaseconnectivity,the
increasinguseofDynamicHTML(DHTML),andthegrowinginterestinXM
L,ithasbecomecommonpracticeinbusinessWebpagesforthedataco
ntainedinthemtobedynamic.Thatis,whatisshownintheformmay
changebasedonuserinteraction(seethesampleinputformbelow).
ThebusinessneedfilledbyBuildDocistoenablesalesassociatesto
createformlettersfromthechangedrecordsofaWebpagetable.Only
thedatamodifiedbythesalespersonissenttoWord,whereitisfo
rmattedintoatable.Obviously,allsamplesherearefictitious.
BuildDocwillreadalloftheinformationontheform,identifyingwhi
chrowshavebeenchanged,andthencreatestheMicrosoftWorddocumen
tusingonlytheinformationcontainedwithinthechangedrows(seeth
esampleoutputdocumentbelow).BuildDocusesatemplatefile(buildD
oc.dot)thatcontainstheaddressheader,andsomepreformattedtext.
Itthenwritesatableintothedocumentthathasarowforeachmodif
iedrowfromtheWebpageform.
HowToDoIt
WestartbyreadingalloftheWebpageformfieldsintohiddenformf
ieldsonthereceivingWebpage.Inthesourcecodebelow,notethe"
onLoad"callinthebodytag.ItcallsthebuildDocVBScriptsubrouti
ne,passingthreeparameterstoit:thecontentsofthepagesform(a
llthehiddenfields),thelocationoftheWordtemplatefile,andthe
numberofrowsreceivedfromtheinputform.Theinputformfieldsar
eallreadandthen,whenthepageloads,itcallsthebuildDocsubrou
tine.Forthesakeofbrevity,wewillassumethatallvariableshave
beenfirstdeclaredbeforeuse.
ThecodefortheloadingoftheinputformfieldsintobuildDoc.aspis
thus:-
<!DOCTYPEHTMLPUBLIC"-//W3C/DTDHTML3.2Final//EN">
<HEAD>
<TITLE>BuildDocument</TITLE>
<METAHTTP-EQUIV="Refresh"CONTENT="30;URL=orderForm.asp">
</HEAD>
<%
dotLocation="servernamedirectory heTemplate.dot"
intRowCount=Request.Form("rowCount")initializearowcounter
%>
<BODYLanguage="VBScript"theForm">
<%
itemCount=0setfieldcountertozero
ForEachIteminRequest.Formcountuptheformfields
itemCount=itemCount+1usingFor..Nextloop
%>
<INPUTTYPE="hidden"NAME="<%=Item%>"VALUE="<%=Request(Item)%>">
<%Next%>
<INPUTTYPE="hidden"NAME="numbRows"VALUE="<%=intRowCount%>">
<INPUTTYPE="hidden"NAME="fieldCount"VALUE="<%=itemCount%>">
</FORM>
</BODY>
</HTML>
WecreateaninstanceoftheWordDocumentobject,usingthesampleco
deimmediatelybelow.NotethatinInternetExplorer4+thiswillfail
unlessthebrowsersecurityissettoLow,orCustomwiththeappropr
iatesettingtorunprograms.
<%
SetobjWordDoc=CreateObject("Word.Document")
ObjWordDoc.Application.Documents.AddtheTemplate,False
ObjWordDoc.Application.Visible=True
%>
Were-dimensionourarraysothatitisthesamesizeasthenumberof
rowsthatarecontainedintheWebpagesform.Inthiscase,weset
theY-axistoaconstantvalueoffourbecausethatisthenumberofc
olumnsweneedintheoutputdocument.TheX-axiscontainsthenumber
ofreceivedrowsfromtheform.
<%
RedimPreservetheArray(4,intTableRows)
%>
Nowwearereadytoexaminealloftheformrows.Wedothisbyloopin
gthroughalltheinputWebpageformfieldstocollecteachformfiel
dnameandcorrespondingvalue.Wetesteachtodeterminewhicharray
elementtoputitinto,andthenweputitthere.TheSELECTCASEstat
ementinthecodesample</p>强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。 学习ASP其实应该上升到如何学习程序设计这种境界,其实学习程序设计又是接受一种编程思想。比如ASP如何学习,你也许在以前的学习中碰到过。以下我仔细给你说几点: 不是很难但是英文要有一点基础网上的教程很少有系统的详细的去买书吧,另不用专门学习vb关于vbscript脚本在asp教材都有介绍 Application:这个存储服务端的数据,如果不清除,会直到web应用程序结束才清除(例如重启站点) 我们必须明确一个大方向,不要只是停留在因为学而去学,我们应有方向应有目标. 虽然ASP也有很多网络教程。但是这些都不系统。都是半路出家,只是从一个例子告诉你怎么用。不会深入讨论,更不会将没有出现在例子里的方法都一一列举出来。 如何更好的使自己的东西看上去很不错等等。其实这些都不是问题的实质,我们可以在实践中不断提升自己,不断充实自己。 不是很难但是英文要有一点基础网上的教程很少有系统的详细的去买书吧,另不用专门学习vb关于vbscript脚本在asp教材都有介绍 ASP也是这几种脚本语言中最简单易学的开发语言。但ASP也是这几种语言中唯一的一个不能很好支持跨平台的语言。 因为ASP脚本语言非常简单,因此其代码也简单易懂,结合HTML代码,可快速地完成网站的应用程序。
页:
[1]