We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Removing white line on exisiting .dot file

Hi Team,

We are using Aspose.Words Java and we are facing one issue while replacing a text in existing .dot template file. In our case, the text to be replaced is on a single cell. Single cell has some other contents with line break ("\r"). When we replace the text with empty value, we are getting whitespace line and could not able to remove the line. Here is the contents looking like in our. dot file. Please find the attached templates for your reference.

Addr name

Addr Line 1

Addr Line 2

State

City

In our case, Addr Line 1 or Addr Line 2 might be empty. After replacing we got

Addr name

Addr Line 1

<>

State

City

We have tried removing the text Addr Line 2 from that cell using run.remove() method but still that line is not getting removed.

Hi Naveen,

Please try using the following code:

Document doc = new Document(MyDir + @"outputTemplate.dot");
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    if (string.IsNullOrEmpty(para.ToString(SaveFormat.Text).Trim()))
    {
        para.Remove();
    }
}
doc.Save(MyDir + @"16.12.0.docx");

Best regards,

Thanks for your quick and prompt response. Yes, we have tried the same solution after we had posted this post on your forum and it worked great.

Anyway, I greatly appreciate your support and help on this.

Happy New Year!!!

Thanks
Naveen Venkat

Hi Naveen,

It is great you were able to find what you were looking for. Please let us know any time you have any further queries. Happy new year to you as well.

Best regards,