1. Create a report style in Word or Excel.
The Row Height and column width in Excel cannot be expressed in mm or cm.
Computing required. In 1024*768, 1CM is about 38 pixels.
Based on this, you can calculate and control the row and column positions of reports.
2. Set "table-duplicate header row" in Word ".
In Excel, set "file-page settings-worksheet-Print Title ".
3. Save it as a web page and change the suffix "htm" to "jsp ".
4. The 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 file header section 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>" +
......");
%>
7. Other JSP codes.
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 and continue modification.