A simple solution of JSP report printing


1. Make report style in word or excel.
Excel row height and column width cannot be expressed in mm or cm.
It needs to be calculated. At 1024 * 768, 1cm is about 38 pixels.
Based on this, the row and column positions of the report can be calculated and controlled.
2. Set “table – Title row repeat” in word.
Set “file page setup worksheet print title” in Excel.
3. Save as a web page and change the suffix “HTM” to “JSP“.
4. The header of word report file is:
<%@page contentType=”application/msword;charset=GBK” language=”java”%>
The header of excel report file is:
<% @page contentType=”application/vnd.ms-excel;charset=GBK” language=”java”%>
5. 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 blank lines to print on the last page
int LoopNum=PageRowCount-PrintRowCount%PageRowCount;
//The height of the print area, where 2 means the number of header lines that need to be repeated per page
int PrintAreaHeight=(PrintRowCount%PageRowCount==0)?PrintRowCount+2:PrintRowCount+LoopNum+2;
6. After < style > < / style >, change <–[ If GTE MSO 9] and <[ The content of XML tag in ENDIF] > > tag is mainly to set the dynamic printing area (take excel as an example)
out.print(” ……
…… “);
7. Other coding of JSP.
The following is the main cycle printing part (take excel as an example)
for (int i=1;i<=PrintRowCount; i++)
out.print(“<tr>”<td>”+i+”</td></tr>”); // There is content
if (LoopNum!= Pagerowcount) / / if there are blank lines, the last page will be filled with blank lines
for (int j=1;j<=LoopNum; j++)
out.print(“<tr><td> </td></tr>”);// No content
8. Test and continue to modify.