SimpleField
をと で追加することInstruction
により、動的なページ番号を追加できます"PAGE"
。Word は、そのようなフィールドを正しいページ番号で自動的に更新します。
に追加されるに を含めるために、GeneratePageFooterPart
提供したリンクに を適応させることができることをコード化するには:SimpleField
Run
Footer
private static Footer GeneratePageFooterPart(string FooterText)
{
var element =
new Footer(
new Paragraph(
new ParagraphProperties(
new ParagraphStyleId() { Val = "Footer" }),
new Run(
new Text(FooterText),
// *** Adaptation: This will output the page number dynamically ***
new SimpleField() { Instruction = "PAGE" })
));
return element;
}
PAGE
テキストを後置することにより、ページ番号の形式を変更できることに注意してください。Ecma Office Open XML Part 1 - Fundamentals And Markup Language Reference.pdfから:
現在のページ番号が 19 で、次のフィールドが更新された場合:
PAGE
PAGE \* アラビアダッシュ
PAGE \* アルファベットのページ
\* ローマ字
結果は次のとおりです。
19
- 19 -
S
xix
たとえば、ローマ数字を取得するには、SimpleField
上記のコード行を次のように変更する必要があります。
new SimpleField() { Instruction = "PAGE \\* roman" })
または(ご希望の場合)
new SimpleField() { Instruction = @"PAGE \* roman" })