Best way to have table dynamic page number

Hi, we need to create a table with several columns and one of them is page number, but the value is dynamic as it depends on the section filled above the table itself.
We cannot use Table of contents (TOC) via “style” as we need several columns

Is it necessary to fill report twice ? One for filling data and the second time for page numbers ?

Any help ?

Thanks a lot in advance.

Best regards,
Jack

@Jackomino If I understand you requirement properly, it is required to put page numbed of some content in the document into the table - some kind of custom TOC. If so, you can simply use PAGEREF field in the column with page numbers, just like it is done in regular TOC.

Thanks for the answer.
If I understood well, I need to:

  1. create a bookmark for each element I want to have the page number for

  2. place a PAGEREF with bookmark_name to have cross-reference to the object position

  3. Update document to recalculate references

Is it right ?

Thanks a lot again
Jack

@Jackomino Yes, you are absolutely right. Also if it is required to make page numbers clickable, you can add \h switch to PAGEREF field. In this case it will behave like hyperlink to the bookmark.

Thanks a lot for your help

Have a good day
Jack

1 Like

Hi everyone…

I found how insert the list of my bookmarks (Inserting Bookmarks Dynamically in C#|Aspose.Words for .NET)
but how can I insert a cross-reference field (PAGEREF) via LINQ reporting in doc template (<<…>>)? Is it possible or I can only use C# ?

Thanks a lot again
Jack

@Jackomino You can insert PAGEREF in your template like this:

{ PAGEREF <<[bookmarkName]>> \h }

And then use LINQ Reporting engine to insert the bookmark name in it. For example see the following code template and output (press Alt+F9 in MS Word to see field codes):

Document doc = new Document("C:\\Temp\\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.buildReport(doc, "test", "bookmarkName");
doc.updateFields();
doc.save("C:\\Temp\\out.docx");

in.docx (12.6 KB)
in.docx (12.6 KB)

Thank you so much for you fast and precise help !
You rock !

Another little question: we should youse “UpdateFields” or “UpdatePageLayout”, cause in documentation the first one seems not to be related to PAGEREF, so it’s suggested to use the second one (Document.UpdateFields | Aspose.Words for .NET)

BTW, we’ll try both and check, Kiitos !

@Jackomino UpdatePageLayout is required to build document layout and calculate page numbers. So you can first call UpdatePageLayout, the document layout will be cached. Then when UpdateFields is called layout will not be built the second time. So there is no harm to call these method one by one.