在实际应用中,我总结出来一种新的生成Word文件的方法,生成的Word文件有页眉、页角,现拿出一例与大家探讨。
实现:
我的解决办法,用WordXP(其他版本还没有试过)制作表格,将做好的Word表格转换为HTML文档,在用ASP控制转换后HTML文档。
页眉、页角的解决办法,在转换带Word页眉、页角的DOC文档后会在转换的HTML文件附加一个文件夹,内有页眉、页角文件及图片,只要在HTML文件的相应位置改变其路径为服务器路径即可。用户打开并ASP生成的Word文件后,Word会自动提示将这些文件保存。
看下面的Word转换后的HTML文,我用ASP加以简单控制:
<%Response.ContentType="application/msword"%>
<!--#includefile="inc/Conn_Open.asp"-->
<!--#includefile="inc/Transition.asp"-->
<!--#includefile="inc/Check_Character.asp"-->
<!--#includefile="inc/ErrorMsg.asp"-->
<!--#includefile="inc/Check_Privilege.asp"-->
<!--#includefile="inc/Check_Logout.asp"-->
<!--#includefile="inc/System_Log_Action.asp"-->
<%response.buffer=false
response.expires=0
callCheck_Logout()
callcheck_state()
callPrivilege(6)
callLog_Action("访问","销售编号打印","打印临时销售编号"&request("Temp_Id"),1)%>
%>
<htmlxmlns: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>
<metahttp-equiv=Content-Typecontent="text/html;charset=gb2312">
<metaname=ProgIdcontent=Word.Document>
<metaname=Generatorcontent="MicrosoftWord10">
<metaname=Originatorcontent="MicrosoftWord10">
<linkrel=File-Listhref="create_doc/filelist.xml">
<linkrel=Edit-Time-Datahref="create_doc/editdata.mso">
<linkrel=OLE-Object-Datahref="create_doc/oledata.mso">
<!--[ifgtemso9]><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]--><!--[ifgtemso9]><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>
<!--
/*FontDefinitions*/
@font-face
{font-family:宋体;
panose-1:2160311111;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:31351352321602621450;}
@font-face
{font-family:"\@宋体";
panose-1:2160311111;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:31351352321602621450;}
/*StyleDefinitions*/
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:center207.65ptright415.3pt;
layout-grid-mode:char;
border:none;
mso-border-bottom-alt:solidwindowtext.75pt;
padding:0cm;
mso-padding-alt:0cm0cm1.0pt0cm;
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:center207.65ptright415.3pt;
layout-grid-mode:char;
font-size:9.0pt;
font-family:宋体;
mso-bidi-font-family:宋体;}
span.GramE
{mso-style-name:"";
mso-gram-e:yes;}
@pageSection1
{size:595.3pt841.9pt;
margin:44.95pt90.0pt72.0pt90.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>
<!--[ifgtemso10]>
<style>
/*StyleDefinitions*/
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:0cm5.4pt0cm5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"TimesNewRoman";
mso-fareast-font-family:"TimesNewRoman";}
table.MsoTableGrid
{mso-style-name:网格型;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
border:solidwindowtext1.0pt;
mso-border-alt:solidwindowtext.5pt;
mso-padding-alt:0cm5.4pt0cm5.4pt;
mso-border-insideh:.5ptsolidwindowtext;
mso-border-insidev:.5ptsolidwindowtext;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"TimesNewRoman";}
</style>
<![endif]--><!--[ifgtemso9]><xml>
<o:shapedefaultsv:ext="edit"spidmax="5122"/>
</xml><![endif]--><!--[ifgtemso9]><xml>
<o:shapelayoutv:ext="edit">
<o:idmapv:ext="edit"data="1"/>
</o:shapelayout></xml><![endif]-->
</head>
<bodylang=ZH-CNstyle='tab-interval:21.0pt'>
<divclass=Section1>
<%setrs=server.createobject("ADODB.RecordSet")
sql="select*fromT_TempwhereTemp_ID="&request("Temp_Id")
rs.opensql,cstr(conn),1,1
SearchDate=rs("CreateTime")
rs.close
sql="select*fromT_TempReadnewswhereR_Temp_Id="&request("Temp_Id")&"OrderbyTempReadnews_IdDESC"
rs.opensql,cstr(conn),1,1%>
<pclass=MsoNormal><bstyle='mso-bidi-font-weight:normal'><spanlang=EN-US
style='font-size:10.5pt'><o:p></o:p></span></b></p>
<pclass=MsoNormalalign=centerstyle='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-USstyle='font-size:9.0pt;line-height:175%'><o:p></o:p></span></b></p>
<pclass=MsoNormalalign=centerstyle='text-align:center;line-height:175%'><b><span
lang=EN-USstyle='font-size:9.0pt;line-height:175%'><o:p></o:p></span></b></p>
<pclass=MsoNormalstyle='line-height:150%'><b><spanstyle='font-size:10.5pt'>查询编号:<u><spanlang=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><spanstyle='mso-spacerun:yes'></span>查询日期:<u>
<spanstyle='mso-spacerun:yes;font-size:10.5pt'></span><span
style='mso-spacerun:yes'><%=SearchDate%></span></u>_<o:p></o:p></span></span></b></p>
<tableclass=MsoTableGridborder=1cellspacing=0cellpadding=0
style='border-collapse:collapse;border:none;mso-border-alt:solidwindowtext.5pt;
mso-yfti-tbllook:480;mso-padding-alt:0cm5.4pt0cm5.4pt;mso-border-insideh:
.5ptsolidwindowtext;mso-border-insidev:.5ptsolidwindowtext'>
<trstyle='mso-yfti-irow:0;height:17.25pt'>
<tdwidth=71style='width:53.25pt;border:solidwindowtext1.0pt;mso-border-alt:
solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanstyle='font-size:9.0pt'>日报编号<span
lang=EN-US><o:p></o:p></span></span></b></p>
</td>
<tdwidth=56style='width:42.15pt;border:solidwindowtext1.0pt;border-left:
none;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanstyle='font-size:9.0pt'>区域<span
lang=EN-US><o:p></o:p></span></span></b></p>
</td>
<tdwidth=72style='width:54.0pt;border:solidwindowtext1.0pt;border-left:
none;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanstyle='font-size:9.0pt'>路段名<span
lang=EN-US><o:p></o:p></span></span></b></p>
</td>
<tdwidth=36style='width:27.0pt;border:solidwindowtext1.0pt;border-left:
none;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanlang=EN-USstyle='font-size:9.0pt'>L/R<o:p></o:p></span></b></p>
</td>
<tdwidth=48style='width:36.0pt;border:solidwindowtext1.0pt;border-left:
none;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanstyle='font-size:9.0pt'>形式<span
lang=EN-US><o:p></o:p></span></span></b></p>
</td>
<tdwidth=48style='width:36.0pt;border:solidwindowtext1.0pt;border-left:
none;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanstyle='font-size:9.0pt'>级别<span
lang=EN-US><o:p></o:p></span></span></b></p>
</td>
<tdwidth=189style='width:141.7pt;border:solidwindowtext1.0pt;border-left:
none;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:17.25pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><b
style='mso-bidi-font-weight:normal'><spanstyle='font-size:9.0pt'>详细位置<span
lang=EN-US><o:p></o:p></span></span></b></p>
</td>
</tr>
<%setrs1=server.createobject("ADODB.RecordSet")
dowhilenotrs.eof
sql1="select*fromT_ReadnewswhereReadnews_Id="&rs("R_Readnews_Id")
rs1.opensql1,cstr(conn),1,1%>
<trstyle='mso-yfti-irow:1;mso-yfti-lastrow:yes;height:15.0pt'>
<tdwidth=71style='width:53.25pt;border:solidwindowtext1.0pt;border-top:
none;mso-border-top-alt:solidwindowtext.5pt;mso-border-alt:solidwindowtext.5pt;
padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><spanlang=EN-US
style='font-size:9.0pt'><%=rs1("DailyNumber")%>071<o:p></o:p></span></p>
</td>
<tdwidth=56style='width:42.15pt;border-top:none;border-left:none;
border-bottom:solidwindowtext1.0pt;border-right:solidwindowtext1.0pt;
mso-border-top-alt:solidwindowtext.5pt;mso-border-left-alt:solidwindowtext.5pt;
mso-border-alt:solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><span
style='font-size:9.0pt'><%=Area(rs1("Area"))%><spanlang=EN-US><o:p></o:p></span></span></p>
</td>
<tdwidth=72style='width:54.0pt;border-top:none;border-left:none;border-bottom:
solidwindowtext1.0pt;border-right:solidwindowtext1.0pt;mso-border-top-alt:
solidwindowtext.5pt;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:
solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><span
style='font-size:9.0pt'><%=rs1("RoadName")%><spanlang=EN-US><o:p></o:p></span></span></p>
</td>
<tdwidth=36style='width:27.0pt;border-top:none;border-left:none;border-bottom:
solidwindowtext1.0pt;border-right:solidwindowtext1.0pt;mso-border-top-alt:
solidwindowtext.5pt;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:
solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><spanlang=EN-US
style='font-size:9.0pt'><%=LeftRight1(rs1("LeftRight"))%><o:p></o:p></span></p>
</td>
<tdwidth=48style='width:36.0pt;border-top:none;border-left:none;border-bottom:
solidwindowtext1.0pt;border-right:solidwindowtext1.0pt;mso-border-top-alt:
solidwindowtext.5pt;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:
solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><spanlang=EN-US
style='font-size:9.0pt'><%=rs1("Form")%><o:p></o:p></span></p>
</td>
<tdwidth=48style='width:36.0pt;border-top:none;border-left:none;border-bottom:
solidwindowtext1.0pt;border-right:solidwindowtext1.0pt;mso-border-top-alt:
solidwindowtext.5pt;mso-border-left-alt:solidwindowtext.5pt;mso-border-alt:
solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><spanlang=EN-US
style='font-size:9.0pt'><%=rs1("PlaceLevel")%><o:p></o:p></span></p>
</td>
<tdwidth=189style='width:141.7pt;border-top:none;border-left:none;
border-bottom:solidwindowtext1.0pt;border-right:solidwindowtext1.0pt;
mso-border-top-alt:solidwindowtext.5pt;mso-border-left-alt:solidwindowtext.5pt;
mso-border-alt:solidwindowtext.5pt;padding:0cm5.4pt0cm5.4pt;height:15.0pt'>
<pclass=MsoNormalalign=centerstyle='text-align:center'><spanclass=GramE><span
style='font-size:9.0pt'><%=rs1("PAddress")%></span></span></p>
</td>
</tr>
<%rs1.close
rs.movenext
loop
rs.close
sql="select*fromT_TempwhereTemp_Id="&request("Temp_Id")
rs.opensql,cstr(conn),1,1
User_Id=rs("R_User_Id")
rs.close
sql="select*fromT_UserwhereUser_Id="&User_Id
rs.opensql,cstr(conn),1,1
UserName=rs("TrueName")
rs.close
setrs=nothing
setrs1=nothing%>
</table>
<p></p>
<pclass=MsoNormalalign=rightstyle='text-align:right;'><b><span
style='font-size:9.0pt'>销售人</span></b><spanstyle='font-size:9.0pt'>:<span
lang=EN-US><%=UserName%> <b>制表时间</b>:<%=Now%></span></span><spanlang=EN-US></span><span
lang=EN-USstyle='font-size:9.0pt'><o:p></o:p></span></p>
</div>
</body>
</html>