oWord.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = -1; //奇偶頁不同
object oFirstPage = true;
object leftAlign = Word.WdPageNumberAlignment.wdAlignPageNumberLeft;
object rightAlign = Word.WdPageNumberAlignment.wdAlignPageNumberRight;
//奇數頁右對齊
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.Add(ref rightAlign, ref oFirstPage);
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.NumberStyle = Word.WdPageNumberStyle.wdPageNumberStyleArabic;
//偶數頁左對齊
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.Add(ref leftAlign, ref oFirstPage);
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].PageNumbers.NumberStyle = Word.WdPageNumberStyle.wdPageNumberStyleArabic;
問題: 結果是頁碼全左對齊 ,奇偶頁沒起效果,但是我是分了奇偶頁的,如果是我只添加偶數頁的頁碼時,卻把奇數頁的頁碼也給添加了
但是下面的那段又是有效的
oWord.ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = -1; //奇偶頁不同
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.InsertBefore("Section 1 Odd Header");
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range.InsertBefore("Section 1 Even Header");
oWord.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].Range.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
這個頁碼問題 折騰我好幾天了,網上沒找到相關答案,求達人解惑啊
對齊常量修改成下面的就可以了
object leftAlign = Word.Word.WdPageNumberAlignment.wdAlignPageNumberInside;
object rightAlign = Word.Word.WdPageNumberAlignment.wdAlignPageNumberOutside;