尝试从word文档中获取数据?

时间:2015-05-11 14:35:43

标签: c# ms-word office-interop

我正在尝试使用

从word文档中获取数据
string Mainer(string pathfile)
        {
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();

                object miss = System.Reflection.Missing.Value;
                object path = pathfile;
                object readOnly = true;
                Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
                string totaltext = "";
                for (int i = 0; i < docs.Paragraphs.Count; i++)
                {
                    totaltext += " \r\n " + docs.Paragraphs[i + 1].Range.Text.ToString();
                }

                docs.Close();   
                word.Quit();
                word = null;
                docs = null;
                GC.Collect(); 
                return totaltext;
        }

我收到错误The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))我在foreach中使用此代码对此错误有任何建议吗?

0 个答案:

没有答案