HeaderFooter

HeaderFooter constructor

Crée un nouvel en-tête ou pied de page du type spécifié.

public HeaderFooter(DocumentBase doc, HeaderFooterType headerFooterType)
ParamètreTaperLa description
docDocumentBaseLe document du propriétaire.
headerFooterTypeHeaderFooterTypeUNHeaderFooterType value qui spécifie le type de l’en-tête ou du pied de page.

Remarques

QuandHeaderFooter est créé, il appartient au document spécifié, mais ne fait pas encore partie du document etParentNode estnul.

À ajouterHeaderFooterà unSection utiliserInsertAfter ,InsertBefore , ouHeadersFooters propriété et méthodesAdd ,Insert.

Exemples

Montre comment créer un en-tête et un pied de page.

Document doc = new Document();

// Créez un en-tête et ajoutez-y un paragraphe. Le texte de ce paragraphe
// apparaîtra en haut de chaque page de cette section, au-dessus du corps du texte principal.
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);

// Créez un pied de page et ajoutez-y un paragraphe. Le texte de ce paragraphe
// apparaîtra au bas de chaque page de cette section, sous le corps du texte principal.
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");

Voir également