ASP生成Word文档的又一方法 |
|
作者:佚名 文章来源:网络文摘 更新时间:2006-5-6 13:30:38 |
【声明:转载此信息在于传递更多信息,其内容表达的观点并不代表本站立场,由这些信息所产生的一切后果本站不负任何责任。如果您对本信息有什么意见,欢迎和本站联系,谢谢!】http://CiDu.Net
在网上,利用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 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"\@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋体; mso-bidi-font-family:宋体;} p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0cm; margin-bottom:.0001pt; text-align:center; mso-pagination:widow-orphan; tab-stops:center 207.65pt right 415.3pt; layout-grid-mode:char; border:none; mso-border-bottom-alt:solid windowtext .75pt; padding:0cm; mso-padding-alt:0cm 0cm 1.0pt 0cm; font-size:9.0pt; font-family:宋体; mso-bidi-font-family:宋体;} p.MsoFooter, li.MsoFooter, div.MsoFooter {margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 207.65pt right 415.3pt; layout-grid-mode:char; font-size:9.0pt; font-family:宋体; mso-bidi-font-family:宋体;} span.GramE {mso-style-name:""; mso-gram-e:yes;} @page Section1 {size:595.3pt 841.9pt; margin:44.95pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '*********************************************************************** '页眉页角的位置 '*********************************************************************** <%DocPath="http://";&request.ServerVariables("Remote_Host")&"/bacmda/create_doc/"%> mso-header:url("<%=DocPath%>header.htm") h1; mso-footer:url("<%=DocPath%>header.htm") f1; mso-paper-source:0;} div.Section1 {page:Section1;} --> </style> <!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} table.MsoTableGrid {mso-style-name:网格型; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; border:solid windowtext 1.0pt; mso-border-alt:solid windowtext .5pt; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-border-insideh:.5pt solid windowtext; mso-border-insidev:.5pt solid windowtext; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="5122"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]--> </head>
<body lang=ZH-CN style='tab-interval:21.0pt'>
<div class=Section1> <%set rs=server.createobject("ADODB.RecordSet") sql="select * from T_Temp where Temp_ID="&request("Temp_Id") rs.open sql,cstr(conn),1,1 SearchDate=rs("CreateTime") rs.close sql="select * from T_TempReadnews where R_Temp_Id="&request("Temp_Id")&" Order by TempReadnews_Id DESC" rs.open sql,cstr(conn),1,1%> <p class=MsoNormal><b style='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:10.5pt'><o:p> </o:p></span></b></p>
<p class=MsoNormal align=center style='text-align:center;line-height:175%'><b><span style='font-size:16.0pt;mso-bidi-font-size:12.0pt;line-height:175%'>阅报栏媒体查询单</span></b><b><span lang=EN-US style='font-size:9.0pt;line-height:175%'><o:p></o:p></span></b></p>
<p class=MsoNormal align=center style='text-align:center;line-height:175%'><b><span lang=EN-US style='font-size:9.0pt;line-height:175%'><o:p> </o:p></span></b></p>
<p class=MsoNormal style='line-height:150%'><b><span style='font-size:10.5pt'>查询编号:<u><span lang=EN-US><span style='mso-spacerun:yes'> </span><span style='mso-spacerun:yes'><%=request("Temp_Id")%> </span><span style='mso-spacerun:yes'> </span></span></u><span lang=EN-US><span style='mso-spacerun:yes'> </span>查询日期:<u> <span style='mso-spacerun:yes;font-size:10.5pt'> </span><span style='mso-spacerun:yes'><%=SearchDate%> </span></u>_<o:p></o:p></span></span></b></p>
<table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none;mso-border-alt:solid windowtext .5pt; mso-yfti-tbllook:480;mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-border-insideh: .5pt solid windowtext;mso-border-insidev:.5pt solid windowtext'> <tr style='mso-yfti-irow:0;height:17.25pt'> <td width=71 style='width:53.25pt;border:solid windowtext 1.0pt;mso-border-alt: solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-size:9.0pt'>日报编号<span lang=EN-US><o:p></o:p></span></span></b></p> </td> <td width=56 style='width:42.15pt;border:solid windowtext 1.0pt;border-left: none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-size:9.0pt'>区域<span lang=EN-US><o:p></o:p></span></span></b></p> </td> <td width=72 style='width:54.0pt;border:solid windowtext 1.0pt;border-left: none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-size:9.0pt'>路段名<span lang=EN-US><o:p></o:p></span></span></b></p> </td> <td width=36 style='width:27.0pt;border:solid windowtext 1.0pt;border-left: none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span lang=EN-US style='font-size:9.0pt'>L/R<o:p></o:p></span></b></p> </td> <td width=48 style='width:36.0pt;border:solid windowtext 1.0pt;border-left: none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-size:9.0pt'>形式<span lang=EN-US><o:p></o:p></span></span></b></p> </td> <td width=48 style='width:36.0pt;border:solid windowtext 1.0pt;border-left: none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-size:9.0pt'>级别<span lang=EN-US><o:p></o:p></span></span></b></p> </td> <td width=189 style='width:141.7pt;border:solid windowtext 1.0pt;border-left: none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:17.25pt'> <p class=MsoNormal align=center style='text-align:center'><b style='mso-bidi-font-weight:normal'><span style='font-size:9.0pt'>详细位置<span lang=EN-US><o:p></o:p></span></span></b></p> </td> </tr> <%set rs1=server.createobject("ADODB.RecordSet") do while not rs.eof sql1="select * from T_Readnews where Readnews_Id="&rs("R_Readnews_Id") rs1.open sql1,cstr(conn),1,1%> <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes;height:15.0pt'> <td width=71 style='width:53.25pt;border:solid windowtext 1.0pt;border-top: none;mso-border-top-alt:solid windowtext .5pt;mso-border-alt:solid windowtext .5pt; padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:9.0pt'><%=rs1("DailyNumber")%>071<o:p></o:p></span></p> </td> <td width=56 style='width:42.15pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span style='font-size:9.0pt'><%=Area(rs1("Area"))%><span lang=EN-US><o:p></o:p></span></span></p> </td> <td width=72 style='width:54.0pt;border-top:none;border-left:none;border-bottom: solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;mso-border-top-alt: solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-alt: solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span style='font-size:9.0pt'><%=rs1("RoadName")%><span lang=EN-US><o:p></o:p></span></span></p> </td> <td width=36 style='width:27.0pt;border-top:none;border-left:none;border-bottom: solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;mso-border-top-alt: solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-alt: solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:9.0pt'><%=LeftRight1(rs1("LeftRight"))%><o:p></o:p></span></p> </td> <td width=48 style='width:36.0pt;border-top:none;border-left:none;border-bottom: solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;mso-border-top-alt: solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-alt: solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:9.0pt'><%=rs1("Form")%><o:p></o:p></span></p> </td> <td width=48 style='width:36.0pt;border-top:none;border-left:none;border-bottom: solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;mso-border-top-alt: solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;mso-border-alt: solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span lang=EN-US style='font-size:9.0pt'><%=rs1("PlaceLevel")%><o:p></o:p></span></p> </td> <td width=189 style='width:141.7pt;border-top:none;border-left:none; border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt; mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt; mso-border-alt:solid windowtext .5pt;padding:0cm 5.4pt 0cm 5.4pt;height:15.0pt'> <p class=MsoNormal align=center style='text-align:center'><span class=GramE><span style='font-size:9.0pt'><%=rs1("PAddress")%></span></span></p> </td> </tr> <%rs1.close rs.movenext loop rs.close sql="select * from T_Temp where Temp_Id="&request("Temp_Id") rs.open sql,cstr(conn),1,1 User_Id=rs("R_User_Id") rs.close sql="select * from T_User where User_Id="&User_Id rs.open sql,cstr(conn),1,1 UserName=rs("TrueName") rs.close set rs=nothing set rs1=nothing%> </table> <p></p> <p class=MsoNormal align=right style='text-align:right;'><b><span style='font-size:9.0pt'>销售人</span></b><span style='font-size:9.0pt'>:<span lang=EN-US><%=UserName%> <b>制表时间</b>:<%=Now%></span></span><span lang=EN-US> </span><span lang=EN-US style='font-size:9.0pt'><o:p></o:p></span></p> </div>
</body>
</html>
声明:以上信息资料大都是网上搜集而来,版权归作者,如有版权问题请留言告知我将马上改正。 文中所提到的各种观点只是原文观点,各种说法未经一一确认。并不代表本站认可此观点!!
|
资讯录入:admin 责任编辑:admin |
|
上一篇资讯: 如何准确定时运行ASP文件
下一篇资讯: 使用ASP组件的一点经验 |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |