繁体   English   中英

css打印模式:仅在生成的单词doc的第一页上显示页眉和页脚

[英]css print mode: display header and footer only on first page of a generated word doc

我使用html代码成功生成word文档,页眉和页脚在css打印模式下设置样式,这是我的代码:

<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Mon document</title>
<meta charset=\"UTF-8\" />
<!--[if gte mso 9]>
<xml><w:WordDocument><w:View>Print</w:View><w:Zoom>100</w:Zoom><w:DoNotOptimizeForBrowser/></w:WordDocument></xml>
<![endif]-->
<link rel=File-List href=\"mydocument_files/filelist.xml\">
<style><!-- 
@page
{
    size:21cm 29.7cmt;  /* A4 */
    margin:1cm 1cm 1cm 1cm; /* Margins: 2.5 cm on each side */
    mso-page-orientation: portrait;  
    mso-header: url(\"mydocument_files/headerfooter.htm\") h1;
    mso-footer: url(\"mydocument_files/headerfooter.htm\") f1;  
}
@page Section1 { }
div.Section1 { page:Section1; }
p.MsoHeader, p.MsoFooter { border: none; }
--></style>
</head>
<body>
<div class=Section1>
 my content
</div>
</body>
</html>

我想要做的是只在第一页显示页眉和页脚。 为此我尝试应用visibility:hidden到页眉和页脚的页面不同于第一种方式:

p.MsoHeader, p.MsoFooter { border: none; visibility: hidden;}
p.MsoHeader :first, p.MsoFooter :first { border: none; visibility: visible;}

但页眉和页脚仍然显示在所有页面上...任何想法如何做到这一点?

试试这个:

p.MsoHeader, p.MsoFooter { border: none; display: none;}
p.MsoHeader :first, p.MsoFooter :first { border: none; display: block;}

或者,如果这不起作用,最好不要在第一次播放中调用页眉和页脚,所以只需从不希望页眉和页脚出现的页面中删除这两行。 :

mso-header: url(\"mydocument_files/headerfooter.htm\") h1;
mso-footer: url(\"mydocument_files/headerfooter.htm\") f1; 

比较单词生成的html时,我错过了一个关键的mso css标签:

mso-first-header: url ...

而不是mso-header

与此同时,属性mso-title-page也必须设置为yes

通过组合这两个,你可以获得理想的效果!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM