当前位置: 首页 > 图文教程 > 网络编程 > 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生成Word文档的又一方法


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

  在网上,利用Asp生成Word文档的方法实在不少,最常见到的方法就是利用Word生成.dot的文档,再用Asp向.dot文档中传递宏,这种方法虽好,但实现起来非常复杂,而且不能循环生成表格。

在实际应用中,我总结出来一种新的生成Word文件的方法,生成的Word文件有页眉、页角,现拿出一例与大家探讨。

 

实现:

我的解决办法,用Word XP(其他版本还没有试过)制作表格,将做好的Word表格转换为HTML文档,在用ASP控制转换后HTML文档。

页眉、页角的解决办法,在转换带Word页眉、页角的DOC文档后会在转换的HTML文件附加一个文件夹,内有页眉、页角文件及图片,只要在HTML文件的相应位置改变其路径为服务器路径即可。用户打开并ASP生成的Word文件后,Word会自动提示将这些文件保存。

看下面的Word转换后的HTML文,我用ASP加以简单控制:

<% Response.ContentType = "application/msword" %>
<!-- #include file="inc/Conn_Open.asp"-->
<!-- #include file="inc/Transition.asp"-->
<!-- #include file="inc/Check_Character.asp"-->
<!-- #include file="inc/ErrorMsg.asp"-->
<!-- #include file="inc/Check_Privilege.asp"-->
<!-- #include file="inc/Check_Logout.asp"-->
<!-- #include file="inc/System_Log_Action.asp"-->
<%response.buffer=false
response.expires=0
call Check_Logout()
call check_state()
call Privilege(6)
call Log_Action("访问","销售编号打印","打印临时销售编号"&request("Temp_Id"),1)%>
%>
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40";>

<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 10">
<meta name=Originator content="Microsoft Word 10">
<link rel=File-List href="create_doc/filelist.xml">
<link rel=Edit-Time-Data href="create_doc/editdata.mso">
<link rel=OLE-Object-Data href="create_doc/oledata.mso">
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Administrator</o:Author>
  <o:LastAuthor>Administrator</o:LastAuthor>
  <o:Revision>34</o:Revision>
  <o:TotalTime>26</o:TotalTime>
  <o:LastPrinted>2002-11-06T05:54:00Z</o:LastPrinted>
  <o:Created>2002-11-06T04:56:00Z</o:Created>
  <o:LastSaved>2002-11-06T05:55:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>98</o:Words>
  <o:Characters>562</o:Characters>
  <o:Company>shine</o:Company>
  <o:Lines>4</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:CharactersWithSpaces>659</o:CharactersWithSpaces>
  <o:Version>10.2625</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Print</w:View>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:Compatibility>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
 {font-family:宋体;
 panose-1:2 1 6 0 3 1 1 1 1