Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将docx文件中的所有单词放到听写器中_C#_Dictionary_Ms Word_Docx - Fatal编程技术网

C# 如何将docx文件中的所有单词放到听写器中

C# 如何将docx文件中的所有单词放到听写器中,c#,dictionary,ms-word,docx,C#,Dictionary,Ms Word,Docx,我想从docx(WORD)文件中提取所有单词,并将它们放入字典,字典中有所有值,因为我试图将它们作为键放入,但有时在docx文件中有相同的单词 ` Dictionary <int, string> motRap = new Dictionary<int, string>(); Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.W

我想从docx(WORD)文件中提取所有单词,并将它们放入字典,字典中有所有值,因为我试图将它们作为键放入,但有时在docx文件中有相同的单词

 ` Dictionary <int, string> motRap = new Dictionary<int, string>();
            Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
            Document document = application.Documents.Open("test.docx");

        // Loop through all words in the document.
        int count = document.Words.Count;
        for (int i = 1; i <= count; i++)
        {
            string text = document.Words[i].Text;
            motRap.Add(i, text);

        }
        // Close word.
        application.Quit();
        foreach(var o in motRap)
        {
            Console.WriteLine(o.Value);
        }`
`Dictionary motRap=new Dictionary();
Microsoft.Office.Interop.Word.Application Application=新的Microsoft.Office.Interop.Word.Application();
Document=application.Documents.Open(“test.docx”);
//循环浏览文档中的所有单词。
int count=document.Words.count;

对于(int i=1;我可以捕获异常以查看它是什么吗?因为您似乎是新来的,所以当您遇到异常时,请尽量记住始终在问题中包含错误消息。另外,请花时间查看抛出的异常的
数据
属性,因为有时它会提供有用的信息。No No.dll您可以使用的另一个工具是
InnerException
属性:如果它不是
null
,它可以显示有关出错原因的更多详细信息。消息错误是:“System.Runtime.InteropServices.COMException:消息过滤器指出应用程序正忙。(HRESULT的异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))致Microsoft.Office.Interop.Word.DocumentClass.get_Words();以测试Program.cs中的.Program.Main(字符串[]args):第42行谢谢你的提示是的,我是新来的,而且我是法国人,所以我的英语不是很好(对不起)这是
String text=document.Words[i].text;
42行吗?