c# word interop selection example

  • 197
  • 0
  • 2019-01-01

c# word interop selection example


using Word = Microsoft.Office.Interop.Word;

            
object docPath = @"X:\X\test.docx";
var wordApp = new Word.Application();
Word.Document doc = wordApp.Documents.Open(ref docPath);


object a = doc.Application.Selection.Start;
object b = doc.Application.Selection.End;
//doc.Paragraphs[1].Range.Select();
Word.Range r1 = doc.Range(a, b);
r1.Select();
var selectoion = wordApp.Selection;


for (int i = 1; i <= tablecount; i++)
{
	Word.Table wTable = doc.Tables[i];
	Word.Cell pCell = wTable.Cell(i, i);

	pCell.Range.Text = "test txt";
	pCell.Range.Select();

	var selectoion2 = wordApp.Selection;

}