Esempio n. 1
0
        public void InsertPageNumber(string strType, bool bHeader)
        {
            object oAlignment = Word.WdPageNumberAlignment.wdAlignPageNumberOutside;
            object oFirstPage = bHeader;

            Word.WdHeaderFooterIndex WdFooterIndex = Word.WdHeaderFooterIndex.wdHeaderFooterPrimary;
            var page = application.Selection.Sections[1].Footers[WdFooterIndex].PageNumbers;

            page.NumberStyle               = Word.WdPageNumberStyle.wdPageNumberStyleNumberInDash;
            page.HeadingLevelForChapter    = 0;
            page.ChapterPageSeparator      = Word.WdSeparatorType.wdSeparatorHyphen;
            page.RestartNumberingAtSection = false;
            page.StartingNumber            = 0;
            page.Add(ref oAlignment, ref oFirstPage);
            //application.ActiveWindow.ActivePane.View.Zoom.PageFit = Word.WdPageFit.wdPageFitFullPage;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets whether or not a specific header/footer type is visible in a given section.
        /// </summary>
        /// <param name="Section">The section to check.</param>
        /// <param name="HeaderFooterIndex">The header/footer to check for.</param>
        /// <returns>True if visible, otherwise False.</returns>
        internal static bool GetHeaderFooterVisibility(Word.Section Section, Word.WdHeaderFooterIndex HeaderFooterIndex)
        {
            Word.Range StartOfSection = Section.Range.Duplicate;
            Word.Range EndOfSection   = Section.Range.Duplicate;

            //set ranges
            StartOfSection.End = StartOfSection.Start;

            //get start/end page
            int StartingPageNumber = (int)StartOfSection.get_Information(Word.WdInformation.wdActiveEndAdjustedPageNumber);
            int EndingPageNumber   = (int)EndOfSection.get_Information(Word.WdInformation.wdActiveEndAdjustedPageNumber);

            //first page header in use?
            bool FirstPageVisible = (Section.PageSetup.DifferentFirstPageHeaderFooter == -1);

            if (FirstPageVisible && HeaderFooterIndex == Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage)
            {
                return(true);
            }

            //even page header in use?
            bool EvenPagesInUse = (Section.PageSetup.OddAndEvenPagesHeaderFooter == -1);

            if (!EvenPagesInUse && HeaderFooterIndex == Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages)
            {
                return(false);
            }

            if (EndingPageNumber - StartingPageNumber >= 2)
            {
                //if there are more than three pages, then the type is definitely showing
                return(true);
            }
            else if (EndingPageNumber - StartingPageNumber == 1)
            {
                //if there are two pages, need to check
                switch (HeaderFooterIndex)
                {
                case Word.WdHeaderFooterIndex.wdHeaderFooterPrimary:
                    if (!EvenPagesInUse || !FirstPageVisible)
                    {
                        return(true);
                    }
                    else
                    {
                        return((StartingPageNumber + 1) % 2 != 0);      // is next page odd
                    }

                case Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages:
                    if (!FirstPageVisible)
                    {
                        return(true);
                    }
                    else
                    {
                        return((StartingPageNumber + 1) % 2 == 0);      // is next page even
                    }
                }
            }

            // == 1
            switch (HeaderFooterIndex)
            {
            case Word.WdHeaderFooterIndex.wdHeaderFooterPrimary:
                if (FirstPageVisible)     // first page is showing
                {
                    return(false);
                }
                else if (EvenPagesInUse)     // first page not showing and even showing
                {
                    return(StartingPageNumber % 2 != 0);
                }
                else              //first page not showing, even not showing
                {
                    return(true); // is page odd
                }

            case Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages:
                if (FirstPageVisible)     // first page is showing
                {
                    return(false);
                }
                else if (EvenPagesInUse)     // first page not showing and even showing
                {
                    return(StartingPageNumber % 2 == 0);
                }
                else               //first page not showing, even not showing
                {
                    return(false); // is page odd
                }
            }

            Debug.Fail("should never fall through on visibility");
            return(false);
        }