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.

Wed Jun 03, 2020 1:56 pm

Hello!
Can I add a HTML in a string into a Word File and respect the HTML attributes?

Something like this
Code: Select all
string htmlText = "<ol><li>Just a test file</li></ol>";

Paragraph paragraphNew = new Paragraph(document);
paragraphNew.AppendText(htmlText);

body.ChildObjects.Insert(index, paragraphNew.Clone());

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Wed Jun 03, 2020 5:49 pm

Update:
Already found a function called AppendHTML

But I got a error using that
"Object reference not set to an instance of an object."

Follow the code below
Code: Select all
 Paragraph ParagraphHTML = new Paragraph(document);
 ParagraphHTML.AppendHTML("<p>Test</p>");

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Wed Jun 03, 2020 10:01 pm

Update2:

I did it!

The solution that I found is: Modify the original paragraph that I got from the search of a stringName, and use AppendHTML
Still dont know why when I use AppendHtml into a new paragraph give me error.

But ok, that's working for me xD

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Thu Jun 04, 2020 2:30 am

Hello,

Thanks for your post.
I did notice that you mentioned when adding HTML text into a new paragraph, the application would threw the error "Object reference not set to an instance of an object". I have posted it to our Dev team with the ticket SPIREDOC-4580 for further investigation and fixing. We will let you know if there is any update.
Besides, you can refer to the following code to avoid this issue.
Code: Select all
    Document document = new Document();
    Section section = document.AddSection();

    ////workaround 1:
    //Paragraph para = new Paragraph(document);
    //section.Body.ChildObjects.Insert(0, para);
    //para.AppendHTML("<p>Test</p>");

    //workaround 2:
    Paragraph para = section.AddParagraph();
    para.AppendHTML("<p>Test</p>");


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Jun 05, 2020 12:53 pm

rachel.lei wrote:I did notice that you mentioned when adding HTML text into a new paragraph, the application would threw the error "Object reference not set to an instance of an object". I have posted it to our Dev team with the ticket SPIREDOC-4580 for further investigation and fixing. We will let you know if there is any update.


Cool! don't worry, that's working for me!
I was trying to insert the html before insert the paragraph on the document.
Didn't tried insert in the document first xD

Thanks!

kevinka999
 
Posts: 16
Joined: Wed Apr 08, 2020 7:09 pm

Mon Jun 08, 2020 1:24 am

Hello,

Thanks for you response.
And as for the issue of SPIREDOC-4580, our Dev team will continue to investigate it and find the solution to resolve it. If it is fixed, we will let you know.
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Mar 03, 2021 9:07 am

Hello,

Hope you are doing well.
Regarding the issue SPIREDOC-4580, I got news from our Dev team that you must first insert the paragraph into the document, and then insert the HTML, just like the two workarounds I provided above. Hope you can understand.

If you have any other questions, please feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc