【问题标题】:unwanted squares in MS Word doc generated from HTML从 HTML 生成的 MS Word 文档中不需要的方块
【发布时间】:2021-02-05 00:49:37
【问题描述】:

我正在使用来自this topic 的代码从 HTML 创建一个 MS Word 文档。经过一些适应后,它对我来说工作正常,除了现在我在页眉和页脚see image here 的每一端都有正方形。这些方块无法手动移除,我看不出是什么在创建它们。

要重现,只需创建一个 *.doc 文件,使用 notepad++ 或 VS Code 等文本编辑器打开它,然后输入以下代码。之后用 MS Word 打开文件。

希望你们能帮我摆脱那些方块!

<html xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'
    xmlns:w='urn:schemas-microsoft-com:office:word' xmlns:m='http://schemas.microsoft.com/office/2004/12/omml'
    xmlns='http://www.w3.org/TR/REC-html40'>

<head>
    <meta charset='utf-8'/>
    <title></title>
    <style>
        @page {
            mso-page-orientation: portrait;
            margin: 1cm 1cm 1cm 1cm;
        }

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

        div.Section1 {
            page: Section1;
        }

        table.hdrftrtbl {
            margin: 0in 0in 0in 900in;
            width: 1px;
            height: 1px;
            overflow: hidden;
        }

        p.MsoHeadFoot,
        li.MsoHeadFoot,
        div.MsoHeadFoot,
        td.MsoHeadFoot {
            margin: 0;
            margin-bottom:1px;
            tab-stops: center 50% right 100%;
            font-size: 12.0pt;
        }
    </style>
</head>

<body>
    <br/>
    TODO: Actual content goes here

    <div class='Section1'>
        <table class='hdrftrtbl' border='0' cellspacing='0' cellpadding='0'>
            <tr>
                <!-- HEADER-tags -->
                <td class='MsoHeadFoot'>
                    <div style='mso-element:header' id='h1'>
                        <span style='mso-tab-count:2'>
                            <img src='logo.jpg' width="140" height="60">
                        </span>
                    </div>
                </td>
                <!-- end HEADER-tags -->
                <!-- FOOTER-tags -->
                <td class='MsoHeadFoot'>
                    <div style='mso-element:footer' id='f1'>
                        <span style='mso-tab-count:0'>&copy; company name</span>
                        <span style='mso-tab-count:1'>TODO: beginning from page 2</span>
                        <span style='mso-tab-count:1'></span>
                        page
                        <span style='mso-field-code:PAGE'></span>
                        of
                        <span style='mso-field-code:NUMPAGES'></span>
                    </div>
                </td>
                <!-- end FOOTER-tags -->
            </tr>
        </table>
    </div>
    
</body>

</html>

【问题讨论】:

    标签: html ms-word


    【解决方案1】:

    找到了。我必须为每个页眉和页脚添加另一个 &lt;div&gt; 块:

    <div style='mso-element:header'>
      <p class='MsoHeader'>
        <span>&nbsp;<o:p></o:p></span>
      </p>
    </div>
    

    因此

    <div style='mso-element:footer'>
      <p class='MsoFooter'>
        <span>&nbsp;<o:p></o:p></span>
      </p>
    </div>
    

    显然&lt;o:p&gt;&lt;/o:p&gt; 标签负责这些方块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 2014-07-24
      相关资源
      最近更新 更多