HeaderFooter

HeaderFooter constructor

Создает новый верхний или нижний колонтитул указанного типа.

public HeaderFooter(DocumentBase doc, HeaderFooterType headerFooterType)
ПараметрТипОписание
docDocumentBaseДокумент владельца.
headerFooterTypeHeaderFooterTypeАHeaderFooterType value , указывающее тип верхнего или нижнего колонтитула.

Примечания

КогдаHeaderFooter создан, он принадлежит указанному документу, но еще не является частью документа иParentNode являетсянулевой.

Чтобы добавитьHeaderFooterкSection использоватьInsertAfter ,InsertBefore , илиHeadersFooters свойство и методыAdd ,Insert.

Примеры

Показывает, как создать верхний и нижний колонтитулы.

Document doc = new Document();

// Создаем заголовок и добавляем к нему абзац. Текст в этом абзаце
// появится вверху каждой страницы этого раздела, над основным текстом.
HeaderFooter header = new HeaderFooter(doc, HeaderFooterType.HeaderPrimary);
doc.FirstSection.HeadersFooters.Add(header);

Paragraph para = header.AppendParagraph("My header.");

Assert.True(header.IsHeader);
Assert.True(para.IsEndOfHeaderFooter);

// Создаем нижний колонтитул и добавляем к нему абзац. Текст в этом абзаце
// появится внизу каждой страницы этого раздела, под основным текстом.
HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FooterPrimary);
doc.FirstSection.HeadersFooters.Add(footer);

para = footer.AppendParagraph("My footer.");

Assert.False(footer.IsHeader);
Assert.True(para.IsEndOfHeaderFooter);

Assert.AreEqual(footer, para.ParentStory);
Assert.AreEqual(footer.ParentSection, para.ParentSection);
Assert.AreEqual(footer.ParentSection, header.ParentSection);

doc.Save(ArtifactsDir + "HeaderFooter.Create.docx");

Смотрите также