Spacing between Paragraphs

Hi Team,

I am building a Word Document. In the final generated word document, some of the paragraphs have one line spacing in between and some do not. I am trying to add space(one blank line) between those paragraphs which do not have space in between. For this I am working on Find and Replace approach and trying to use Regular expression in it. Could you please help me with this piece of code. I am trying something like this:

Dim docDoc As Document = New Document
.
{code for doc generation}
.
docDoc.Range.Replace(New Regex("^p[A-Z]"), “MyWord”)

In the above I am trying to find, paragraph tag and just after that any Uppercase alphabet(will also include digits). But the above code does not seem to work. Could you please help with this.

Also I need to find a way to insert one blank line in between ^p and [A-Z] (instead of “MyWord”) above.

Thanks in advance.

Hi,

Could you please help me in implementing the below scenario through aspose:
I would like to perform Find and Replace with “Use Wildcard” option ticked.

Hi,

Thanks for your inquiry. Could you please attach your 1) input Word document, 2) Aspose.Words generated output document which shows the undesired behavior and 3) expected document here for testing? You can generate your expected document using Microsoft Word. We will investigate the scenario on our end and provide you code to achieve the same using Aspose.Words.

Best regards,

Hi Hafeez,

I have mailed you the relevant documents on Friday. Could you please have a look at it and do the needful ASAP.
Please let me know in case you haven’t received the mail.

Regards,
Dheeraj

Hi Dheeraj,

Thanks for your inquiry. I can offer you a simple way to achieve this. Please see the following code:

Document doc = new Document(MyDir + @"OriginalOutput.doc");
NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph p in paras)
    if (p.ChildNodes.Count == 0 || p.ToString(SaveFormat.Text).Trim().Equals(""))
        p.Remove();
Node[] paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).ToArray();
foreach (Paragraph p in paragraphs)
    p.ParentNode.InsertAfter(new Paragraph(doc), p);
doc.Save(MyDir + @"out.doc");

I hope, this helps.

Best regards,

Thank you Hafeez. I will surely try this piece of code and get back. If possible can you help with the corresponding VB.NET code

Hi Hafeez,

Really appreciate your sincere effort. The code you provided worked perfectly. Thanks a ton.
Have an additional query. Have mailed you the relevant documents and the issue.

Regards
Dheeraj

Hi Dheeraj,

Thanks for your inquiry. You can make use of ParagraphFormat.SpaceAfter and ParagraphFormat.SpaceBefore properties to adjust vertical spacing between paragraphs: e.g.

foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
    p.ParagraphFormat.SpaceBefore = 20;
    p.ParagraphFormat.SpaceAfter = 20;
}

Best regards,