日期:2014-05-18  浏览次数:21326 次

C#设置word页码
怎样用c#设置word的页码。比如我想让页码从5开始

object wdFieldPage = Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage;
object preserveFormatting = true;
wordApp.Selection.Fields.Add(wordApp.Selection.Range, ref wdFieldPage,ref Nothing,ref preserveFormatting);

我使用上面的方法页码只能从1开始计算。我想可以自己设置起始页码

------解决方案--------------------
C# code


 //页码
                bool bHeader = true;
                object oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;
                object oFirstPage = bHeader;
                oAlignment = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberRight;
                WordApp.Selection.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref   oAlignment, ref   oFirstPage);
                WordApp.Selection.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.NumberStyle = WdPageNumberStyle.wdPageNumberStyleNumberInDash;

------解决方案--------------------
.RestartNumberingAtSection = True
.StartingNumber = 5