Groups
Groups
Sign in
Groups
Groups
yuanhotel
Conversations
About
Send feedback
Help
JSP报表打印的一种简单解决方案
1 view
Skip to first unread message
星星
unread,
Aug 9, 2006, 6:52:56 AM
8/9/06
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to yuanhotel
1. 在Word或Excel中制作报表的样式。
Excel的行高和列宽单位无法用mm或cm表示。
需要计算。在1024*768下,1CM约为38像素。
以此为基准,可计算并控制报表的行列位置。
2. 在Word中设置"表格??标题行重复"。
在Excel中设置"文件??页面设置??工作表??打印标题"。
3. 另存为网页,改后缀名"htm"为"jsp"。
4. Word报表文件头为:
<%@page contentType="application/msword;charset=GBK"
language="java"%>
Excel报表文件头为:
<% @page contentType="application/vnd.ms-excel;charset=GBK"
language="java"%>
5.
在文件头部分定义打印参数变量如下(以Excel为例):
<%
//需要打印的记录条数
int PrintRowCount=RowCount;
//每页打印的记录条数
int PageRowCount=16;
//最后一页需要打印的空行的数目
int LoopNum=PageRowCount-PrintRowCount%PageRowCount;
//打印区域的高度,其中2的意思是每页需要重复的标题行的数目
int
PrintAreaHeight=(PrintRowCount%PageRowCount==0)?PrintRowCount+2:PrintRowCount+LoopNum+2;
%>
6. 在<style></style>后,改动<!--[if gte mso
9]与<![endif]-->标签中的XML标签内容,主要是设置动态打印区域(以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. JSP其他编码。
下面是主体循环打印部分(以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. 测试并继续修改
Reply all
Reply to author
Forward
0 new messages