Converting Carriage Return Line Feed

I have a database field that has carriage return line feeds saved in it. This database field is then put into an xml document. That xml document is parsed and the word document is created using aspose.words using the replace functions.
Instead of the carriage return line feeds in my word document, I get the boxes, just like they are displayed in the sql server database table.
My question is, how can I get the carriage return line feeds to be evaluated correctly?
What I get in my word doc is shown in the attachment to this post.
My text should look like this:
EMK3 Sales
15770 N Dallas Parkway
Dallas, TX 75248
Attn: Terry Coulter
972-267-3653 x.900

Hello!
To look like this strings should be split into paragraphs:

builder.Writeln("EMK3 Sales");
builder.Writeln("15770 N Dallas Parkway");
builder.Writeln("Dallas, TX 75248");
builder.Writeln("Attn: Terry Coulter");
builder.Writeln("972-267-3653 x.900");

There is no way to perform this in one call.
You can use Writeln in the loop finding line feeds or prepare the list of strings and then output them one by one.
Regards,

Is there not a Word equivalent of the vb constant vbCrlf?

I am using templates and the Range.Replace function instead of builders. I need to be able to replace the carriage return line feeds and then replace the section with the formatted text.

HeaderSection.Range.Replace("<<" & sNodeName.ToString.Trim & ">>", sNodeValue.ToString.Trim, False, False)

Would you send me a sample code which replaces a range with that value containing CR + LF? Please take a look how line breaks are represented in your application after parsing. When I explicitly insert vbCrlf it is split by a paragraph break:

builder.Writeln("EMK3 Sales" + vbCrLf + "15770 N Dallas Parkway")

Builder doesn’t confuse the way the characters are interpreted.
Most probably character sequences after parsing should be replaced with vbCrlf first.
Thank you,

sNodeName is the attribute name in the XML and is found in the doc template.
sNodeValue is the attribute value and has the vbCrlf value already in it. When it gets to the document the vbcrlf is displayed as a box instead of a line feed.
I can’t add multible lines, I am replacing a field in a template with formated text.

For aX = 0 To numAttributes - 1
oAttribute = oAttributes(aX)
sNodeName = oAttribute.Name
sNodeValue = oAttribute.Value
HeaderSection.Range.Replace("<<" & sNodeName.ToString.Trim & ">>", sNodeValue.ToString.Trim, False, False) 
Next

As an alternative, is it possible to replace that field in the template with the results of the builder.
For example

HeaderSection.Range.Replace("<<" & sNodeName.ToString.Trim & ">>", DocumentBuilder.ToString, False, False)

Hello!
This issue was logged as #3223. It is to be fixed in one of the next versions. Now you can use these workarounds you’ve already found.
Regards,

Hi
I investigated the issue mentioned above and I think it is not a bug in Aspose.Words. Aspose.Words does not allow using special characters in a captured or replacement string.
https://reference.aspose.com/words/net/aspose.words/range/replace/
If you need to use special characters in replacement string, you can easily achieve this using IReplacingCallback. I created a simple code example that demonstrates the technique you can use:

[Test]
public void Test001()
{
    Document doc = new Document("in.doc");
    doc.Range.Replace(new Regex("test"), new ReplaceEvaluatorFindAndInsertText("Here you can insert any text\nWith special characters you want\fall of them will be properly handled"), false);
    doc.Save("out.doc");
}
private class ReplaceEvaluatorFindAndInsertText : IReplacingCallback
{
    public ReplaceEvaluatorFindAndInsertText(string text)
    {
        mText = text;
    }
    /// 
    /// This method is called by the Aspose.Words find and replace engine for each match.
    /// This method replaces the match string, even if it spans multiple runs.
    /// 
    ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)
    {
        // This is a Run node that contains either the beginning or the complete match.
        Node currentNode = e.MatchNode;
        // The first (and may be the only) run can contain text before the match, 
        // in this case it is necessary to split the run.
        if (e.MatchOffset > 0)
            currentNode = SplitRun((Run)currentNode, e.MatchOffset);
        // This array is used to store all nodes of the match for further removing.
        ArrayList runs = new ArrayList();
        // Find all runs that contain parts of the match string.
        int remainingLength = e.Match.Value.Length;
        while (
        (remainingLength > 0) &&
        (currentNode != null) &&
        (currentNode.GetText().Length <= remainingLength))
        {
            runs.Add(currentNode);
            remainingLength = remainingLength - currentNode.GetText().Length;
            // Select the next Run node. 
            // Have to loop because there could be other nodes such as BookmarkStart etc.
            do
            {
                currentNode = currentNode.NextSibling;
            }
            while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));
        }
        // Split the last run that contains the match if there is any text left.
        if ((currentNode != null) && (remainingLength > 0))
        {
            SplitRun((Run)currentNode, remainingLength);
            runs.Add(currentNode);
        }
        // Create Document Buidler aond insert text
        DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);
        builder.MoveTo((Run)runs[runs.Count - 1]);
        builder.Write(mText);
        // Now remove all runs in the sequence.
        foreach (Run run in runs)
            run.Remove();
        // Signal to the replace engine to do nothing because we have already done all what we wanted.
        return ReplaceAction.Skip;
    }
    /// 
    /// Splits text of the specified run into two runs.
    /// Inserts the new run just after the specified run.
    /// 
    private static Run SplitRun(Run run, int position)
    {
        Run afterRun = (Run)run.Clone(true);
        afterRun.Text = run.Text.Substring(position);
        run.Text = run.Text.Substring(0, position);
        run.ParentNode.InsertAfter(afterRun, run);
        return afterRun;
    }
    private string mText;
}

Hope this helps. Please let us know if you need more information. We will be glad to help you.
Best regards,

The issues you have found earlier (filed as WORDSNET-1252) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(23)