Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Current Page No of Word Document. - Office IMO #111

Open
Workaholic01 opened this issue Feb 20, 2023 · 3 comments
Open

Getting Current Page No of Word Document. - Office IMO #111

Workaholic01 opened this issue Feb 20, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Workaholic01
Copy link

Hi,

Is there a way to get current page number. I am using Office IMO? I know we can add it by

document.Header.Default.AddPageNumber(WordPageNumberStyle.PlainNumber)

But not sure how to get it. I want to display it with custom text.

Thank you.

@PrzemyslawKlys
Copy link
Member

Word writes down information about pages but its what Word does. There is no way to tell programmatically which page we are on.

@Workaholic01
Copy link
Author

Not necessarily as in which page number we are at. But I want to add a text along with page number. e-g PageSide-1 , PageSide-2

@PrzemyslawKlys
Copy link
Member

It's not exposed. It would require some work to expose FieldCodes and add dummy/empty Run before and after to allow manipulation.

Run run1 = new Run();
FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
run1.Append(fieldChar1);
Run run2 = new Run();
FieldCode fieldCode1 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve };
fieldCode1.Text = " PAGE \\* MERGEFORMAT ";
run2.Append(fieldCode1);
Run run3 = new Run();
FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate };
run3.Append(fieldChar2);
Run run4 = new Run();
RunProperties runProperties2 = new RunProperties();
NoProof noProof2 = new NoProof();
runProperties2.Append(noProof2);
Text text1 = new Text();
text1.Text = "2";
run4.Append(runProperties2);
run4.Append(text1);
Run run5 = new Run();
RunProperties runProperties3 = new RunProperties();
NoProof noProof3 = new NoProof();
runProperties3.Append(noProof3);
FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End };
run5.Append(runProperties3);
run5.Append(fieldChar3);
paragraph1.Append(paragraphProperties1);
paragraph1.Append(run1);
paragraph1.Append(run2);
paragraph1.Append(run3);
paragraph1.Append(run4);
paragraph1.Append(run5);

@PrzemyslawKlys PrzemyslawKlys added the enhancement New feature or request label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants