用ASP怎么实现生成Word文档保存的有关问题,看了很多帖子都无法解决有关问题
用ASP如何实现生成Word文档保存的问题,看了很多帖子都无法解决问题。
在网上看到很多这段代码,不知道为何在我电脑上实现不了呢?
Word.Application好像用不起来,我的是win7,office2007.求高人指点。
------解决方案--------------------
在ASP中生成Word文件、Excel文件和Txt文件,参考了微软的官方文档,自己简单弄了下,基本可以实现了,不足之处,望指导!下面言归正传。
1、用ASP生成Word文档,代码示例:
<%
Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition", "attachment;filename=NAME.doc"
Response.Write("欢迎来到源码爱好者!<br>" & vbnewline)
Response.Write("<h1>用ASP生成Word文档的示例</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%"">源码爱好者</td>"
response.write "<td width=""30%"">user</td>"
response.write "<td width=""30%"">mypassword</td>"
response.write "</tr>"
response.write "</table>"
%>
用这种方法生成的Word文档,有时候会出现一个提示:“Microsoft Office Word 需要转换器以正确显示该文件。这项功能目前尚未安装,是否现在安装?”,这时候重新安装SKU011.CAB就可以了,原因不明。
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>教程文章</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%"">源码爱好者</td>"
response.write "<td width=""30%"">user</td>"
response.write "<td width=""30%"">mypassword</td>"
response.write "</tr>"
response.write "</table>"
%>
3、ASP生成Txt文档,这个最简单,用Fso就可以:
<%
set objFso = server.createobject("scripting.filesystemobject")
set objFile = objFso.CreateTextFile("sample.txt", false)
objFile.write "这是一个生成txt文本的演示文档"
objFile.close
set objFile = nothing
objFso = nothing
%>
在网上看到很多这段代码,不知道为何在我电脑上实现不了呢?
Word.Application好像用不起来,我的是win7,office2007.求高人指点。
<script language="javascript">
function OpenWord(){
Layer1.style.border=0
word = new ActiveXObject('Word.Application');
word.Application.Visible = true;
var mydoc=word.Documents.Add('',0,1);
myRange =mydoc.Range(0,1)
var sel=Layer1.document.body.createTextRange()
sel.select()
Layer1.document.execCommand('Copy')
sel.moveEnd('character')
myRange.Paste();
location.reload()
word.ActiveWindow.ActivePane.View.Type=9
}
</script>
------解决方案--------------------
在ASP中生成Word文件、Excel文件和Txt文件,参考了微软的官方文档,自己简单弄了下,基本可以实现了,不足之处,望指导!下面言归正传。
1、用ASP生成Word文档,代码示例:
<%
Response.ContentType = "application/msword"
Response.AddHeader "Content-Disposition", "attachment;filename=NAME.doc"
Response.Write("欢迎来到源码爱好者!<br>" & vbnewline)
Response.Write("<h1>用ASP生成Word文档的示例</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%"">源码爱好者</td>"
response.write "<td width=""30%"">user</td>"
response.write "<td width=""30%"">mypassword</td>"
response.write "</tr>"
response.write "</table>"
%>
用这种方法生成的Word文档,有时候会出现一个提示:“Microsoft Office Word 需要转换器以正确显示该文件。这项功能目前尚未安装,是否现在安装?”,这时候重新安装SKU011.CAB就可以了,原因不明。
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>教程文章</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%"">源码爱好者</td>"
response.write "<td width=""30%"">user</td>"
response.write "<td width=""30%"">mypassword</td>"
response.write "</tr>"
response.write "</table>"
%>
3、ASP生成Txt文档,这个最简单,用Fso就可以:
<%
set objFso = server.createobject("scripting.filesystemobject")
set objFile = objFso.CreateTextFile("sample.txt", false)
objFile.write "这是一个生成txt文本的演示文档"
objFile.close
set objFile = nothing
objFso = nothing
%>