0

I'm using this code to set autonumeration in generated Word doc and it works fine but I need to start numeration from specific value, e.g. page_1 - 3, page_2 - 4, page_3 - 5, etc.

//define currentpage object
object currentPage = WdFieldType.wdFieldPage;

activeWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;

//set alignment  
activeWindow.ActivePane.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;

//Add page number  
activeWindow.Selection.Fields.Add(activeWindow.Selection.Range, ref currentPage, ref oMissing, ref oMissing);

In Word you can set it by "Insert->Page Number->Format Page Numbers->Start at" Is there equivalent property in C# for this?

Solved! All we have to do is set this 2 property:

activeWindow.ActivePane.Selection.HeaderFooter.PageNumbers.RestartNumberingAtSection = true;               
activeWindow.ActivePane.Selection.HeaderFooter.PageNumbers.StartingNumber = 666;
4

1 回答 1

2

我知道找出在 Word 中做事的最佳方法是录制宏,然后查看生成的代码。它是 VB,但很容易将其转换为 C#。在 Word 2007 中,如果我录制了一个更改您所说的开始的宏,我将得到以下宏 -

 Sub Macro1()
    '
    ' Macro1 Macro
    '
    '
        With Selection.Sections(1).Headers(1).PageNumbers
            .NumberStyle = wdPageNumberStyleArabic
            .HeadingLevelForChapter = 0
            .IncludeChapterNumber = False
            .ChapterPageSeparator = wdSeparatorHyphen
            .RestartNumberingAtSection = True
            .StartingNumber = 3
        End With
    End Sub

您只对更改 StartingNumber 属性感兴趣,并且转换为 C# 很简单。

于 2013-07-20T18:51:41.480 回答