当前位置: 首页 > 图文教程 > 网络编程 > ASP > asp中将内容生成word文档的函数

ASP
asp中常用的文件处理函数
正确处理ASP动态网页中的容错机制
asp自动生成javascript检验函数
如何避免asp的SQL的执行效率低
编译asp应用程序成为exe文件
ASP完成小偷程序机制和简略示例
ASP技巧:rs.getrows方法
ASP简单实现数字字符混合验证码
ASP技巧 挂QQ的网页源代码ASP/PHP
ASP实例:用ASP判断文件地址是否有效
ASP实例:使用ASP生成图片彩色校验码
ASP如何跳出本次进入下一次循环
ASP读取数据库中数据到数组的类
为你的ASP程序作一个负载测试
如何用ASP来获取客户端真实IP的地址
asp脚本运行超时的解决办法
ASP缓存类 【先锋缓存类】Ver2004
ASP动态包含文件的改进方法
ASP中利用application实现缓存
ASP Application 对象用户手册

ASP 中的 asp中将内容生成word文档的函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 132 ::
收藏到网摘: n/a

日常工作中经常需要把很多内容直接转换成word文档,于是写了个生成word文档的asp函数,代码如下:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>生成word文档</title>
</head>

<script language="vbscript">
sub builddoc()
    On Error Resume Next

    Dim wApp

    Set wApp = CreateObject("Word.Application")
    If Err.number > 0 Then
        Alert "没法保存为Word文件,请正确安装Word97"
    else
    wApp.visible = True
    wApp.Documents.add
   
                     wApp.Selection.TypeParagraph
                     wApp.Selection.Font.Bold = True
                     wApp.Selection.TypeText "programfan"
                     wApp.Selection.ParagraphFormat.Alignment = 1
                      rem 居 中  

                     wApp.Selection.TypeParagraph  
                     wApp.Selection.Font.Bold = false                  
                     wApp.Selection.TypeText "-- programfan.com"
                     wApp.Selection.TypeParagraph   
                     wApp.Selection.ParagraphFormat.LeftIndent = wApp.CentimetersToPoints(0)
                     wApp.Selection.ParagraphFormat.FirstLineIndent = wApp.CentimetersToPoints(0.72/2*2)
                     wApp.Selection.TypeParagraph
                     wApp.Selection.Font.Bold = false
                     wApp.Selection.ParagraphFormat.Alignment = 0
                    
                      
                      
                         wapp.selection.typetext document.form1.doc1.value
                        wApp.Selection.TypeParagraph   

                      rem 居 右
                     wApp.Selection.TypeParagraph  
                     wApp.Selection.Font.Bold = false                 
                     wApp.Selection.TypeText Now()
                     wApp.Selection.TypeParagraph  
                     wApp.Saved = true
                    wapp.ActiveDocument.SaveAs "c:\a.doc"
                    wapp.close
                    
  end if

end sub
</script>
<body>
<form name="form1" >
<p> </p>
<p><textarea rows="8" name="doc1" cols="46"></textarea></p>
<p> </p>
<p>生成word文档<input type="button" value="生成" name="B1" onclick="builddoc()"></p>
</form>
</body>
</html>