We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Convert Html String to word document

Thread ID:

Created:

Updated:

Platform:

Replies:

145749 Jul 6,2019 07:45 AM UTC Aug 2,2019 06:44 AM UTC ASP.NET Web Forms 10
loading
Tags: DocIO
Sarvana
Asked On July 6, 2019 07:45 AM UTC

I have tried converting HTML string to word document. But am getting error  "docio support only well formatted xhtml". Here is my code sample 

               string htmlText = htmlContent;
               WordDocument wordDocument = new WordDocument();
               IWSection section = wordDocument.AddSection();
               section.Body.IsValidXHTML(new XhtmlString(htmlText), wordDocument.XHTMLValidateOption);
               section.Body.InsertXHTML(htmlContent);
       wordDocument.Save("Sample.doc", FormatType.Html, Response, HttpContentDisposition.InBrowser);
Above is my code, can you help me in this.Thanks.,


Mohanaselvam  Jothi [Syncfusion]
Replied On July 8, 2019 07:02 AM UTC

Hi Sarvana,

Thank you for contacting Syncfusion support.

Essential DocIO supports converting the HTML file into Word document and vice versa. It supports HTML with XHTML 1.0 compliant for HTML conversion. We suspect that the input HTML doesn’t meet XHTML 1.0 compliant, so the reported problem occurs at your end.

Please refer the below UG documentation link to know more about converting the HTML file into Word document using DocIO:
https://help.syncfusion.com/file-formats/docio/conversion#html-conversion  

Please let us know if you have any other questions.

Regards,
Mohanaselvam J 


Sarvana
Replied On July 8, 2019 12:10 PM UTC

Hey Mohan,
                 can you provide some samples.

Poorani Rajendran [Syncfusion]
Replied On July 9, 2019 09:32 AM UTC

Hi Saravana,

Thank you for your update.

We have prepared sample for converting HTML file into Word document and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145749/ze/CreateWordFile1693168057_21530295238

Please let us know if you have any other questions.

Regards,
Poorani Rajendran
 


Sarvana
Replied On July 18, 2019 07:33 AM UTC

Hi, 

 Am able to convert the Html string to PDF file, but the same Html string is using for converting word, it's giving the error, am not able to convert, I have tried using your samples, from there also I facing the problems. Herewith I have attached the my Html string in the notepad format and pdf in Image format. 

Poorani Rajendran [Syncfusion]
Replied On July 18, 2019 02:11 PM UTC

Hi Saravana,

Thank you for your update.

We have tried to reproduce the reported problem while converting HTML string into Word document, but it works properly at our end. For your reference, we have attached the sample application which we tried at our end and it can be downloaded from the below link:
https://www.syncfusion.com/downloads/support/forum/145749/ze/CreateWordFile1693168057_21530295238

We suspect that the problem might be due to the code snippet and HTML input string used at your end. So, could you please share us the input HTML string and modified sample of above application to reproduce the issue. Based on the details, we will check on your problem and will share you the solution at the earliest.

Please let us know if you have any other questions.

Regards,
Poorani Rajendran


Poorani Rajendran [Syncfusion]
Replied On July 19, 2019 02:03 PM UTC

Hi Saravana,

Thank you for your update.

We have tried in the sample application as provided in our previous update (Updated on 7/18/2019) using your input file which is mailed through our Syncfusion support(HtmlFile), it throws not well formatted exception. On further analyzed your given input text file, we have found that it is not in the standard format of XHTML 1.0 compliant. Essential DocIO supports HTML with XHTML 1.0 compliant for converting HTML file to Word document and vice versa.

We suspect that the code snippet or HTML string used at your end is differed from the file you sent. So please share us the proper input text file and modified code snippet in sample application which is updated (Updated on 7/18/2019).

Based on the above details, we will analyze further on the reported problem and will provide you the appropriate solution at the earliest.

Please let me know if you have any other questions.

Regards,
Poorani Rajendran


Pon Geetha A J [Syncfusion]
Replied On July 24, 2019 10:07 AM UTC

Hello,

The same Html is used for converting Html to Pdf using Syncfusion. It's converting fine. But we are facing the issue while converting to Word format.

P.Sarvan MCA.,



Poorani Rajendran [Syncfusion]
Replied On July 24, 2019 12:16 PM UTC

Hi Saravana,

Thank you for your update.

From the given details, we suspect that you are using Essential PDF library to convert HTML into PDF directly (without any intermediate conversion) so, the reported problem doesn’t occurred at your end.
 
Essential DocIO is a Word library which supports HTML with XHTML 1.0 compliant for HTML conversions. As mentioned in our previous update, we have found that the input HTML content doesn’t meet the standard format of XHTML 1.0 compliant. So, it throws error while converting given HTML to Word document using Essential DocIO.

To resolve this problem at your end, we suggest you modify the input HTML string into well formatted HTML string with XHTML 1.0 compliant and then convert into Word document using DocIO.

Please let us know if you have any other questions.

Regards,
Poorani Rajendran


Pon Geetha A J [Syncfusion]
Replied On August 2, 2019 04:13 AM UTC

Hello,

I have used the same code which you sent previously. I just added the table in the code, but still, am not able to convert the word document. herewith am sending you code samples.
  string htmlText = @"<html><head><title> XHTML to Doc  </title></head>
                               <body><p><b>XHTML to Doc - Strict XHTML example</b></p><p></p>
<table>
   < tr >
      < th > Firstname </ th >
      < th > Lastname </ th >
      < th > Age </ th >
    </ tr >
    < tr >
      < td > Jill </ td >
      < td > Smith </ td >
      < td > 50 </ td >
    </ tr >
    < tr >
      < td > Eve </ td >
      < td > Jackson </ td >
      < td > 94 </ td >
    </ tr >
 </ table >
 
                                < p><b>Essential DocIO</b> now supports converting valid XHTML content to Doc content. The passed in content should be either XHTML 1.0 or 1.1 compliant.</p><p></p>
                               <p><b>XHTML 1.0 Strict</b></p>
                               <p>It is the same as HTML 4.01 Strict, but it follows XML syntax rules.</p>
                               </body></html>";
  
              WordDocument wordDocument = new WordDocument();
              IWSection section = wordDocument.AddSection();
              section.Body.IsValidXHTML(htmlText, wordDocument.XHTMLValidateOption);
              section.Body.InsertXHTML(htmlText);
              wordDocument.Save("ResultThree.doc", FormatType.Doc, Response, HttpContentDisposition.InBrowser);
              wordDocument.Close();



The above image is the error am getting while running the applicat
P.Sarvan MCA., 



Poorani Rajendran [Syncfusion]
Replied On August 2, 2019 06:44 AM UTC

Hi Sarvan,

Thank you for your update.

On analyzing with your input HTML string, we have found that the given input HTML content doesn’t meet the standard format of XHTML 1.0 compliant. As mentioned on our earlier update (
Updated on 7/24/2019), Essential DocIO is a Word library which supports HTML with XHTML 1.0 compliant for HTML conversions. So, it throws error while converting given HTML to Word document using Essential DocIO.

To meet your requirement, we have modified the input HTML string to standard format of XHTML 1.0 compliant. We have prepared a sample application along with modified input HTML string and it can be downloaded from the below link :
https://www.syncfusion.com/downloads/support/forum/145749/ze/ModifiedHTMLString1681353906

Please refer the below UG documentation link to know more about working with HTML document using DocIO:
https://help.syncfusion.com/file-formats/docio/html

Please let us know if you have any other questions.

Regards,
Poorani Rajendran


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon