Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/300.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#如何在插入文本之前将光标设置在末尾_C#_Ms Word_Cursor Position - Fatal编程技术网

c#如何在插入文本之前将光标设置在末尾

c#如何在插入文本之前将光标设置在末尾,c#,ms-word,cursor-position,C#,Ms Word,Cursor Position,我在Word文档的任意位置插入了一些动态文本,之后需要将光标正好放在文本末尾(而不是文档末尾!)。现在,光标停留在以前的位置,即插入文本的开头 我想这里没有太多有用的代码可以显示。。。我只是将一些html复制到一个文件中,然后将其插入到文档中: string tmp = AppDomain.CurrentDomain.BaseDirectory + "tmp.html"; using (StreamWriter file = new StreamWrite

我在Word文档的任意位置插入了一些动态文本,之后需要将光标正好放在文本末尾(而不是文档末尾!)。现在,光标停留在以前的位置,即插入文本的开头

我想这里没有太多有用的代码可以显示。。。我只是将一些html复制到一个文件中,然后将其插入到文档中:

          string tmp = AppDomain.CurrentDomain.BaseDirectory + "tmp.html";
          using (StreamWriter file = new StreamWriter(tmp))
          {
            file.Write(report, 0, report.Length);
          }

          var currentCursorPosition = Globals.ThisAddIn.Application.Selection.Range;
          currentCursorPosition.InsertFile(tmp);

我建议您使用Microsoft.Office.Interop.Word库。 您可以通过它将光标移动到word文档的末尾。
使用此选项:

对我不起作用,因为我的文本可以插入文档中的任何位置,而不仅仅是结尾。忘了提这件事了,我要把它加到问题上