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.

Mon Feb 13, 2017 8:26 pm

Hello!

I am working on a program where I would like to programmatically take HTML and insert it into a word doc, and have it show up in word as it does in HTML.

When I run a line of code like this :

Code: Select all
newParagraph.AppendHTML("<p style='font-weight:\"bold\"'>Font Weight = Bold</p><span><b>b tag</b></span><span><strong>strong tag</strong></span>");


the first part with "font-weight: 'bold'" shows up correctly in the generated document, but the <b> and <strong> tags seem to do nothing at all. I've tried all sorts of things, like using <p>, <span>, and <div> to separate these, but nothing seems to make the <b> or <strong> change the look of the text. Is there anything I can do to make the generated document obey the <b> and <strong> tags? I get the feeling I'm missing something about styles or something document wide, but would love some help!

Thanks much!

- Chris

nevi0030
 
Posts: 4
Joined: Mon Jan 16, 2017 7:09 pm

Tue Feb 14, 2017 3:32 am

Dear Chris,

Thanks for your inquiry.
I have tested the code with the latest Spire.Doc Pack(hot fix) Version:5.8.47, and noticed that the all textes are bold(see attachment), where has issue ? We will appreciate it if you could give us the result you want.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Feb 14, 2017 2:24 pm

Thank you for the response! I downloaded the files you suggested and put them into use in my program (pretty sure I already had this version, but I did it anyway). The results are the same. The first section is bolded, but the second and third are not. I wonder if a paragraph might only be allowed one format at most, or something like that? Is there a potentially better way for me to be importing formatted HTML into a document that I have already loaded into memory?

Thank you!

- Chris

nevi0030
 
Posts: 4
Joined: Mon Jan 16, 2017 7:09 pm

Wed Feb 15, 2017 2:05 am

Dear Chris,

Thanks for the information.
I just create a document and then append that HTML into it. Here is my testing code.
Code: Select all
            Document doc = new Document();
            Section sec = doc.AddSection();
            string code = "<p style='font-weight:\"bold\"'>Font Weight = Bold</p><span><b>b tag</b></span><span><strong>strong tag</strong></span>";
            Paragraph par = sec.AddParagraph();
            par.AppendHTML(code);
            doc.SaveToFile("9750.docx", FileFormat.Docx);

Could you please offer us the sample file you want to import formatted HTML and the entire code you were using for further investigation ?

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Feb 17, 2017 3:31 am

Thanks so much for the reply, this approach is a little different than what I was doing, so I will give it a try and let you know the results, thanks!

- Chris

nevi0030
 
Posts: 4
Joined: Mon Jan 16, 2017 7:09 pm

Fri Feb 17, 2017 8:14 am

Dear Chris,

Thanks for your feedback.
Did you finish the test ? Has your issue been resolved ?
If not, please offer us the sample file you want to import formatted HTML and the entire code you were.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Feb 21, 2017 5:05 am

Yeah! I got this working. My original method still doesn't work, but your suggestions led me down the right road to getting it straight, thank you so much for the help!

- Chris

nevi0030
 
Posts: 4
Joined: Mon Jan 16, 2017 7:09 pm

Tue Feb 21, 2017 5:38 am

Dear Chris,

Thanks for the feedback.
Please feel free to contact us if there is any question. We will be happy to help you.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc