CSS打印模式:仅在生成的Word文档的第一页上显示页眉和页脚 [英] css print mode: display header and footer only on first page of a generated word doc

查看:66
本文介绍了CSS打印模式:仅在生成的Word文档的第一页上显示页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm successfully generating word documents using html code with header and footer styled in css print mode, here is my code :

<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 应用于与第一种方法不同的页面的页眉和页脚:

What I would like to do is to display the header and footer only on first page. For that I have tried to apply visibility:hidden to the header and footer for pages different than first this way :

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

但是页眉和页脚仍显示在所有页面上...知道怎么做吗?

But the header and footer are still displayed on all pages... Any idea how to do the trick?

推荐答案

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

When comparing word generated html, I have missed one crucial mso css tag :

mso-first-header: url ...

代替 mso-header .

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

Together with that, the attribute mso-title-page must also be set to yes.

通过将这两者结合,您将获得想要的效果!

By combining these two you get the desired effect!

这篇关于CSS打印模式:仅在生成的Word文档的第一页上显示页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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