Home » , , » Issue while generating a docx file using C#?

Issue while generating a docx file using C#?

Written By M.L on திங்கள், 10 அக்டோபர், 2011 | அக்டோபர் 10, 2011

am working on a Word document 2007 file. The requirement is to have a different format for the page numbers for the “Table of Contents” section and the main content of the document.

For ex:-

The table of contents the page number should be in the following format: TOC Page x of y where x and y are roman numerals.(Page i of v)

While the rest of the content should have Page number in the format Page x of y where x and y are in numbers.(Page 1 of 10)

Currently I am able to use only one consistent format for the page number throughout the document.

However I am unable to use two different format for the page # in the document.

The code snippet which I am using is provided below:-

                                                Document d;
Window win = d.Application.ActiveWindow;
                    object cp = WdFieldType.wdFieldPage;
                    object np = WdFieldType.wdFieldNumPages;
                    win.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
                    win.ActivePane.Selection.Paragraphs.Alignment =WdParagraphAlignment.wdAlignParagraphRight;
                    win.Selection.TypeText("Page ");
                     win.Selection.Fields.Add(win.Selection.Range, ref cp, ref u, ref u);
                    win.Selection.TypeText(" of ");
                    win.Selection.Fields.Add(win.Selection.Range, ref np, ref u, ref u);
                    win.ActivePane.View.SeekView = WdSeekView.wdSeekMainDocument;

where, wdFieldPage is the current page and wdFieldNumPages is the total number of pages.

The above code generates the page # in the Page 1 of 10 format throughout the document.

Could you please help me resolve this.

0 comments:

கருத்துரையிடுக

Popular Posts

General Category