将word文档转换为xml代码c#

问题描述:

如何将该word文档转换为如下所示的xml代码? 我有一个单词文档模板。将word文档转换为xml代码后,我会将我的数据表追加到body标签并生成word文档。请帮忙。 在我的应用程序中,使用Interop或其他某些dll来自定义文档没有可能性,所以我尝试这样。将word文档转换为xml代码c#

<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>Time</title> 
<!--[if gte mso 9]> 
<xml> 
<w:WordDocument> 
<w:View>Print</w:View> 
<w:Zoom>90</w:Zoom> 
<w:DoNotOptimizeForBrowser/> 
</w:WordDocument> 
</xml> 
<![endif]--> 
<style> 
<!-- /* Style Definitions */ 
@page Section1 
{size:8.5in 11.0in;  
margin:1.0in 1.25in 1.0in 1.25in ;  
mso-header-margin:.5in;  
mso-footer-margin:.5in; 
mso-paper-source:0; 
} 
div.Section1 {page:Section1;} 
--> 
</style> 
</head> 
<body lang=EN-US style='tab-interval:.5in'> 
<div class=Section1><h1>Time and tide wait for none</h1> 
<p style='color:red'><I>10/30/2014 5:37:16 PM</I></p> 
</div> 
</body> 
</html> 
+0

'.docx'文件已经包含XML中的内容。尝试改为扩展名为'.zip'并查看内容。 – 2014-10-30 12:20:52

+0

我相信,OpenXML库(也可以在NuGet中使用)可以解决您的问题(最近我用它来处理Excel文档) – 2014-10-30 12:22:06

+0

@ChristopheDeTroyer:是否可以更改扩展名?我无法将其更改为.zip。你试过了吗? – 2014-10-30 12:25:27

OpenXML SDK 2.5

让您操作Office文件。虽然SDK有点不清楚。

Some help on converting Office files to XML