[摘要]
ASP页面
ASP页( CustomDoc.asp ) 实际完成以下任务:取得用户输入、用COM组件创建Word 文档、
将它递交回用户。下面是带注释的代码:
< %
Dim sTags, sValues, sDestPath, sSourcePath, resValue
Get all the User Input values fr...
ASP页面
ASP页( CustomDoc.asp ) 实际完成以下任务:取得用户输入、用COM组件创建Word 文档、
将它递交回用户。下面是带注释的代码:
< %
Dim sTags, sValues, sDestPath, sSourcePath, resValue
Get all the User Input values from the Form
sName = Request("Name")
sAddress = Request("Address")
sCity = Request("City")
sState = Request("State")
sZip = Request("Zip")
sCountry = Request("Country")
sEmail = Request("Email")
sDate = Now() Create a list of all the tags as defined in the Word Template by You
sTags = "< Name >, < Address >, < City >, < State >, < Zip >, < Country >, " & _
"< Email >, < Date >"
Gather up all the User Input values into one delimited string
sValues = sName & " | " & sAddress & " | " & sCity & " | " & sState & _
" | " & sZip & " | " & sCountry & " | " & sEmail & " | " & sDate
完成之后,需要识别源文件(Template) 和目标文件(Document)的位置。APPL_PHYSICAL_PATH 返回CustomDoc.asp 文件所在的路径。我们将文档文件夹和文件名附加在一起,这是用户负空间的名字。
sSourcePath = Request.ServerVariables("APPL_PHYSICAL_PATH") & _
"Templates\" & "EmployeeTemplate.dot"
sDestPath = Request.ServerVariables("APPL_PHYSICAL_PATH") & _
"Documents\" & Replace(sName, " ","") & ".doc"
现在完成了常见MyDocument对象的例示和调用GenerateDocument.doc,在返回值的基础上进行适当的操作。
Set myDocObj = Server.CreateObject("MyDocument.DocumentObject")
Call the GenerateDocument function while passing the required
Parameters retValue = myDocObj.GenerateDocument(sTags, sValues, sSourcePath, _
sDestPath)
Take appropriate action based on the returned value
If retValue = "Success" Then
Msg = "Successfully generated your Document : " & Replace(sName, _
" ", "") & ".doc"
Response.Write("< font face=arial size=-1 color=Green >< br >" & Msg)
Response.Write("< br >< br >< a href=Documents/" & _
Replace(sName, " ","") & ".doc" & " >Here it is!< /a >")
Else Response.Write("< font face=arial size=-1 color=Red >< br >" & retValue) End If
% > 将文件存入C:\Inetpub\scripts\。就行了。现在在浏览器中键入
http://localhost/scripts/EmployeeForm.html,执行应用程序,输入所有的域值,点击
Save and Generate Profile Document。现在可以看到我们的方法是多么有效和美观了。