Title: Using JSP to implement Word, Excel format report print
Author: Evan
Date: 2003-08-21
Because MS Word and Excel support HTML text format, you can use Word or Excel to do a template, save it as a web page, and then change the HTML to JSP, you can dynamically fill the data part, you don't have to worry hard. Adjustment format
Word page As long as the JSP head is set as follows:
<% @ Page ContentType = "Application / Msword; Charset = GBK"%>
Excel is as follows:
<% @ Page ContentType = "Application / VND.MS-Excel; Charset = GBK"%>
Using this method The client must have Office software installed, and the user will open this page directly in IE when the user is accessible.
This method advantage is that template design, convenient adjustment, no need to use complex POI or JXL technology on server-side, there is no need to use ActiveX control technology, safer, more secure, and easy to implement better printing effects on the client.
Microsoft About Server Dynamically Create Information of Office Documents (ASP Example):
http://support.microsoft.com/default.aspx?scid=kb;n-us;301044&
Simple example:
Use Word to create a document, draw forms as follows:
----------------------------
| Username | Real Name | Gender |
----------------------------
| GUEST | Passenger | Male |
----------------------------
Saved as the web page test.htm, renamed.htm to Test.jsp, modify it
Guest, passerby, male is dynamically inquiry from the database, as follows:
<% @ Page ContentType = "Application / Msword; Charset = GBK"%>
<% @ Page Import = "java.sql. *"%>
XMLns: w = "URN: Schemas-Microsoft-Com: Office: WORD"
XMLns = "http://www.w3.org/tr/rec-html40">
o: DocumentProperties>
xml>
w: Compatibility>
w: WordDocument>
xml>
/ * Font definitions * /
@ font-face
{Font-Family: Song;
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;
Text-align: Justify;
Text-Justify: Inter-Ideograph;
MSO-PAGINATION: NONE;
FONT-SIZE: 10.5pt;
MSO-BIDI-FONT-SIZE: 12.0pt;
Font-Family: "Times New Roman";
MSO-FAREAST-FONT-FAMILY: Song;
MSO-FONT-KERNING: 1.0pt;
/ * Page definitions * /
@PAGE
{MSO-PAGE-BORDER-SURROUND-HEADER: NO;
MSO-PAGE-BORDER-SURROUND-FOOTER: NO;
@Page Section1
{SIZE: 595.3pt 841.9pt;
Margin: 72.0pt 90.0pt 72.0pt 90.0pt;
MSO-HEADER-Margin: 42.55pt;
MSO-FOOTER-MARGIN: 49.6PT;
MSO-Paper-Source: 0;
Layout-grid: 15.6pt;
Div.section1
{Page: Section1;
->
style>
hEAD>
Border-left: none; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt '> Border-left: none; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt '> Border-top: none; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt '> td> None; border-bottom: solid windowtext .5pt; border-right: solid windowtext .5pt; MSO-BORDER-TOP-Alt: Solid WindowText .5pt; MSO-Border-Left-Alt: Solid WindowText .5pt; Padding: 0cm 5.4pt 0cm 5.4pt '> |