A simple solution for JSP report printing _jsp programming
Source: Internet
Author: User
1. The style of making reports in Word or Excel.
Excel's Row height and column width units cannot be represented in mm or cm.
needs to be calculated. Under 1024*768, the 1CM is about 38 pixels.
This is the benchmark for calculating and controlling the row and column positions of the report.
2. In Word, set "table--header row repeat."
In Excel, set the file--page Setup--sheet--print title.
3. Save as Web page, change suffix name "htm" as "jsp".
4. Word report file header is:
<% @page contenttype= "APPLICATION/MSWORD;CHARSET=GBK" language= "java"%>
The Excel report file header is:
<% @page contenttype= "APPLICATION/VND.MS-EXCEL;CHARSET=GBK" language= "java"%>
5. Define the print parameter variables in the header section of the file as follows (for example, in Excel):
<%
Number of record bars that need to be printed
int printrowcount=rowcount;
Number of record bars printed per page
int pagerowcount=16;
Number of blank lines that need to be printed on the last page
int loopnum=pagerowcount-printrowcount%pagerowcount;
The height of the print area, where 2 means the number of header rows 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 the XML tag in the [endif]--> tab, mainly setting the dynamic print area (for example, Excel):
<%
Out.print ("...).
"<x:ExcelName>" +
"<x:Name>Print_Area</x:Name>" +
"<x:SheetIndex>1</x:SheetIndex>" +
"<x:formula>=sheet1! $A $: $G $" +printareaheight+ "</x:Formula>" +
"</x:ExcelName>" +
...... ");
%>
7. Other code for JSP.
The following is the main loop print section (for example, in Excel):
<%
for (int i=1;i<=printrowcount; i++)
{
Out.print ("<tr>" <td> "+i+" </td></tr>); Have content
}
if (loopnum!=pagerowcount)//blank line print blank line to the last page
for (int j=1;j<=loopnum; j + +)
{
Out.print ("<tr><td> </td></tr>");//no content
}
%>
8. Test and continue to modify.
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.