从.docx文件中获取数据,就像C#中的一个大字符串一样 [英] Get Data From .docx file like one big String in C#

查看:88
本文介绍了从.docx文件中获取数据,就像C#中的一个大字符串一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从C#代码的.docx文件中读取数据(如字符串).我浏览了一些问题,但不知道要使用哪个问题.

I want to read data - like string, from .docx file from C# code. I look through some of the issues but didn't understand which one to use.

我正在尝试使用ApplicationClass Application = new ApplicationClass();,但我得到了

I'm trying to use ApplicationClass Application = new ApplicationClass(); but I get t

错误:

类型'Microsoft.Office.Interop.Word.ApplicationClass'没有 定义的构造函数

The type 'Microsoft.Office.Interop.Word.ApplicationClass' has no constructors defined

我想从我的docx文件中获取全文,而不是单词!

And I want to get full text from my docx file, NOT SEPARATED WORDS !

foreach (FileInfo f in docFiles)
{
    Application wo = new Application();
    object nullobj = Missing.Value;
    object file = f.FullName;
    Document doc = wo.Documents.Open(ref file, .... . . ref nullobj);
    doc.Activate();
    doc. == ??    
}

我想知道如何从docx文件中获取全文吗?

I want to know how can I get whole text from docx file?

推荐答案

这就是我要从docx文件中提取整个文本的地方!

This Is what I want to extract whole text from docx file !

    using (ZipFile zip = ZipFile.Read(filename))
{
    MemoryStream stream = new MemoryStream();
    zip.Extract(@"word/document.xml", stream);
    stream.Seek(0, SeekOrigin.Begin); 
    XmlDocument xmldoc = new XmlDocument();
    xmldoc.Load(stream);
    string PlainTextContent = xmldoc.DocumentElement.InnerText;
}

这篇关于从.docx文件中获取数据,就像C#中的一个大字符串一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆