EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
279 stars 49 forks source link

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

Open Workaholic01 opened 1 year ago

Workaholic01 commented 1 year ago

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 commented 1 year ago

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

Workaholic01 commented 1 year ago

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 commented 1 year ago

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

https://github.com/EvotecIT/OfficeIMO/blob/ca19cef4f9f2cdf4aff0a55b5950c47ab96179f8/OfficeIMO.Word/WordPageNumber.cs#L163-L207