Free Support Forum - aspose.com

Remove numbering and bulleting for unmerged content

Hi,

We are using Aspose Words.Net for merging the contents from various documents into the main document conditionally.

The main document maintains the formatting like bullet points and numbering etc. In case, the content doesn't satisfy a condition it will not be merged into the main document and this causes empty bullet points or numbers in the final document. I would like to know if there is a way to remove these unmerged bullet points or numbers from the document.

Please advise.

Thanks.

Regards,

Ashish.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You can try using the following code to achieve this:

// Open documents.

Document doc = new Document(@"Test001\sample.doc");

// Get all paragraphs in the document.

Node[] paragraphs = doc.GetChildNodes(NodeType.Paragraph, true).ToArray();

// Remove paragraph if it is an empty list item.

foreach (Paragraph paragraph in paragraphs)

{

if(paragraph.IsListItem && !paragraph.HasChildNodes)

paragraph.Remove();

}

// Save output document.

doc.Save(@"Test001\out.doc");

Hope this helps.

Best regards.

Hi,

Thanks for your response. Additionally we have a situation where this unmerged content may be in a table. Is there any way to remove these empty tables / rows / cells. We currently have a list of unmerged fields - sample below.

foreach (TargetMergeFieldAbstract item in nonMergeFieldList){

while (builder.MoveToMergeField(item.Name))

{

if (builder.ListFormat.IsListItem)

builder.ListFormat.RemoveNumbers();

if (!builder.CurrentParagraph.HasChildNodes)

builder.CurrentParagraph.Remove();

}

builder.MoveToDocumentStart();

}

Regards,

NCS Team.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. in this case, I think, you can just get parent table/row/cell and remove it. Please see the following simple code:

// Move Documentbuilder cursor to the merge field.

builder.MoveToMergeField("myField");

// Get parent table.

Node table = builder.CurrentParagraph.GetAncestor(NodeType.Table);

// If table exists, thent remove it.

if (table != null)

table.Remove();

Hope this helps.

Best regards.