c# 读取docx文件示例代码

来源:互联网 发布:mac如何退出终端 编辑:程序博客网 时间:2024/04/29 20:24

用C#读取docx文件实例代码实例代码如下:
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IO; 
using System.IO.Packaging; 
using System.Xml; 

namespace ReadDocx 

class Program 

static void Main(string[] args) 

string path = "a.docx"; 
using (Package package = Package.Open(path)) 

Uri docxUri = new Uri("/word/document.xml", UriKind.Relative); 

PackagePart docxPart = package.GetPart(docxUri); 

XmlDocument docxXmlDocument = new XmlDocument(); 

docxXmlDocument.Load(docxPart.GetStream()); 

Console.WriteLine(docxXmlDocument.InnerText.ToString()); 






记得要导入WindowsBase引用!!!