0

我创建了 2 个相同的 word 文档: test1 和 test2 它们都包含一个标题。

两个文档之间的唯一区别是页眉的下边距已向上移动,因此文本可以与页眉重叠。

然后我生成xml并进行比较。我注意到一个有趣的行,这两个文档都不同,结果如下:

测试1.xml:

<w:pgMar w:top="1417" w:right="1417" w:bottom="1417" w:left="1417" w:header="708" w:footer="708" w:gutter="0" />

测试2.xml:

<w:pgMar w:top="-49" w:right="1417" w:bottom="1417" w:left="1417" w:header="708" w:footer="708" w:gutter="0" />

所以w:pgMarw:top 已经从1417变为-49

现在我从 HTML 动态生成 W​​ord 文档,这里是使用的代码的主要部分:

<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>

谁能告诉我是否可以通过在某处集成注意到的 xml 参数或通过添加样式此代码来重现文本和标题之间的重叠效果?

4

1 回答 1

0

为 section1 设置一个负的上边距和为 mso-header 设置一个固定的边距可以解决这个问题:

@page Section1 {margin: -1cm 1cm 1cm 1cm; mso-header-margin: 1cm;}

正文现在与标题处于完全相同的级别,无论标题大小如何。

于 2016-02-04T08:10:57.137 回答