📄 docfunc.asp
字号:
<%
dim oWord
dim oFS
dim strDocDel
Function DocInit()
set oWord=createobject("Word.Application")
Set oFS = CreateObject("Scripting.FileSystemObject")
Randomize
end Function
Function RandFile(strPath,strExp)
strRrandFile=strPath&"\"&cint(10000*rnd)&cint(10000*rnd)&"."&strExp
if oFS.FileExists(strRrandFile) then
RandFile=RandFile(strPath,strExp)
else
RandFile=strRrandFile
end if
end Function
Function DocRelease()
On Error Resume Next
oWord.ActiveDocument.Save()
oWord.ActiveDocument.Close()
oWord.Quit
if strDocDel<>"" then
oFS.DeleteFile strDocDel
end if
On Error Goto 0
end Function
Function DocOutTxT(strTxT)
response.write strTxT&"<br>"
' msgbox strTxT
End Function
Function DocOpen(strDocTemplet,strDocTo,bTemp)
if bTemp then
strDocDel=strDocTo
end if
oFS.CopyFile strDocTemplet,strDocTo
if Err.Number<>0 then
DocOpen=False
Err.clear
else
DocOpen=True
end if
oWord.Documents.Open(strDocTo)
if Err.Number<>0 then
DocOpen=False
Err.clear
else
DocOpen=True
end if
On Error Goto 0
end Function
Function GetVarFields()
Dim VarField()
ReDim VarField(0)
Dim i,j
i = 0
On Error Resume Next
oWord.ActiveDocument.Content.Select
While oWord.ActiveWindow.Selection.Find.Execute("=|*|=", True, True, True, , , , wdFindStop, False, "", False)
strFound = oWord.ActiveWindow.Selection.Text
strFound=Replace(Replace(strFound, "=|", ""), "|=", "")
For j=0 to ubound(VarField)
if VarField(j)=strFound then
exit for
end if
next
if j>ubound(VarField) then
ReDim Preserve VarField(i)
VarField(i) = strFound
i = i + 1
end if
Wend
On Error Goto 0
GetVarFields=VarField
End Function
Function GetFrom()
dim i
dim strForm
dim VarFields
strForm=""
VarFields=GetVarFields()
for i=0 to ubound(VarFields)
strForm=strForm&"<tr><td>"&varFields(i)&"</td><td><input type=text name='"&varFields(i)&"'></td</tr>"
next
GetFrom=strForm
End Function
%>
<%
response.buffer=FALSE
response.expiresabsolute=#jan 01,1980 00:00:00#
DocInit()
'strTempFile=RandFile(server.mappath("/DOCTEMPLET/TEMPFile"),"Doc")
'if not DocOpen(server.mappath("/DOCTEMPLET/_TEMPLET")&"\test.doc",strTempFile,True) then
' DocRelease()
' response.write "can't open"
' response.end
'end if
%><hr>
<FORM METHOD=POST ACTION="">
<table>
<%'=GetFrom()%>
</table>
<INPUT TYPE="submit">
<form>
<%DocRelease()%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -