A simple solution for JSP report printing

Source: Internet
Author: User
Tags header

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):

<%
//需要打印的记录条数
int PrintRowCount=RowCount;
//每页打印的记录条数
int PageRowCount=16;
//最后一页需要打印的空行的数目
int LoopNum=PageRowCount-PrintRowCount%PageRowCount;
//打印区域的高度,其中2的意思是每页需要重复的标题行的数目
int PrintAreaHeight=(PrintRowCount%PageRowCount==0)?PrintRowCount+2:PrintRowCount+LoopNum+2;
%>

6. After , change the!--[if GTE MSO 9] and! [XML tag content in the endif]--> tab, mainly setting the dynamic print area (for example, in Excel):

<%
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>"+
...... ");
%>

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>"); //有内容
}
if (LoopNum!=PageRowCount) //有空行则打印空行补齐最末一页
for (int j=1;j<=LoopNum; j++)
{
out.print("<tr><td> </td></tr>");//无内容
}
%>

8. Test and continue to modify.

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.