我如何打印HTML表格。每页上的页眉和页脚 [英] how do i print HTML table. Header and footer on each page

查看:97
本文介绍了我如何打印HTML表格。每页上的页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有动态生成的html表。



我想要打印这个包含很多页面的表,但是当我使用window.print()时,它会打印成7页,8页。

我的问题是我需要每页上的页眉和页脚(A4大小)。



如何设置每页的页眉和页脚?



我使用的是asp.net C#。



我把页眉和页脚放在.aspx页面上,但问题是数据是动态绑定的,当我打印它们时,打印会在多个页面上进行(即4或5页取决于数据)。

所以页眉首页和页脚在最后一页我需要每页页眉和页脚。



请给我任何建议或另一种方法来执行此任务。

解决方案

如果您使用< thead>和< tfoot>页眉和页脚的元素,你可以使用



  thead  {  display    table-header-group;  } 

tfoot { display table-footer-group; }





to强制浏览器在每个页面上打印它们。


我尝试了Rick Bassham解决方案,它正在为我工​​作。



< pre lang =css> thead { display table-header-group; }
tfoot { display table-footer-group; }





 < span class =code-keyword><   body  >  
< 表格 >
< thead > < tr > < td > 您的标题在此处< / td > < / tr > < / thead >
< tbody >
< ; tr > < td >
此处的页面正文 - 只要它需要
< / td > < / tr >
< / tbody >
< tfoot > < tr > < td > 您的页脚到此处< / td > < / tr > < / tfoot >
< / table >
< / body >







如果您希望页眉和页脚仅显示在打印副本然后用这个





< style type =text / css>

@media print {

thead {display:table-header-group; }

tfoot {display:table-footer-group; }

}

@media screen {

thead {display:block; }

tfoot {display:block; }

}



< / style>


我遇到同样的问题要显示标题所有页面中的页脚,点击打印按钮上面的代码不能正常工作,我也试过了,



如果有人有替代选项请告诉我? / BLOCKQUOTE>

I have html table which is dynamically generated.

I want to print this table, which consists lot of pages, but when I used window.print() it's printing into 7, 8 pages.
My problem is I need Header and footer on each page (A4 size).

How can I set header and footer to each page?

I am using asp.net with C#.

I put header and footer on .aspx page but the problem is that data is binding dynamic, when I print them, the print goes on multiple pages (ie 4 or 5 pages depend on data).
So header come on first page and footer on last page I need header and footer on each page.

Please provide me any suggestion or alternate way to do this task.

解决方案

If you use the <thead> and <tfoot> elements for your header and footer, you can use

thead   {display: table-header-group;   }

tfoot   {display: table-footer-group;   }



to force the browser to print them on every page.


I tried Rick Bassham solution and it is working for me.

thead { display: table-header-group; }
tfoot { display: table-footer-group; }



<body>
<table>
   <thead><tr><td>Your header goes here</td></tr></thead>
   <tbody>
     <tr><td>
     Page body in here -- as long as it needs to be
     </td></tr>
   </tbody>
   <tfoot><tr><td>Your footer goes here</td></tr></tfoot>
</table>
</body>




If you want header and footer appear only on print copy then use this


<style type="text/css">
@media print {
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
@media screen {
thead { display: block; }
tfoot { display: block; }
}

</style>


I am having same problem to display header and footer in all pages while click on print button your above code is not working, I am tried it same,

If anyone having alternate option Please let me know ?


这篇关于我如何打印HTML表格。每页上的页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆