Char(10) in MS Word 2007 Doc from Template

Does text formatting such as char(10) work with MS Word 2007 Doc from Template? I have a text with several line breaks and it works fine in Appian but the output of the document has everything in one line. 

  Discussion posts and replies are publicly visible

Parents
  • char(10) does not work in Word, it will remove the new line.

    If you want to keep it, you need to replace char(10) with "<w:br />" (similarly on html you would do with <br>)

  • 0
    Certified Lead Developer
    in reply to ManuelHTG

    Except if you just insert "<w:br/>" directly into the text, you won't see a linebreak in Word, you'll see "<w:br/>" (though the < or > characters might cause Word to throw an error when opening the document).  The reason for this is that it would still be inside the <w:t> ... </w:t> tags, meaning Word tries to interpret it literally as text.

    The solution I've found for this is to insert </w:t>, then <w:br/>, then a new <w:t>.   I prefer to do this via a predefined expression rule instead of ad-hoc, to take the guesswork out of it.

    Here's mine, i.e. GLBL_insertWordDocxLineBreak()...

    a!localVariables(
      local!rows: if(
        rule!GLBL_isBlank(ri!num),
        1,
        if(ri!num < 1, 0, ri!num)
      ),
    
      "</w:t>"
      & concat(repeat(local!rows, "<w:br/>" & char(10)))
      & "<w:t>"
    )

    Note this rule allows adding multiple linebreaks if/when necessary via passing in a value for ri!num.

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    Further, all text that could ever contain the characters "<", ">", or "&", needs to be sanitized before passing into the Word template.  So basically anything that's ever user-editable, and/or from a not stirctly-controlled source of text.

    Here's my rule GLBL_sanitizeTextForWordDocx(), note that this rule calls the linebreak rule from my above comment, so it takes care of invalid characters and linebreaks (converted from char(10)s) at the same time.

    reduce(
      fn!substitute,
      trim(ri!text),
    
      merge(
        {
          "&",
          ">",
          "<",
          char(10),
          char(13)
        },
        {
          tohtml("&"),
          tohtml(">"),
          tohtml("<"),
          rule!GLBL_insertWordDocxLineBreak(num: 1),
          ""
        }
      )
    )

  • I have like that in some Word from Template and no issues

    That problem i had when i wanted a paragraph data in to a word.

Reply Children