Remove blank line when inserted Table

Hi there,
I have a doc template where the there is a word “[acriticaltable]” and
“Table: Asset criticality assessment” and then replace the “[acriticaltable]” with:

optA.ReplacingCallback = aReplaceWithTableCallback;
doc.Range.Replace("[acriticaltable]", "", optA);

It works, but after the table and before the word “Table: Asset criticality assessment” , there is a new line, although in the templated there is no that line. How to remove it?

I attach two pictures and 1 doc template and 1 doc result
DISP SRA (24).docx (264.6 KB)

BeautySectara01.docx (74.5 KB)

regards
no_line_template


new line

@ibox Looks like the table is inserted from HTML. If so, please try using the HtmlInsertOptions.RemoveLastEmptyParagraph:

builder.InsertHtml(html, HtmlInsertOptions.UseBuilderFormatting | HtmlInsertOptions.RemoveLastEmptyParagraph);

This option instructs Aspose.Words to remove the empty paragraph that is normally inserted after HTML that ends with a block-level element, such as table.

Thank you, Sir,

But it is not html. I create the table manually:

       }
       builder.EndRow();
   }
   builder.EndTable();

and then do the replace
regards
code aspose.zip (13.5 KB)

@ibox Please try modifying code like this:

Paragraph para = matchedRuns.First().ParentParagraph;

// Delete matched runs
foreach (Run run in matchedRuns)
    run.Remove();

if (string.IsNullOrEmpty(para.ToString(SaveFormat.Text).Trim()))
    para.Remove();

After removing runs of the placeholder, the paragraph remains and you see it as empty line.

Thank You, Sir
It works like a charm
regards

1 Like