word 在網上,利用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.M