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

ASP
Asp+Sql 对数据库的各种操作
ASP:6行代码实现无组件上传
ASP中几种分页显示的比较
ASP中数据库调用中常见错误的现象和解决
ASP实用技巧:强制刷新和判断文件地址
asp全站防止注入的代码
ASP如何获取客户端真实IP地址
ASP实现可显示和隐藏的树型菜单
如何用ASP获取真实IP地址
ASP与SQL数据库连接代码
拒绝攻击 万能Asp防注入代码
草根站长成长计划:跟我学新云采集入门(2)
ASP技巧:提高使用Request集合的效率
Asp用存储过程实现数据分页
做网页时常用的ASP函数
Asp编码优化技巧八则
ASP中Cache技术的应用
用ASP封IP的方法,防止固定IP垃圾留言
ASP实现一行多列显示方法实例程序
ASP实现动态添加表单内容的实例程序

ASP生成Word文档的又一方法


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