@GreyKnight

Закладки Word

Добрый день.
Подскажите, пожалуйста, каким образом можно заменить закладки на текст в файле Word, сохраненном в формате XML. Закладки в этом случае обозначаются тегами bookmarkStart и bookmarkEnd. Можно вместо замены также просто вставить текст, это не принципиально. После замены необходимо изменения записать в новый файл и предложить пользователю его сохранить. Буду весьма благодарен за работающий код на C#.
  • Вопрос задан
  • 3705 просмотров
Пригласить эксперта
Ответы на вопрос 1
Iliapan
@Iliapan
вообще обленились?

    To insert text in a range

1. Specify a range at the beginning of a document and insert the text New Text.

The following code example can be used in a document-level customization.

object start = 0;

object end = 0;

Word.Range rng = this.Range(ref start, ref end);

rng.Text = “New Text”;

The following code example can be used in an application-level add-in. This code uses the active document.

Word.Range rng = this.Application.ActiveDocument.Range(0, 0);

rng.Text = “New Text”;

2. Select the Range object, which has expanded from one character to the length of the inserted text.

rng.Select();

    Replacing Text in a Range

If the specified range contains text, all text in the range is replaced with the inserted text.

 1. Create a Range object that consists of the first 12 characters in the document.

The following code example can be used in a document-level customization.

object start = 0;

object end = 12;

Word.Range rng = this.Range(ref start, ref end);

The following code example can be used in an application-level add-in. This code uses the active document.

Word.Range rng = this.Application.ActiveDocument.Range(0, 12);

2. Replace those characters with the string New Text.

rng.Text = “New Text”;

3. Select the range.

rng.Select();
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы