Title: A simple solution for JSP RePort Printing
Keyword: JSP report
Author: jrq
Abstract: MS Office is a simple solution for JSP report output and printing. Make a memo.
Link: http://blog.csdn.net/jrq/archive/2005/10/21/510523.aspx
Body:
1. Create a report style in word or Excel.
The unit of Row Height and column width in Excel cannot be expressed in mm or cm, which must be calculated.
The default Row Height in an Excel worksheet is 14.25 (19 pixels), and the default column width is 8.38 (72 pixels ).
According to the calculation, 1CM is about 38 pixels.
Based on this, you can calculate and control the row and column positions of the output report.
2. Set "table-duplicate header row" in word ".
In Excel, set "file-page settings-worksheet-Print Title ".
After setting, the title of each page is automatically repeated when the report is printed.
This is a function provided by the ms_office tool :)
3. Save it as a web page and change the suffix "htm" to "jsp ".
In this way, you can directly edit the JSP file.
4. the JSP file header of the word report is:
<% @ Page contenttype = "application/MSWord; charset = GBK" Language = "Java" %>
The JSP file header of an Excel report is:
<% @ Page contenttype = "application/vnd. MS-Excel; charset = GBK" Language = "Java" %>
5. Edit the JSP file and define the print parameter variables in the file header as follows (take excel as an example ):
<%
// Number of records to be printed
Int printrowcount = rowcount;
// Number of records printed per page
Int pagerowcount = 16;
// The number of empty rows to be printed on the last page
Int loopnum = pagerowcount-printrowcount % pagerowcount;
// Print the height of the area. 2 indicates the number of header rows that need to be repeated on each page.
Int printareaheight = (printrowcount % pagerowcount = 0 )? Printrowcount + 2: printrowcount + loopnum + 2;
%>
6. After <style> </style>, modify <! -- [If gte mso 9] and <! [Endif] --> the XML tag content in the tag, mainly to set the dynamic printing area (take excel as an example ):
<%
Out. Print ("......
"<X: excelname>" +
"<X: Name> print_area </X: Name>" +
"<X: sheetindex> 1 </X: sheetindex>" +
"<X: formula> = sheet1! $ A $1: $ G $ "+ printareaheight +" </X: formula> "+
"</X: excelname>" +
......");
%>
You can adjust the number of rows in the print area by controlling printareaheight.
7. Other JSP coding work.
The following section uses excel as an example to describe how to print the subject cyclically ):
<%
For (INT I = 1; I <= printrowcount; I ++)
{
Out. Print ("<tr>" <TD> "+ I +" </TD> </tr> "); // content available
}
If (loopnum! = Pagerowcount) // if there are empty rows, the blank rows are printed to fill in the last page.
For (Int J = 1; j <= loopnum; j ++)
{
Out. Print ("<tr> <TD> </tr>"); // NO content
}
%>
8. Test printing and modify the JSP file againCode.
Summary: The overall workflow is MS Office ---> HTML ---> JSP ---> MS Office.
Using the MS Office tool, the JSP report output is simply printed. Pai_^
However, the client user must install the MS Office tool.
Jrq
In the early morning of 2005.10.21