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 ].

Comments

  • 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/>');
    CLEAR(ZipArchive);
    ZipArchive := ZipArchive.ZipArchive(OutStrWordDoc, ZipArchiveMode.Update);
    ZipArchiveEntry := ZipArchive.GetEntry('word/document.xml');
    ZipArchiveEntry.Delete();
    ZipArchiveEntry := ZipArchive.CreateEntry('word/document.xml');
    StreamWriter := StreamWriter.StreamWriter(ZipArchiveEntry.Open());
    StreamWriter.Write(Contents);
    StreamWriter.Close();
    
    // vars:
    ZipArchive	DotNet	System.IO.Compression.ZipArchive.'System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ZipArchiveMode	DotNet	System.IO.Compression.ZipArchiveMode.'System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    ZipArchiveEntry	DotNet	System.IO.Compression.ZipArchiveEntry.'System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    StreamReader	DotNet	System.IO.StreamReader.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    StreamWriter	DotNet	System.IO.StreamWriter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
    Contents	DotNet	System.String.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    

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

    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
    @chrisdf
    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 https://massivedynamicsblog.wordpress.com/2016/09/08/wordlayout-revisited/, 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 https://massivedynamicsblog.wordpress.com/2016/09/15/wordlayout/
Sign In or Register to comment.