在动态生成的Word文档上创建文本重叠标题

时间:2016-02-02 18:31:57

标签: html ms-word header ms-office wordml

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

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

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

Test1.xml:

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

Test2.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:pgMar w:top已从1417更改为-49

现在我从HTML动态生成Word文档,这是所用代码的主要部分:

<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参数或通过添加样式来重现文本和标题之间的重叠效果吗?

1 个答案:

答案 0 :(得分:0)

为section1设置负上边距并为mso-header设置固定边距可解决此问题:

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

主要文本现在与标题完全相同,无论标题大小如何。