Newlines in Word report fields

ivarskivarsk Member Posts: 12
edited 2015-07-11 in NAV Three Tier
Has anyone had success having multi-line fields displayed properly on a Word report in NAV 2015 ?

For the Word content control (plain text type), I have set the "Allow carriage returns (multiple paragraphs)" checkbox, and it does make the difference in the way that pressing Enter inside the content control results in a linebreak, while for the controls without that checkbox, pressing Enter is suppressed and does nothing. Hence, not the Word's fault.

Meanwhile from NAV, I've tried about everything with no success, e.g. the one below outputs a single-liner in Word, CRLF ignored:
CRLF[1] := 13;
CRLF[2] := 10;
TextField := Description + CRLF + "Description 2";
Also tried to directly output a NAV text field with MultiLine=Yes with some linebreaks, same result.

Any suggestions? If nothing else, where do we report such issues to MS currently? Connect? :)

[ currently using CU 5, nothing related to be seen in platform fixes in later builds ].


  • ivarskivarsk Member Posts: 12
    OK, silly enough, yet worth the journey - a workaround :)

    Essentially I'm placing '{CRLF}' markers where I wish the newlines to appear in Word, and customize standard codeunit to convert those to linebreaks after NAVWordXMLMerger has done its job.
    Messing with .docx directly, any guarantees disclaimed.

    In Codeunit 9651 Document Report Mgt.:
    OutStrWordDoc := NAVWordXMLMerger.MergeWordDocument(InStrWordDoc,InStrXmlData,OutStrWordDoc); // standard code
    HandleCRLFs(OutStrWordDoc); // new function call
    COMMIT; // standard code
    The function itself:
    LOCAL HandleCRLFs(VAR OutStrWordDoc : OutStream)
    ZipArchive := ZipArchive.ZipArchive(OutStrWordDoc, ZipArchiveMode.Read);
    ZipArchiveEntry := ZipArchive.GetEntry('word/document.xml');
    StreamReader := StreamReader.StreamReader(ZipArchiveEntry.Open());
    Contents := StreamReader.ReadToEnd();
    Contents := Contents.Replace('{CRLF}', '<w:br/>');
    ZipArchive := ZipArchive.ZipArchive(OutStrWordDoc, ZipArchiveMode.Update);
    ZipArchiveEntry := ZipArchive.GetEntry('word/document.xml');
    ZipArchiveEntry := ZipArchive.CreateEntry('word/document.xml');
    StreamWriter := StreamWriter.StreamWriter(ZipArchiveEntry.Open());
    // vars:
    ZipArchive	DotNet	System.IO.Compression.ZipArchive.'System.IO.Compression, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ZipArchiveMode	DotNet	System.IO.Compression.ZipArchiveMode.'System.IO.Compression, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ZipArchiveEntry	DotNet	System.IO.Compression.ZipArchiveEntry.'System.IO.Compression, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    StreamReader	DotNet	System.IO.StreamReader.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    StreamWriter	DotNet	System.IO.StreamWriter.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Contents	DotNet	System.String.'mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    PS. Still looking forward to hear the normal way of doing this :)
  • chrisdfchrisdf Member Posts: 81

    Thanks for this - have found it useful!

    However, have found one small problem - if you use this technique and the data is in a Header section it does not work.

  • gerdhuebnergerdhuebner Member Posts: 155
    edited 2016-09-08
    In addition to document.xml, you should also convert the header1.xml (header2.xml, ...) and footer1.xml files.

    Standard Word custom xml parts can be used instead of the NAV WordMergeDocument AddIn. Then a CL/LF is correctly transformed into a line feed within a plain text content control.
    (see, e. g.)
  • gerdhuebnergerdhuebner Member Posts: 155
    You can use Wordlayout+, which automatically transforms CR/LF into new lines in a word plain text control. Download and info here
Sign In or Register to comment.