当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP生成Word文档的又一方法

ASP
ASP 编程中20个非常有用的例子(一)
ASP 编程中20个非常有用的例子(二)
ASP基础教程:ADO存取数据库时如何分页显示
ASP基础教程:其它的ASP常用组件
ASP基础教程:学习ASP中子程序的应用
ASP基础教程之ASP程序对Cookie的处理
ASP基础教程之实例学习ASP Response 对象
ASP基础教程之ASP AdRotator 组件的使用
ADO初学者教程:ADO 通过GetString()加速脚本
初学者来认识OLEDB和ODBC的区别
ASP常见数学函数 Abs Atn Cos 等详细详解
VBScript新手入门初学教程:VBScript简介
有用的无声递交表单的客户端函数
Windows 2003 安装设置iis
ASP技巧实例:几行代码解决防止表单重复提交
ASP读sql数据时出现乱码问题的解决方法
ASP技巧实例:使用ASP记录在线用户的数量
ASP技巧实例:关于对表单操作的程序
ASP技巧实例:ASP实现最简洁的多重查询的解决方案
ASP实例:利用缓存提高数据显示效率

ASP生成Word文档的又一方法


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