<!--#include file ="conn.asp"--> <% sql="select * from news order by date desc" set rs=server.CreateObject("adodb.recordset") rs.open sql,conn,1,1
set fso=server.CreateObject("scripting.filesystemobject") path=server.MapPath("./") set docfile=fso.createTextFile(path&"\data.doc")
while not rs.eof title=rs("title") content=rs("content") author=rs("author") datetime=rs("date") docfile.writeLine(title) '写入一字符串和换行符,如果没有title,就只写入换行符 docfile.writeLine(content) docfile.writeLine(author) docfile.writeLine(datetime) rs.movenext wend docfile.close '注意,我这样做打开DOC文档时要我选择编码,选择WINDOWS默认(即简体中文)就行 %>
<% Response.ContentType = "application/msword" %> <%
Dim Fso,FileExt,strFilePath,Mime strFilePath = "c:\a.doc" Set Fso=Server.CreateObject("Scripting.FileSystemObject") FileExt = Fso.GetExtensionName(strFilePath) Set fso=Nothing
Select Case FileExt Case "doc" Mime="Application/msword" Case "xls" Mime="Application/msexcel" End Select
Call OutPut(strFilePath,Mime)
'###################################################### Function OutPut(strFilePath,Mime) Response.ContentType = Mime Const adTypeBinary = 1 Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = adTypeBinary objStream.LoadFromFile strFilePath Response.BinaryWrite objStream.Read objStream.Close Set objStream = Nothing End Function '###################################################### %> 把上面的信息拷贝到你的ASP页面中,然后在C盘下新建一个 "a.doc" 的文件,这样就可以实现了