用C#读取docx文件

it2022-05-09  34

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引用!!!

 

 

转载于:https://www.cnblogs.com/chenlhuaf/archive/2008/05/15/1198530.html

相关资源:读取word文本

最新回复(0)