-1

How can i get the range values of each bookmark in my word document? I want them to be shown in datagrid, so the code is:

int ii = 0;
Object obj;
var orderedBoomarks = WordDocument.Bookmarks.Cast<Bookmark>().OrderBy(d => d.Start).ToList();
foreach(Bookmark bookmark in orderedBoomarks)
{                    
    obj = bookmark.Range;
    dataGridView1.Rows.Add(bookmark.Name.ToString());
    dataGridView1.Rows[ii].Cells[1].Value = obj.ToString();
    ii++;
}

For now, the result in cell is "System.__ComObject". So, can i even get the numeric value of bookmark range?

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
Dmitry
  • 187
  • 15

2 Answers2

0

If I understand your question correctly, you want to get the value of the Range, so in this case you can use:

string bm = bookmark.Range.Text;
I.Manev
  • 709
  • 7
  • 23
  • You didnt get me right :) by your way, i'll get the text at the bookmark,so i want to get the number of symbol position at the bookmark. For example: Name: . The number of symbols before the beginning of the is 6 – Dmitry Jan 18 '18 at 12:16
0

Thanks, ive figured it out:

bm_numb =  bookmark.Range.Start;
Dmitry
  • 187
  • 15
  • A word of warning: the number of Range.Start is not particularly reliable/accurate. Word inserts a lot of "hidden" control characters which can throw this off if you try to use it, later. Also field codes can make this inaccurate. – Cindy Meister Jan 18 '18 at 17:31