Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu May 18, 2017 5:52 am

Hello Support Team,

I run on an issue when appending html to a new paragraph.
e.g.
<div>Text1</div>
<div>Text2</div>
<div>Text3</div>
<div>Text4</div>

If I append the html and indent the paragraph, only the text from the first tag (Text1)
is affected. Text2 etc. has no indentation. I have this behavior regardles of doing indetation by
setting the property
paragraph.Format.LeftIndent = 10;
or applying a style
paragraph.ApplyStyle(styleWithIndentation)

How can I affect the whole paragraph with all its html content?

As I can see, it creates more then on paragraph from the html. Is there a way to access all the generated paragraphs an set the style?

<w:p w:rsidR="005F7EF8" w:rsidRDefault="0073235D" w:rsidP="005A4F1C">
<w:pPr>
<w:pStyle w:val="Liste4"/>
<w:divId w:val="1"/>
</w:pPr>
<w:r>
<w:t xml:space="preserve"> Text1 </w:t>
</w:r>
</w:p>
<w:p w:rsidR="005F7EF8" w:rsidRDefault="0073235D">
<w:pPr>
<w:divId w:val="3"/>
</w:pPr>
<w:r>
<w:rPr>
<w:sz w:val="24"/>
</w:rPr>
<w:t>Text2</w:t>
</w:r>

Best regards,
Arne

arne.weber@webtelligence.net
 
Posts: 19
Joined: Mon Sep 19, 2016 6:52 am

Thu May 18, 2017 8:07 am

Hello,

Thanks for your inquiry.
Kindly note that each div tag will be parsed as a paragraph, thus the code "paragraph.Format.LeftIndent = 10" only works on the first paragraph, that is "Text1". After investigation, sorry there's no approach to set a style to all the generated paragraphs from a certian html string directly since it's hard to detect how many paragraphs there are in the html. Concerning your case, we suggest you add the style in the html string or just manually set the format for the 4 paragraphs .
Code: Select all
 Document document = new Document(inputFile);
            Section s = document.Sections[0];
            Paragraph p = s.AddParagraph();
            p.AppendHTML("<div>Text1</div><div>Text2</div><div>Text3</div><div>Text4</div>");
            int index = s.Paragraphs.IndexOf(p);
            for (int i = 0; i < 4;i++ )//you need to know the paragraph amount of the html
            {
                s.Paragraphs[index].Format.LeftIndent = 10;
                index++;
            }

If there's any problem, please feel free to contact us.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.Doc