如何在通过HTML生成Word文档时实现仅从第二页开始显示页脚
实现页脚仅从第二页显示的修改方案
你需要做3处调整即可实现需求,不需要替换原有mso-header/mso-footer配置,仅需新增首页专属配置:
- 在
@page Section1的样式规则中添加mso-title-page: yes;,该属性的作用是告诉Word当前节包含独立标题页(也就是你的第一页封面),标题页可使用单独的页眉页脚规则。 - 同样在
@page Section1中新增两条首页页眉页脚的指向配置,指定首页使用空的页眉页脚:mso-first-header: h0;mso-first-footer: f0;
- 在页眉页脚定义区域新增两个内容为空的页眉页脚元素,对应上一步配置的
h0和f0ID。
修改后的完整代码如下:
<head> <style type="text/css" media="print"> @page Section1 { size:8.3in 11.7in; mso-footer:f1; mso-header:h1; /* 新增以下3行配置 */ mso-title-page: yes; mso-first-header: h0; mso-first-footer: f0; margin:0.0in 0.6in 0.0in 0.6in; mso-header-margin:0.0in; mso-footer-margin:0.0in; } div.Section1{ page:Section1; } p.MsoFooter, li.MsoFooter, div.MsoFooter { mso-pagination:widow-orphan; } </style> </head> <body> <!-- Content --> <div class="Section1"> <!-- Cover Page 1 --> <div class="coverP"> Cover page text goes here </div> <br clear="all" style="page-break-before:always" /> <!-- Page 2 Starts --> <div> Page 2 goes here with footer (pg#2 and logo) </div> <br clear="all" style="page-break-before:always" /> <!-- Page 3 Starts --> <div> page 3 go here with footer (pg#2 and logo) </div> <!---------- HEADER AND FOOTER SECTIONS ---------------> <!-- 新增空的首页页眉页脚 --> <div style="mso-element:header" id="h0"> <!-- 无内容,首页不显示页眉 --> </div> <div style="mso-element:footer" id="f0" > <!-- 无内容,首页不显示页脚 --> </div> <div style="mso-element:header" id="h1"> <table>...</table> </div> <div style="mso-element:footer" id="f1" > <table>...</table> </div> </div> </body> </html>
内容的提问来源于stack exchange,提问作者Thaís C.
相关产品推荐
相关产品推荐

