网页编程 - 用ASP生成Word、Excel和Txt文档)

1、用ASP生成Word文档

    <%

    Response.ContentType = "application/msword"

    Response.AddHeader "Content-Disposition", "attachment;filename=NAME.doc"    

    Response.Write("Weste.net : <a href=""http://weste.net"">欢迎您访问西部e网!</a><br>" & vbnewline)

    Response.Write("<h1>We can use HTML codes for word documents</h1>")

    response.write "<table width=""100%"" border=""1"" >"

    response.write "<tr>"

    response.write "<th width=""40%""><b>Name</b></th>"

    response.write "<th width=""30%""><b>Username</b></th>"

    response.write "<th width=""30%""><b>Password</b></th>"

    response.write "</tr>"

    response.write "<tr>"

    response.write "<td width=""40%"">Weste.net</td>"

    response.write "<td width=""30%"">admin@weste.net</td>"

    response.write "<td width=""30%"">mypassword</td>"

    response.write "</tr>"

    response.write "</table>"

    %>

2、用ASP生成Excel文档

    <%

    Response.AddHeader "Content-Disposition", "attachment;filename=members.xls"

    

    Response.ContentType = "application/vnd.ms-excel"

    

    response.write "<table width=""100%"" border=""1"" >"

    response.write "<tr>"

    response.write "<th width=""40%""><b>Name</b></th>"

    response.write "<th width=""30%""><b>Username</b></th>"

    response.write "<th width=""30%""><b>Password</b></th>"

    response.write "</tr>"

    response.write "<tr>"

    response.write "<td width=""40%"">Weste.net</td>"

    response.write "<td width=""30%"">admin@weste.net</td>"

    response.write "<td width=""30%"">mypassword</td>"

    response.write "</tr>"

    response.write "</table>"

    %>

3、用ASP生成Txt文档

    对己存在的文档进行编辑

    <%

    set objFso = server.createobject("scripting.filesystemobject")

    set objFile = objFso.CreateTextFile("sample.txt", true)

    objFile.write "An example creating a file"

    objFile.close

    set objFile = nothing

    objFso = nothing

    %>

    创建一个新文档,并在里面添加数据

    <%

    set objFso = server.createobject("scripting.filesystemobject")

    set objFile = objFso.CreateTextFile("sample.txt", false)

    objFile.write "An example creating a file"

    objFile.close

    set objFile = nothing

    objFso = nothing

    %>