是什么让Microsoft-Word生成的HTML文档代码如此之大?

时间:2015-05-25 11:32:18

标签: html ms-word

下面是一个简单的W3C验证代码,用于打印" Hello World":

<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>Hello</title>
</head>
Hello World
</html> 

但是当我使用MS Word做同样的事情时,生成的代码是449 lines为什么所有这些额外的行都出现在代码中?

3 个答案:

答案 0 :(得分:13)

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

Word保留元数据信息:

<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>xxxxxx</o:Author>
  <o:LastAuthor>xxxxx</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>0</o:TotalTime>
  <o:Created>2015-05-25T11:40:00Z</o:Created>
  <o:LastSaved>2015-05-25T11:40:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>1</o:Words>
  <o:Characters>11</o:Characters>
  <o:Company>Sopra Group</o:Company>
  <o:Lines>1</o:Lines>
  <o:Paragraphs>1</o:Paragraphs>
  <o:CharactersWithSpaces>11</o:CharactersWithSpaces>
  <o:Version>12.00</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->

Word添加css样式:

<style>
<!--
 /* Font Definitions */
 @font-face
    {font-family:"Cambria Math";
    panose-1:2 4 5 3 5 4 6 3 2 4;
    mso-font-charset:0;
    mso-generic-font-family:roman;
    mso-font-pitch:variable;
    mso-font-signature:-536870145 1107305727 0 0 415 0;}
@font-face
    {font-family:Calibri;
    panose-1:2 15 5 2 2 2 4 3 2 4;
    mso-font-charset:0;
    mso-generic-font-family:swiss;
    mso-font-pitch:variable;
    mso-font-signature:-536870145 1073786111 1 0 415 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
    {mso-style-unhide:no;
    mso-style-qformat:yes;
    mso-style-parent:"";
    margin-top:0cm;
    margin-right:0cm;
    margin-bottom:10.0pt;
    margin-left:0cm;
    line-height:115%;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-fareast-font-family:Calibri;
    mso-fareast-theme-font:minor-latin;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;
    mso-bidi-font-family:"Times New Roman";
    mso-bidi-theme-font:minor-bidi;
    mso-fareast-language:EN-US;}
.MsoChpDefault
    {mso-style-type:export-only;
    mso-default-props:yes; ......

Word使用css样式:

<p class=MsoNormal>Hello World</p>

如果您将来需要修改此信息,则需要保留此信息。如果您正在进行简单导出,则可以删除所有元数据。

答案 1 :(得分:7)

正如this link中所述,代码是为MS Office目的而添加的;除此之外,它还可以让您更轻松地在Word中继续编辑文档。我收集的大部分膨胀都只是布局和文档信息。我将发布相关报价以供将来参考链接腐烂。

  

[...]原来这些HTML文件是由Microsoft Word创建的!由于一个   一系列不同的网页设计和设计师多年来,   以及营销部门的健康编辑,1英寸   我们创建或修改了客户当前网站的4个网页   使用Microsoft Word!

     

当我们滚动浏览HTML文件时,我们看到了大量的额外内容   没有普通网络浏览器会解释的数据。一点   研究为我们解释了它。 Microsoft允许您保存文档   作为HTML文件。他们还希望您能够打开HTML文件   使用Microsoft Office创建并继续编辑它   像普通文件一样。由于Microsoft Office有各种各样的   HTML和CSS不支持的功能允许Office保留   编辑之间HTML文件中的某些信息。

     

存储的一些数据很明显:文档创建时   由谁,谁做了什么编辑时,段数等。其他   不太明显的数据,如VML,DHTML行为,列和页面   间距,Word样式信息,嵌入式对象数据等等   也存储在文件中。所有这些Office特定数据都是   存储在HTML文件中并包含在特殊条件内   评论,例如<!--[if gte mso 9]。这隐藏了内容   其他阅读HTML的程序。

正如Adriano Repetti指出的那样,有一些代码可以处理旧版本的Office。

<!--[if gte mso 9]> ...
<!--[if gte mso 10]> ...

检查MS Office版本的兼容性以确定布局。 应该提一下,在Word中编辑HTML不是我推荐的。永远。

尝试 NetBeans ,它是免费的,真棒:) 我听起来像汽车推销员...... *抱怨*

答案 2 :(得分:1)

您看到的额外代码包括:

  1. 使用字体的字体链接。
  2. O信息(文档属性),用于存储作者,日期字,计数等信息。
  3. Word Doc设置&amp;数学,这包括诸如字距调整(字母之间的空格),语言输入以及通常与页面和页面相关的许多其他设置之类的内容。内容布局。
  4. 最终这会影响您在页面上看到的内容,使其看起来与您的单词文档类似,并保留背景信息,如字数统计等。