【问题标题】:c# how to set the cursor at the end of before inserted textc#如何在插入文本之前将光标设置在末尾
【发布时间】:2019-05-17 14:34:40
【问题描述】:

我在 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);

【问题讨论】:

    标签: c# ms-word cursor-position


    【解决方案1】:

    我建议您使用 Microsoft.Office.Interop.Word 库。 您可以通过它将光标移动到word文档的末尾。 使用这个:Move my cursor to the end of the Text in MsWord using C#?

    【讨论】:

    • 对我不起作用,因为我的文本可以插入到文档的任何位置,而不仅仅是在末尾。忘了提这个,我会把它添加到问题中
    猜你喜欢
    • 2011-05-31
    • 2012-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    相关资源
    最近更新 更多