AppendHTML with multiple paragraphs does not apply BeforeSpacing and AfterSpacing

Hello community,

I have HTML-Code like this:

<p>Paragraph first</p>
<ul>
<li>Test 1</li>
   <li>Test 2</li>
</ul>
<p>Paragraph between</p>
<p>Paragraph last</p>

I would like to insert this HTML code into a Word document. For this I use the following code:

IWParagraph Paragraph1 = section.AddParagraph();
Paragraph1.ParagraphFormat.BeforeSpacing = 0;
Paragraph1.ParagraphFormat.AfterSpacing = 0;
Paragraph1.ParagraphFormat.SpaceAfterAuto = false;
Paragraph1.ParagraphFormat.SpaceBeforeAuto = false;
Paragraph1.AppendHTML("HTML-Code...");

Unfortunately, the formatting BeforeSpacing and SpaceBeforeAuto are applied only to the first paragraph <p> and AfterSpacing and SpaceAfterAuto are applied only to the last paragraph <p>. For the paragraphs in between, my specifications are ignored and set to "auto". The spacing is so much too big. How can I control this?

Unbenannt.png

I've been trying to solve this problem for hours.

Does anyone have a solution?

With best regards

Robert


2 Replies

LB Lokesh Baskar Syncfusion Team February 8, 2022 06:32 PM UTC

Hi Robert,

When we insert the HTML string in Word document using Microsoft Word application, the content having before and after spacing are auto. Please refer to the below screenshot.

It is the Microsoft Word behavior. Essentials DocIO also does the same thing while appending the HTML string.

To acheive your requirement, you can apply formatting after appended the HTML into Word document by iterating the paragraphs in the Word document .
 


Regards,
 
Lokesh B 
 



RL Robert Lassen February 8, 2022 08:03 PM UTC

Hi Lokesh,


thank you very much for your great support.

The solution works perfectly.


Regards

Robert



Loader.
Up arrow icon