I'm debugging variable results is not the same as in the word display

When debug code, I watch variable p.Range.Text content, I found:the p.Range.Text is (1) test word 1。\r (2) test word 2 3 4。 \r (3) test word 5 6;\r. See Fig 1.

But It display three different row in the TestFile.docx

My code,

doca = new Aspose.Words.Document("TestFile.docx");
foreach (Aspose.Words.Paragraph p in doca.Sections[0].Body.Paragraphs)
{
    p.Range.Replace(new Regex(@"([\u002c])"), ",");
}

Hi Li,

Thanks for your inquiry. This is the expected behavior. This happens because a single Paragraph spans across multiple lines because of Carriage Return characters. Please see the following sample to see Carriage Return character behavior in MS Word:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Before " + 
    ControlChar.Cr + 
    ControlChar.Cr + 
    ControlChar.Cr + 
    ControlChar.Cr + 
    ControlChar.Cr + 
    "After");
doc.Save(MyDir + @"15.12.0.docx");

If we can help you with anything else, please feel free to ask.

Best regards,

How can I through the code, can adjust a single Paragraph with multi Return characters(\r) to different rows(Paragraph) ?

Hi Li,

Thanks for your inquiry. Could you please attach your expected Word document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will then provide you code to achieve the same using Aspose.Words.

Best regards,

When debug code, I watch variable p.Range.Text content, I found:the p.Range.Text is (1) test word 1。\r (2) test word 2 3 4。 \r (3) test word 5 6;\r. See Fig 1.
<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:
“Calibri”,sans-serif;mso-ascii-theme-font:minor-latin;mso-fareast-font-family:
宋体;mso-fareast-theme-font:minor-fareast;mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:“Times New Roman”;mso-bidi-theme-font:minor-bidi;
mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>But
It display three different row in the TestFile.docx

Hi Li,

Thanks for your inquiry. You have attached the same documents again which were also attached to your first post. We need your expected Word document to investigate its structure as to how you want your final output be generated like. You can create expected document using Microsoft Word. We will then provide you code to achieve the same using Aspose.Words.

Best regards,

This attached OutputFile.docx is my expected Word document.TestFile.docx is my the original documents with something wrong

Hi Li,

Thanks for the additional information. We are working over your query and will get back to you soon.

Best regards,

Any new progress?Thanks

Hi Li,

Thanks for being patient. Please try using the following code (see attached 15.12.0.docx):

Document doc = new Document(MyDir + @"TestFile.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (Run run in doc.GetChildNodes(NodeType.Run, true))
{
    if (run.Text.Contains(ControlChar.Cr))
    {
        builder.MoveTo(run);
        builder.InsertBreak(BreakType.ParagraphBreak);
        run.Text = run.Text.Replace(ControlChar.Cr, "");
    }
}
doc.Save(MyDir + @"15.12.0.docx");

Hope, this helps.

Best regards,