如何从上一节的最高页码开始继续编号?

How to continue page numbering from the highest page number in the previous section?

在我的 Word 文档中,我添加了新的部分:

var defaultSection = mainPart.Document.Descendants<SectionProperties>().First();
var paragraph2 = new Paragraph();
var paragraphProperties2 = new ParagraphProperties();

var sectionProperties2 = defaultSection.Clone() as SectionProperties;

var sectionTypeCur = sectionProperties2.Descendants<SectionType>().FirstOrDefault();
sectionProperties2.RemoveChild(sectionTypeCur);
var sectionType2 = new SectionType() { Val = SectionMarkValues.NextPage };

 var pageNumberType2 = new PageNumberType()
     {
       ChapterSeparator = defaultPageNumbering.ChapterSeparator,
       ChapterStyle = defaultPageNumbering.ChapterStyle,
       Format = defaultPageNumbering.Format,
       Start = null
      };

  var pageNumberTypeCur = sectionProperties2.Descendants<PageNumberType>().FirstOrDefault();
  sectionProperties2.RemoveChild(pageNumberTypeCur);
  sectionProperties2.Append(pageNumberType2);

  var titlePageCur2 = sectionProperties2.Descendants<TitlePage>().FirstOrDefault();
  sectionProperties2.RemoveChild(titlePageCur2);

  paragraphProperties2.Append(sectionProperties2);
  paragraph2.Append(paragraphProperties2);
  lastElementInFirstSection.InsertAfterSelf(paragraph2);

并看到在新部分中页码从默认值开始。但是我想从上一节的最高页码开始连续编号。
我该怎么做?

您需要使用 SectionMarkValues.Continuous 而不是 Val = SectionMarkValues.NextPage。连续不会转到下一页,因此您可能也需要放入一个普通的下一页。