C#在Word文档光标处插入文字后光标移至被插入文字后

发布时间:2019-12-02 23:34:54.31编辑:佚名阅读(343)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Word = Microsoft.Office.Interop.Word;
namespace WordInsertStringBeforeCursor
{
    public partial class Ribbon1
    {
        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {
        
        }
        
        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            Word.Application objApplication = Globals.ThisDocument.Application;
            Word.Selection objSelection = objApplication.Selection;
            Word.Range objRange = objSelection.Range;
            objRange.InsertAfter("Test");
            objRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
            objRange.Select();
        }
    }
}


  关键字:C#Word文档光标处插入文字


鼓掌

1

正能量

0

0

呵呵

0


评论区