|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
强大的可扩展性。ASP具有强大的扩展性,可以实现与多种网络、硬件设备的连接:通过专用的通讯线路远程接入企业;通过远程拨号服务器为远程拨号客户提供服务;通过WAP为移动电话互联网客户服务。word|创立|wordUsingActiveServerPagestoBuildMicrosoftWordDocuments
ByGardinerB.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为移动电话互联网客户服务。 |
|