C# 在文档光标处插入文字后光标移至被插入文字后
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();
}
}
}
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();
}
}
}