Another way for ASP to generate WORD Documents

Source: Internet
Author: User

There are many ways to generate WORD Documents Using ASP on the Internet. The most common method is to generate WORD Documents Using word. dot document, and then use ASP. although this method is good, it is very complicated to implement and cannot generate tables cyclically in the dot document.

In practical application, I have summarized a new method for generating Word files. The generated Word files include headers and page corners. I will take an example to discuss with you.

 

Implementation:

My solution is to use Word XP (other versions have not yet tried) to create a table, convert a prepared Word Table to an HTML document, and use ASP to control the HTML document after conversion.

After converting a DOC file with a word header and a page angle, a folder will be appended to the converted HTML file with a header, a page angle file, and an image, you only need to change the path of the HTML file to the server path. After you open a Word file generated by ASP, the word will automatically prompt you to save the files.

Let's take a look at the HTML text converted by the following word. I will use ASP for simple control:

<% 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 ("access", "sales number printing", "Print temporary sales number" & 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: character> 562 </O: character>
<O: Company> shine </O: Company>
<O: lines> 4 </O: lines>
<O: paragraphs> 1 </O: paragraphs>
<O: characterswitheat aces> 659 </O: characterswitheat aces>
<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: 0 cm;
Margin-bottom:. 0001pt;
MSO-pagination: widow-orphan;
Font-size: 12.0pt;
Font-family:;
MSO-bidi-font-family: ;}
P. msoheader, Li. msoheader, Div. msoheader
{Margin: 0 cm;
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: 0 cm;
MSO-padding-alt: 0 cm 0 cm 1.0pt 0 cm;
Font-size: 9.0pt;
Font-family:;
MSO-bidi-font-family: ;}
P. msofooter, Li. msofooter, Div. msofooter
{Margin: 0 cm;
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;
'''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''
'*************************************** ********************************
'Position of the header and page angular
'*************************************** ********************************
<% 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: common table;
MSO-tstyle-rowband-size: 0;
MSO-tstyle-colband-size: 0;
MSO-style-noshow: yes;
MSO-style-parent :"";
MSO-padding-alt: 0 cm 5.4pt 0 cm 5.4pt;
MSO-Para-margin: 0 cm;
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: grid type;
MSO-tstyle-rowband-size: 0;
MSO-tstyle-colband-size: 0;
Border: solid windowtext 1.0pt;
MSO-border-alt: solid windowtext. 5pt;
MSO-padding-alt: 0 cm 5.4pt 0 cm 5.4pt;
MSO-border-insideh:. 5pt solid windowtext;
MSO-border-insidev:. 5pt solid windowtext;
MSO-Para-margin: 0 cm;
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>

& Lt; body lang = ZH-CN style = 'tab-interval: 21.0pt '& gt;

<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> </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% '> media query ticket in the record </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: 8080'> <B> <span style = 'font-size: 10.5pt '> query No: <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> </u> <Span
Lang = en-US> <span style = 'mso-spacerun: Yes'> </span> query Date: <u>
<Span style = 'mso-spacerun: Yes; font-size: 10.5pt '> </span> <Span
Style = 'mso-spacerun: Yes'> <% = searchdate %> </span> </u> _ <O: P> </O: p> </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: 0 cm 5.4pt 0 cm 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: 0 cm 5.4pt 0 cm 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 '> daily report No. <Span
Lang = en-US> <O: P> </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: 0 cm 5.4pt 0 cm 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 '> area <Span
Lang = en-US> <O: P> </span> </B> </P>
</TD>
<TD width = 72 style = 'width: 5420.pt; Border: solid windowtext 1.0pt; border-left:
None; MSO-border-left-alt: solid windowtext. 5pt; MSO-border-alt: solid windowtext. 5pt;
Padding: 0 cm 5.4pt 0 cm 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 '> road section name <Span
Lang = en-US> <O: P> </span> </B> </P>
</TD>
<TD width = 36 style = 'width: 2720.pt; Border: solid windowtext 1.0pt; border-left:
None; MSO-border-left-alt: solid windowtext. 5pt; MSO-border-alt: solid windowtext. 5pt;
Padding: 0 cm 5.4pt 0 cm 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: 36366pt; Border: solid windowtext 1.0pt; border-left:
None; MSO-border-left-alt: solid windowtext. 5pt; MSO-border-alt: solid windowtext. 5pt;
Padding: 0 cm 5.4pt 0 cm 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 '> Format <Span
Lang = en-US> <O: P> </span> </B> </P>
</TD>
<TD width = 48 style = 'width: 36366pt; Border: solid windowtext 1.0pt; border-left:
None; MSO-border-left-alt: solid windowtext. 5pt; MSO-border-alt: solid windowtext. 5pt;
Padding: 0 cm 5.4pt 0 cm 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 '> level <Span
Lang = en-US> <O: P> </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: 0 cm 5.4pt 0 cm 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 '> detailed location <Span
Lang = en-US> <O: P> </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: 0 cm 5.4pt 0 cm 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: 0 cm 5.4pt 0 cm 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> </P>
</TD>
<TD width = 72 style = 'width: 5420.pt; 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: 0 cm 5.4pt 0 cm 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> </P>
</TD>
<TD width = 36 style = 'width: 2720.pt; 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: 0 cm 5.4pt 0 cm 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: 36366pt; 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: 0 cm 5.4pt 0 cm 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> </span> </P>
</TD>
<TD width = 48 style = 'width: 36366pt; 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: 0 cm 5.4pt 0 cm 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> </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: 0 cm 5.4pt 0 cm 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> </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 '> sales person </span> </B> <span style = 'font-size: 9.0pt' >:< Span
Lang = en-US> <% = username %> <B> tabulation time </B>: <% = now %> </span> <SPAN lang = en-US> </span> <Span
Lang = en-US style = 'font-size: 9.0pt '> <O: P> </span> </P>
</Div>

</Body>

</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.