【发布时间】: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 十几次。