阅读Word文档使用C#

阅读Word文档使用C#

本文介绍了阅读Word文档使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要开始从一个特定的角度看一个word文档。
这关键词是从下拉组合框中拍摄。
关键字是一样的东西[等等等等,等等,001]



所以,我只需要阅读该关键字下一个标题内容...



我用这个来逐行读取
标题编号和线路,但标题NUM notworking

 字符串headNum = objparagraph.Range.ListFormat.ListString; 
串SLINE = objparagraph.Range.Text;


解决方案

 词。应用字=新Word.Application(); 
Word.Document DOC =新Word.Document();
目标文件名= @C:\wordFile.docx
//定义一个物体传递到API缺少的参数
对象缺少= System.Type.Missing;
DOC = word.Documents.Open(REF文件名,
参考失踪,失踪参考,参考失踪,失踪参考,
参考失踪,失踪参考,参考失踪,失踪参考,
裁判失踪,失踪参考,参考失踪,失踪参考,
参考失踪,失踪参考,参考失踪);
串ReadValue =的String.Empty;
//激活文件
doc.Activate();

的foreach(Word.Range tmpRange在doc.StoryRanges)
{
ReadValue + = tmpRange.Text;
}


I need to start reading a word document from a specific point.That key word is taken from a dropdown combo box.The keyword is something like [blah blah, blah, 001]

So, I need to read only the content from that keyword to next heading ...

I used this to read heading numbers and line by linebut heading num notworking

string headNum = objparagraph.Range.ListFormat.ListString;
string sLine = objparagraph.Range.Text;
解决方案
       Word.Application word = new Word.Application();
       Word.Document doc = new Word.Document();
       object fileName = @"C:\wordFile.docx";
        // Define an object to pass to the API for missing parameters
        object missing = System.Type.Missing;
        doc = word.Documents.Open(ref fileName,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing);
        string ReadValue = string.Empty;
            // Activate the document
        doc.Activate();

         foreach (Word.Range tmpRange in doc.StoryRanges)
         {
            ReadValue += tmpRange.Text;
         }

这篇关于阅读Word文档使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:06