在VC#2010中逐页阅读docx文件

在VC#2010中逐页阅读docx文件,c#,docx,C#,Docx,我一直在使用以下代码阅读整个word文档 Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass(); //Microsoft.Office.Interop.Word.ApplicationClass wordObject = new ApplicationClass();

我一直在使用以下代码阅读整个word文档

Microsoft.Office.Interop.Word.ApplicationClass wordObject = new Microsoft.Office.Interop.Word.ApplicationClass();
                //Microsoft.Office.Interop.Word.ApplicationClass wordObject = new ApplicationClass();
                object file = file_path.Text; //this is the path
                object nullobject = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Word.Document docs = wordObject.Documents.Open
                    (ref file, ref nullobject, ref nullobject, ref nullobject,
                    ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                    ref nullobject, ref nullobject, ref nullobject, ref nullobject,
                    ref nullobject, ref nullobject, ref nullobject, ref nullobject
                                    );

                docs.ActiveWindow.Selection.WholeStory();                
                docs.ActiveWindow.Selection.Copy();
                IDataObject data = Clipboard.GetDataObject();
                //docx_contents.Text = data.GetData(DataFormats.Text).ToString();
                pages = data.GetData(DataFormats.Text).ToString();
                docs.Close(ref nullobject, ref nullobject, ref nullobject);
我把所有的东西都放在页面上。请建议我如何以字符串数组逐页阅读?

这是我代码的一部分

        DOCXStructure[] returnval = null;

        object file = filePath;
        object nullobj = System.Reflection.Missing.Value;
        object read_only = true;

        wordApp = new Word.ApplicationClass();

        FileInfo fileInfo = new FileInfo(filePath);

        string fileName = filePath.Substring(filePath.LastIndexOf('\\'));
        fileName = "~" + fileName;




        document = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);



        Word.WdStatistic stat = Word.WdStatistic.wdStatisticPages;
        int PageNum = document.ComputeStatistics(stat, ref nullobj);

        returnval = new DOCXStructure[PageNum];

        for(int i=0; i<PageNum; i++){
            returnval[i] = new DOCXStructure();

            object what = Word.WdGoToItem.wdGoToPage;
            object which = nullobj;
            object count = i+1;
            object name = nullobj;
            object Page = "\\Page";

            wordApp.Selection.GoTo(ref what, ref which, ref count, ref name);

            Word.Range range = document.Bookmarks.get_Item(ref Page).Range;
            returnval[i].page = i+1;
            returnval[i].context.AddRange(range.Text.Split('\r', '\n', '\t'));
        }
        document.Close(ref nullobj, ref nullobj, ref nullobj);
DOCXStructure[]returnval=null;
对象文件=文件路径;
对象nullobj=System.Reflection.Missing.Value;
对象只读=真;
wordApp=新单词.ApplicationClass();
FileInfo FileInfo=新的FileInfo(filePath);
字符串fileName=filePath.Substring(filePath.LastIndexOf('\\');
fileName=“~”+文件名;
document=wordApp.Documents.Open(ref file,ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj,
ref nullobj、ref nullobj、ref nullobj、ref nullobj、ref nullobj、ref nullobj、ref nullobj、ref nullobj);
Word.WdStatistic stat=Word.WdStatistic.wdStatisticPages;
int PageNum=document.computeTestatics(stat,ref nullobj);
returnval=新的docx结构[PageNum];
对于(int i=0;i