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

ASP
ASP连接SQL2005数据库连接代码
ASP程序与SQL存储过程结合使用详解
asp 小偷采集程序原理与常用函数方法
防盗链接ASP函数
asp将table生成excel文件(xls)
asp实现新评论自动发短信提示的代码
asp最简单的生成验证码代码
ASP 常见对象总结(熟悉一下利用以后的开发使用)
ASP UTF-8编码生成静态网页的函数
ASP+FSO生成的网页文件默认编码格式以及转换成UTF-8编码方法
asp Access数据备份,还原,压缩类代码
asp fso操作类
ASP 自动采集实现代码
asp 一些支付接口
ASP 递归调用 已知节点查找根节点的函数
用asp实现读取文件的最后一行的代码
用asp实现的获取文件夹中文件的个数的代码
ASP与Excel结合生成数据表和Chart图的代码
iis7 ASP+Access数据库连接错误
ASP 日期的加减运算实现代码

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 124 ::
收藏到网摘: 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>