程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c#-C# word 2007 奇偶頁問題

c#-C# word 2007 奇偶頁問題

編輯:編程綜合問答
C# word 2007 奇偶頁問題

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;

save4me
longxianfu
save4me
longxianfu
longxianfu
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved