【问题标题】:css print mode: display header and footer only on first page of a generated word doccss 打印模式:仅在生成的 word doc 的第一页上显示页眉和页脚
【发布时间】:2016-02-16 21:50:55
【问题描述】:

我正在使用 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;}

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

【问题讨论】:

  • 尝试在 Word 中创建一个简单的示例文档,并为页眉/页脚激活“首页”选项 - 这是 Word 中的特定选项。然后将其保存为“往返”HTML 文件并查看 Word 希望您使用的内容。
  • 我已经尝试过了,但我得到的区别是很多 mso-list-id 标签...我没有看到任何表明页眉页脚的差异,尽管我使用了比较插件在记事本++中
  • 页眉/页脚与部分相关联。文档可能只有一个部分,其定义通常在文档末尾附近。也许这会帮助你找到它?
  • Cindy Meister 是对的。 Word 根据分节符处理页眉和页脚。这就是为什么您遇到无法取消选中“链接到最后一节”的错误的原因。进入并制作一个包含几页的文档并确保您制作了部分,然后查看代码,您将看到它如何处理每个部分。然后相应地添加 CSS。
  • 是的,我知道,但没有找到任何可以让我找到解决方案的东西。区别如下:mso-title-page:yes; (但我没有找到关于这个的任何文档)和 ms-list-id/mso-list-template-ids 十几次。

标签: html css ms-word wordml


【解决方案1】:

试试这个:

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; 

【讨论】:

  • 已经有一个 100% 有效的答案,你的答案开始不起作用,第二部分只是题外话
【解决方案2】:

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

mso-first-header: url ...

而不是mso-header

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

将这两者结合起来就可以得到想要的效果!

【讨论】:

    猜你喜欢
    • 2020-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 2018-12-28
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    相关资源
    最近更新 更多