html - 从 HTML 生成的 MS Word 文档中不需要的方块
问题描述
我正在使用本主题中的代码从 HTML 创建一个 MS Word 文档。经过一些调整后,它对我来说工作得很好,除了现在我在页眉和页脚的每一端都有正方形,请参见此处的图片。这些方块不能手动删除,我看不出是什么在创建它们。
要重现,只需创建一个 *.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'>© 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>
解决方案
找到了。我必须<div>
为每个页眉和页脚添加另一个块:
<div style='mso-element:header'>
<p class='MsoHeader'>
<span> <o:p></o:p></span>
</p>
</div>
并相应地
<div style='mso-element:footer'>
<p class='MsoFooter'>
<span> <o:p></o:p></span>
</p>
</div>
显然<o:p></o:p>
标签负责这些方块。
推荐阅读
- reactjs - 如何在下一个 js 中创建 url 别名并表达您通过 id 获取数据的帖子或用户?
- java - 我可以为多个 Web 操作只调用一次 PageFactory 实例吗?
- javascript - Sequelize 中的迁移在我自己的文件夹结构中
- android - 在 ARCore 中使用 ImageView 显示图像
- perl - 如何在 Perl 中实现断言?
- python - 如何索引,删除和计算列表中元素的所有实例?
- jquery - 如何在 onclick 事件之前触发 onchange 事件(Bootstrap 4 单选按钮)
- java - Selenium Webdriver (Java) - 如何解决动态文本和倒数计时器?
- python - 如何在我的 Tkinter GUI 应用程序中嵌入 SDL2 窗口?
- python - 整数不会附加到我的网格数组 - python