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 May 06, 2019 12:12 pm

Hello,

I am reading a Html File, and I want to convert it to a Word File.

I am using this code:

Code: Select all
Document docHTML = new Document();
docHTML.LoadHTML(new StreamReader("example.html"), XHTMLValidationType.None);
docHTML.SaveToFile("htmlToWord.doc", FileFormat.Doc);


and this code too:

Code: Select all
Document docHTML = new Document();
docHTML.LoadFromFile("example.html", FileFormat.Html, XHTMLValidationType.None);
docHTML.SaveToFile("htmlToWord.doc", FileFormat.Doc);


but the Word File is not with the correct format. You can see it in the two attachments uploaded.
The Word File have a lot of line breaks.


Can you help me to solve this problem?
I want the Word File format to be the same as the Html format.

Sincerely
Fernando.

FerJR
 
Posts: 3
Joined: Mon May 06, 2019 11:50 am

Tue May 07, 2019 10:02 am

Hi,

Thank you for contacting us.
I tested your HTML with the latest Spire.Doc Pack(hot fix) Version:7.5.1, but I didn't find the issue you encountered. Attached is my genereated .doc file . If you were using an old version, I would suggest that you try the latest one. If the issue still occurs after trying, Please provide your system configuration (E.g. Win 7, 64 bit) and your region setting (E.g. China/Chinese) to help us further look into your issue. Thanks in advance.

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Tue May 07, 2019 10:37 am

nancy.yang wrote:Hi,

Thank you for contacting us.
I tested your HTML with the latest Spire.Doc Pack(hot fix) Version:7.5.1, but I didn't find the issue you encountered. Attached is my genereated .doc file . If you were using an old version, I would suggest that you try the latest one. If the issue still occurs after trying, Please provide your system configuration (E.g. Win 7, 64 bit) and your region setting (E.g. China/Chinese) to help us further look into your issue. Thanks in advance.

Sincerely,
Nancy
E-iceblue support team



Hi,

I updated my version to 7.5.1 (hot fix) but the issue is still ocurring (.doc generated in attachments).
My system is:
Win 10, 64 bit
Español/Spain
The project is a .NET Framework 4.7.1, and i have seen that the latest dll of the release hot fix of Spire is for .NET 4.6 ¿Could it be the reason?

Sincerely,
Fernando.

FerJR
 
Posts: 3
Joined: Mon May 06, 2019 11:50 am

Wed May 08, 2019 3:20 am

Hi,

Thanks for your quick feedback.
With the same Region setting as yours, I have noticed your issue. To avoid it, please set the CurrentCulture as InvariantCulture. Below is my testing code. Just feel free to write back if there is any question.
Code: Select all
            CultureInfo cc = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Document docHTML = new Document();
            docHTML.LoadFromFile("HtmlMedio.html", FileFormat.Html, XHTMLValidationType.None);
            docHTML.SaveToFile("htmlToWord.doc", FileFormat.Doc);
            Thread.CurrentThread.CurrentCulture = cc;

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Wed May 08, 2019 7:07 am

Hi,

Thanks for your help.
I tried with your code and It solved my problem.

Sincerely,
Fernando.

FerJR
 
Posts: 3
Joined: Mon May 06, 2019 11:50 am

Wed May 08, 2019 9:21 am

Hi,

Thanks for your feedback.
If there is anything we can do for you in the future, please do not hesitate to contact us.
Wish you all the best!

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Return to Spire.Doc

cron