【问题标题】:Office HTML Word headerOffice HTML Word 标题
【发布时间】:2012-03-09 13:51:36
【问题描述】:

我在第一页生成带有标题的“Word 文档”作为 HTML 代码。 <style> 标签包含:

@page Section {
    size:8.5in 11.0in;
    margin: 0.7in 0.9in 0.7in 0.9in;
    mso-header-margin: 0.0in;
    mso-footer-margin: 0.0in;
    mso-title-page: yes;
    mso-first-header: fh1;
    mso-paper-source: 0;
}
div.Section {
    page: Section;
}

<body>:

<div class="Section" style="font-family: Verdana, sans-serif;">
    <![if supportFields]>
        <div style="mso-element:header" id="fh1">
            <p class="MsoHeader">
                header
            </p>
        </div>
    <![endif]>
</div>

它在标题和文档的主体中显示“标题”文本。我发现的资源(http://techsynapse.blogspot.com/2007/03/generating-word-document-dynamically.html 和http://www.pbdr.com/ostips/wordfoot.htm)说如果不使用额外的头文件就无法避免这种影响这不是我的选择。

我的问题是:您知道该问题的任何解决方法吗?如何隐藏主文档中标题的出现,但将其保留在页面顶部的位置?提前感谢您的任何建议。

【问题讨论】:

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


    【解决方案1】:

    这对我有用:

    <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></title>
    
    <!--[if gte mso 9]><xml>
     <w:WordDocument>
      <w:View>Print</w:View>
      <w:Zoom>90</w:Zoom>
    </w:WordDocument>
    </xml><![endif]-->
    
    
    <style>
    p.MsoFooter, li.MsoFooter, div.MsoFooter
    {
        margin:0in;
        margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        tab-stops:center 3.0in right 6.0in;
        font-size:12.0pt;
    }
    <style>
    
    <!-- /* Style Definitions */
    
    @page Section1
    {
        size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;
        mso-header-margin:.5in;
        mso-footer-margin:.5in;
        mso-title-page:yes;
        mso-header: h1;
        mso-footer: f1;
        mso-first-header: fh1;
        mso-first-footer: ff1;
        mso-paper-source:0;
    }
    
    
    div.Section1
    {
        page:Section1;
    }
    
    table#hrdftrtbl
    {
        margin:0in 0in 0in 900in;
        width:1px;
        height:1px;
        overflow:hidden;
    }
    -->
    </style></head>
    
    <body lang=EN-US style='tab-interval:.5in'>
    <div class=Section1>
    
    <p> CONTENT </p>
    
    <br/>
        <table id='hrdftrtbl' border='0' cellspacing='0' cellpadding='0'>
        <tr><td>
    
        <div style='mso-element:header' id=h1 >
            <p class=MsoHeader ><p>&nbsp;HEADER-TITLE</p></p>
        </div>
    
        </td>
        <td>
        <div style='mso-element:footer' id=f1>
    
            <p>&nbsp;FOOTER-TITLE</p>
            <p class=MsoFooter>
            <span style=mso-tab-count:2'></span>
                Page <span style='mso-field-code: PAGE '><span style='mso-no-proof:yes'></span></span> of <span style='mso-field-code: NUMPAGES '></span>
            </p>
    
        </div>
    
    
    
        <div style='mso-element:header' id=fh1>
    
        <p class=MsoHeader><span lang=EN-US style='mso-ansi-language:EN-US'>&nbsp;FIRST-HEADER-TITLE<o:p></o:p></span></p>
    
        </div>
    
        <div style='mso-element:footer' id=ff1>
    
        <p class=MsoFooter><span lang=EN-US style='mso-ansi-language:EN-US'>&nbsp;FIRST-FOOTER-TITLE<o:p></o:p></span></p>
    
        </div>
    
        </td></tr>
        </table>
    
    
    </body></html>
    

    【讨论】:

    • 它总是为我显示一个额外的空间。
    • 无法从服务器生成标头中的图像,但在本地主机上它工作正常。为图像生成的路径在服务器上也很好。你能告诉我我缺少什么,在 localhost 图像被添加到 word 文件中,但在服务器上它没有。 注意 我在本地机器上安装了 ms-office,但在服务器上没有。
    • 如何删除页眉部分的空白?当我在单词中查看它时,一切都很好,但是当打印出来时,会添加空白空间......有什么想法吗?
    【解决方案2】:

    要更新 vencedor 的上述答案并删除添加到页眉/页脚图像/文本中的额外空字符编码,您可以执行以下操作:

    <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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    
    <!--[if gte mso 9]><xml>
     <w:WordDocument>
      <w:View>Print</w:View>
      <w:Zoom>100</w:Zoom>
    </w:WordDocument>
    </xml><![endif]-->
    <style>
    <!-- /* Style Definitions */
    p.MsoHeader, li.MsoHeader, div.MsoHeader{
        margin:0in;
        margin-top:.0001pt;
        mso-pagination:widow-orphan;
        tab-stops:center 3.0in right 6.0in;
    }
    p.MsoFooter, li.MsoFooter, div.MsoFooter{
        margin:0in 0in 1in 0in;
        margin-bottom:.0001pt;
        mso-pagination:widow-orphan;
        tab-stops:center 3.0in right 6.0in;
    }
    .footer {
        font-size: 9pt;
    }
    @page Section1{
        size:8.5in 11.0in;
        margin:0.5in 0.5in 0.5in 0.5in;
        mso-header-margin:0.5in;
        mso-header:h1;
        mso-footer:f1;
        mso-footer-margin:0.5in;
        mso-paper-source:0;
    }
    div.Section1{
        page:Section1;
    }
    table#hrdftrtbl{
        margin:0in 0in 0in 9in;
    } 
    -->
    </style>
    <style type="text/css" media="screen,print">
    body {
        font-family: "Calibri", "Verdana","HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
        font-size:12pt;
    }
    pageBreak {
      clear:all;
      page-break-before:always;
      mso-special-character:line-break;
    }
    </style>
    </head>
    <body style='tab-interval:.5in'>
    <div class="Section1">
    
    Something page 1
    <div class="pageBreak"></div>
    Something page 2
    <div class="pageBreak"></div>
    
    <table id='hrdftrtbl' border='1' cellspacing='0' cellpadding='0'>
            <tr>
                <td>
                    <div style='mso-element:header' id="h1" >
                        <p class="MsoHeader">
                            <table border="0" width="100%">
                                <tr>
                                    <td>
    
                                        YOUR_HEADER IMAGE/TEXT
    
                                    </td>
                                </tr>
                            </table>
                        </p>
                   </div>
              </td>
              <td>
                <div style='mso-element:footer' id="f1">
                    <p class="MsoFooter">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td align="center" class="footer">
                                YOUR_FOOTER_TEXT
                                    <g:message code="offer.letter.page.label"/> <span style='mso-field-code: PAGE '></span> of <span style='mso-field-code: NUMPAGES '></span>
                                </td>
                            </tr>
                        </table>
                    </p>
                </div>
            </td>
        </tr>
        </table>
      </div>
    </body>
    </html>
    

    这现在包括用于页眉和页脚段的完整 CSS 组件。

    实际上删除额外编码的技巧是在 MsoFooter 和 MsoHeader 部分中声明另一个表。

    【讨论】:

    • 非常有用,谢谢!你知道是否有任何属性可以让正文重叠在标题部分?就像现在一样,正文始终位于标题最后一行的下方。
    • 看看这里sebsauvage.net/wiki/doku.php?id=word_document_generation。我们最终使用了 mhtml 模型(在最底部),它运行良好。当前方法的问题是隐藏表,在我们的例子中,当最后一页下降一半以上时,它会创建一个额外的页面。
    • 是的,这正是我成功使用的教程。但我没有设法让文本与标题重叠。另一种选择是使用水印而不是标题,但这意味着将标题 html 转换为图片,这也不容易:/ 所以如果你有一个技巧可以让正文从页面顶部开始,即使有一个标题,那会很棒:)
    • 有什么办法可以去掉页尾的隐藏表格/去掉多余的空白页?
    • 根据上述sebsauvage.net/wiki/lib/exe/… 评论 - 唯一的解决方法是完全更改 mhtml
    【解决方案3】:

    this answer 后面的多余空格可以隐藏

    限制桌子的高度:

    <table id='hrdftrtbl' border='1' cellspacing='0' cellpadding='0' style='margin-left:50in;'>
        <tr style='height:1pt;mso-height-rule:exactly'>
                <td>
                    <div style='mso-element:header' id="h1" dir="ltr" >
                        <p class="MsoHeader">
                            <table border="0" width="100%" style="margin-bottom: 15pt;">
                                <tr>
                                    <td width="50%">
                                    Some text goes here
                                    </td>
                                    <td width="50%" style="text-align: left">
                                        <img height="auto" src="">
                                    </td>
                                </tr>
                            </table>
                        </p>
                   </div>
              </td>
              <td>
                <div style='mso-element:footer' id="f1">
                    <p class="MsoFooter">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td align="center" class="footer" dir="ltr">
                                    <g:message code="offer.letter.page.label"/> <span style='mso-field-code: PAGE '></span> / <span style='mso-field-code: NUMPAGES '></span>
                                </td>
                            </tr>
                        </table>
                    </p>
                </div>
            </td>
        </tr>
        </table>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多