Hi ,
I want to create a section and each section has a different header and footer.
Regards,
Document document = new Document();
//add a section and add header and footer for this section
Section sec = document.AddSection();
sec.HeadersFooters.Header.AddParagraph().AppendText("Header for section1.");
sec.HeadersFooters.Footer.AddParagraph().AppendText("Footer for section1.");
//Add another section and set different header footer.
Section sec1 = document.AddSection();
sec1.HeadersFooters.Header.AddParagraph().AppendText("Header for section2.");
sec1.HeadersFooters.Footer.AddParagraph().AppendText("Footer for section2.");
document.SaveToFile("headerFooter.docx", Spire.Doc.FileFormat.Docx);// Investigation Section
Section InvestigationSection = document.AddSection();
InvestigationSection.PageSetup.InsertPageNumbers(false, Spire.Doc.Documents.PageNumberAlignment.Left);
InvestigationSection.AddParagraph().AppendHTML(InvestigationContent);
InvestigationSection.HeadersFooters.Header.AddParagraph().AppendHTML(Header);
InvestigationSection.HeadersFooters.Footer.AddParagraph().AppendHTML(InvestigationFooter);
InvestigationSection.Paragraphs[InvestigationSection.Paragraphs.Count - 1].InsertSectionBreak(Spire.Doc.Documents.SectionBreakType.NoBreak);
// Decision Section
Section DecisionSection = null;
if (DecisionContent.Length > 0)
{
DecisionSection = document.AddSection();
DecisionSection.AddParagraph().AppendHTML(DecisionContent);
DecisionSection.HeadersFooters.Header.AddParagraph().AppendHTML(Header);
InvestigationSection.HeadersFooters.Footer.AddParagraph().AppendHTML(DecisionFooter);
}
ms = new MemoryStream();
document.SaveToStream(ms, FileFormat.Docx); // Investigation Section
Section InvestigationSection = document.AddSection();
InvestigationSection.PageSetup.InsertPageNumbers(false, Spire.Doc.Documents.PageNumberAlignment.Left);
InvestigationSection.AddParagraph().AppendHTML(InvestigationContent);
InvestigationSection.HeadersFooters.LinkToPrevious = false;// added by jane
InvestigationSection.HeadersFooters.Header.AddParagraph().AppendHTML(Header);
InvestigationSection.HeadersFooters.Footer.AddParagraph().AppendHTML(InvestigationFooter);
InvestigationSection.Paragraphs[InvestigationSection.Paragraphs.Count - 1].InsertSectionBreak(Spire.Doc.Documents.SectionBreakType.NoBreak);
// Decision Section
Section DecisionSection = null;
if (DecisionContent.Length > 0)
{
DecisionSection = document.AddSection();
DecisionSection.AddParagraph().AppendHTML(DecisionContent);
DecisionSection.HeadersFooters.LinkToPrevious = false;// added by jane
DecisionSection.HeadersFooters.Header.AddParagraph().AppendHTML(Header);
DecisionSection.HeadersFooters.Footer.AddParagraph().AppendHTML(DecisionFooter);
}
ms = new MemoryStream();
document.SaveToStream(ms, FileFormat.Docx);