Since Wordlayout has been introduced with NAV 2015, many have tried to implement Transheader/-footer functionality from classic report layout into Word and many have failed. For a long time, the only possible approach seemed to be that, with a fixed number of lines per page layout. But now, I found another, much simpler way for arbitrary layout, and I will show you, how this can be accomplished for a sample report, namely report 1306 “Mini Sales – Invoice” of NAV 2016…… The idea behind it is quite similar to the procedure for RDLC reports (see https://massivedynamicsblog.wordpress.com/2015/12/05/how-to-implement-carryover-in-rdlc-report-layouts/ , e. g.). What we need is a function to reference content from the report body in the report header and/or footer. In the case of Word, this function is the STYLEREF function (see https://support.microsoft.com/en-us/kb/141994 , e. g.). With this function, you can grab the first or last content on a page’s body, which is formatted with a certain style, and reuse it within the page’s header or footer. As for the RDLC report layout, we need additional columns within the repeating section for the running value (summing up) of the line amount. I used two additional columns, one for the carry-over value in the header and one for the carry-forward value in the footer. Both columns are calculated in a way, that the first value on each page can be directly used as carry-over in the page’s header and the last value on each page can be used as carry-forward in the page’s footer. The column cells are formatted with two new styles (TransHeader and TransFooter), to grab them with the STYLEREF function. Be sure to define these new styles as pure character styles and not as paragraph styles or linked styles.
The additional columns do not disturb the layout, because they have a very small width and the two styles use a white colored font of size 1 (hidden text is not grabbed by the STYLEREF function!), so the two columns are practically invisible (same is true in RDLC layout).
Furthermore, two new text constants are needed for labeling the carry-over and carry-forward values, respectively. I put them into the first table of the report body, which is printed only on the first page for each document. For the two labels, two additional, invisible, style have to be created (CarriedOverLbl and CarriedForwardLbl). Fortunately, the STYLEREF function searches every page of the document, if it doesn’t find the referenced style on the current page, so it is sufficient to output the labels only on the first page (similar to RDLC).
Now here is the field expression, I used for the Word header and footer line, respectively:
Note, that the braces of field expressions are most easily created with Ctrl+F9. Furthermore Alt+F9 toggles the visibility of field expressions for the whole document. The IF-function suppresses the carry-over and carry-forward on the first and last page, respectivel. In the footer expression, the \l (smallcaps L) for “last” is supplied, to grab the last content on the current page.
Here is some sample output of the report:
I also handled the case, when the page break occurs in the totals repeater:
As is true for RDLC report layouts, the carry-over lines have to be put into the page header and footer, and will not work within the page body.
Here you can download the sample report to be used directly in NAV 2016 CRONUS database:
In order to run the report, Wordlayout+ is not necessary. But you may wish, for example, blank zeros or implement shipment lines, etc. – This is all possible with the new Wordlayout+ (see https://massivedynamicsblog.wordpress.com/2016/09/15/wordlayout/ )