格式化一下用IE打印,高级的可以看看 iRepert(好像是这么写的)

解决方案 »

  1.   

    可能我说的不是很明白,就是在页面查询出来的数据列表有N 列,我怎样只打印其中的 M 列
    (M〈=N)如:    列名: A        B       C      D        E       F.........N
                     数值   4        8       9      5        8       7.........8
                            7        4       4      5        7       9.........9
                            ....................................................  
    我怎么按打印按钮,只打出 A  B  D 这三列的数据??? 
      

  2.   

    刚完成的具有分页显示打印功能的:
    <%@page contentType="text/html;charset=gb2312"%>
    <html>
    <head>
    <title>查询所有菜谱</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <style type="text/css">
    <!--
    .a {  font-family: "宋体"; color:blue; text-decoration:underline}
    .a:hover {  font-family: "宋体"; color:red; text-decoration:none}
    .b {  font-family: "宋体"; color:purple; text-decoration:underline}
    .b:hover {  font-family: "宋体"; color:purple; text-decoration:none}
    .style1 {
    color: #FFFFFF;
    font-weight: bold;
    }
    .style2 {font-size: 12px}
    .style3 {color: #FFFFFF; font-weight: bold; font-size: 12px; }
    .style4 {font-family: "宋体"; color: purple; text-decoration: underline; font-size: 12px; }
    .style5 {color: #FF0000}
    a:link {
    color: #FFCC00;
    text-decoration: none;
    }
    a:visited {
    text-decoration: none;
    color: #FFCC00;
    }
    a:hover {
    text-decoration: underline;
    }
    a:active {
    text-decoration: none;
    }
    -->
    </style>
    </head>
    <body bgcolor="#FFFFFF" text="#000000" bgproperties=fixed>
    <%@ page language="java" import="java.sql.*"%>
    <%
      String sql="select * from caipu order by companyname desc";  int pagesize=9; //每页显示的记录数
      int showpage=1;  //当前页码
      int RowCount=0; //记录总数
      int PageCount=0; //页的总数  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      Connection con=DriverManager.getConnection("jdbc:odbc:JSP");
      Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
      ResultSet rs;
      rs=stmt.executeQuery(sql);
      
      if(rs.next())
      {
      rs.last();
      RowCount=rs.getRow();
      PageCount=((RowCount%pagesize)==0?(RowCount/pagesize):(RowCount/pagesize)+1);
      String ToPage=request.getParameter("ToPage");
      if(ToPage!=null)
      {
      showpage=Integer.parseInt(ToPage);
      if(showpage>PageCount)
      {
      showpage=PageCount;
      }
      else if(showpage<=0)
      {
      showpage=1;
      }
      }
      rs.absolute((showpage-1)*pagesize+1);//????
      %>
      <form action="add.jsp" method="post">
          <table width="992" height="22" border="0" align="center">
            <tr>
              <td width="179"><span class="style2">个人用户:<b><font size=3 color=red><%=(String)session.getValue("uid")%></font></b></span></td>
              <td width="573"><span class="style2">在线订餐 ◎ 订餐管理 ◎ 订单查询 ◎ 帮助中心 ◎ 首页 </span></td>
            </tr>
          </table>
          <hr width="1000" noshade>
          <div align="left"><span class="style2">您现在的位置: 首页 &gt; <a href="per_main.jsp">个人会员管理专区</a> &gt;在线订餐专区  </span></div>   
          <div align=center class=style2>符合关键字的相关记录共有<font color=red><%=RowCount%></font>条,共显示<font color=red><%=PageCount%></font>页,当前是第<font color=red><%=showpage%></font>页</div>
      <table width="80%" align="center" cellspacing=2>
      <tr bgcolor="#FFCC00"> 
       <td width="4%" height="19"> 
        <div align="center" class="style1 style2">序号</div>    </td>
      <td width="10%" height="19"> 
        <div align="center" class="style1 style2">快餐店名称</div>    </td>
        <td width="8%" height="19"> 
        <div align="center" class="style3">菜名</div>    </td>
        <td width="8%" height="19"> 
        <div align="center" class="style3">价钱</div>    </td>
        <td width="9%" height="19"> 
        <div align="center" class="style3">送货范围</div>    </td>

     <td width="15%" height="19"> 
        <div align="center" class="style3">发布日期</div>    </td>

    <td width="32%" height="19"> 
        <div align="center" class="style3">简介</div>    </td> <td width="5%" height=19> 
        <div align="center" class="style3">订购</div>   </td>
     
    </table>
    <%
    String id=rs.getString("caipuID");
        int j=0;
    for(int i=0;i<pagesize;i++)
      {
    String k;
      %>
      <table width="80%" align="center" cellpadding=2 >
      <tr bgcolor=#F0EEEC> 
      <td width="4%" height="19">
       <div align="center" class="style2"><%=id=rs.getString("caipuID").trim()%></div></td>
      <td width="10%" height="19"> 
        <div align="center" class="style2"><b><span class="style5"><%=rs.getString("companyname")%></span></b></div>    </td>
        <td width="8%" height="19"> 
        <div align="center" class="style2"><%=rs.getString("caiming").trim()%></a></div>    </td>
    <td width="8%" height="19"> 
        <div align="center" class="style2">¥<%=rs.getString("jiaqian").trim()%>.00元</a></div>    </td>
        <td width="9%" height="19"> 
        <div align="center" class="style2"><%=rs.getString("scope").trim()%></div>    </td>
     
     <td width="15%" height="19"> 
        <div align="center" class="style2"><%=rs.getString("riqi").trim().substring(0,11)%></div> </td>

    <td width="32%" height="19"> 
        <div align="center" class="style2"><%=rs.getString("jianjie").trim()%></div> </td>
     <td width="5%" height="19"> 
            <div align="center" class="style3"> <input type="checkbox" name="selected" value='<%=j%>'>
     <input type="hidden" name="id<%=j%>" value='<%=id%>'>
        </div>      </td>
      </tr>
    </table>
    <%
    j++;
     if(!rs.next()) break;
      }
      %>
      <hr width=780>
      <div align=center><input type=submit value="确定"></div>
      <form action=per_query.jsp method=post>
      <table align="center" cellspacing="8">
      <tr>
      <%
      if(showpage!=1)
      {
      %>
      <td><span class=style2><a href="per_query.jsp?ToPage=<%=1%>" class="b">第一页</a>|</span></td>
      <td><span class=style2><a href="per_query.jsp?ToPage=<%=showpage-1%>" class="b">上一页</a>|</span></td>
      <%
      }
      else
      {
      %>
      <td><span class=style2>第一页</span></td>
      <td><span class=style2>上一页</span></td>
      <%
      }
      if(showpage!=PageCount)
      {
    %>
    <td><span class=style2><a href="per_query.jsp?ToPage=<%=showpage+1%>" class="b">下一页</a>|</span></td>
    <td><span class=style2><a href="per_query.jsp?ToPage=<%=PageCount%>" class="b">最后一页</a></span></td>
    <%
      }
    else
      {
    %>
    <td><span class=style2>下一页</span></td>
                        <td><span class=style2>最后一页</span></td>
    <%
      }
    %>
    <td><span class=style2><font color=red><%=showpage%></font>/<font color=red><%=PageCount%></font></span></td>
    </tr>
    </table>
    </form>
    <p>
    <%
    rs.close();
        stmt.close();
    con.close();
                            }   //if(rs.next())语句的结束
    else //若找不到记录则输出以下语句
    {
    out.print("<br>"+"<div align=center>"+"<font color=red>"+"没有符合条件的记录"+"</font>"+"</div>"+"</br>");
    }
    %>
    </p>
    </form>
    </body>
    </html>
      

  3.   

    <style media="print">
    .noprint  { display: none }
    </style>
    上面的代码写在<head>中···
    <INPUT onclick="document.execCommand('print','true','true')" class="noprint" type="button" value="打印">然后在你不要打印的地方加一个 class="noprint"属性···
      

  4.   

    如果有时间请关注这两个贴子,谢谢哪位高手用JSP和XMLHTTP做过无刷新的三级以上的从数据库取数据的级联菜单,大家一起探讨一下
    http://community.csdn.net/Expert/topic/3592/3592696.xml?temp=.4974481
    分步注册中a.jsp,b.jsp均有文本框;b.jsp用history.back()返回,但a.jsp再次提交,b.jsp内容全部丢失 
    http://community.csdn.net/Expert/topic/3592/3592650.xml?temp=.6778223
      

  5.   

    谢谢 cgliang00() ,虽然我还不知道这些代码的意思,我去试试看.
      

  6.   

    如果查询出来的页面带有表头: a     b      c     d          “打印按钮”
                       内容:   。。  。。   。。  。。
                                。。  。。   。。  。。
                            共n页  上一页 下一页 我想按“打印按钮”后只把表格a,b,c,d的内容打印出来,而不显示分页这些内容,该怎么做?请大家给我点提示,或相关资料。
      

  7.   

    http://blog.csdn.net/qmei/archive/2005/04/11/342968.aspx
      

  8.   

    跳转到一个新的print页面吧,一般打印都这样作的,主要是调格式。数据可以从window.parent.forms[0].xx.value取得
      

  9.   

    谢谢querlang(编程浪子)的回复!!