Convert text from HTML to MS Word

I am trying to convert HTML (from CK editor) to MS Word:

wordDoc = new ActiveXObject("Word.Application"); 

But the result shows all HTML tags (e.g. span , strong ) in a Word document.

How can I solve this problem?

+6
source share
5 answers

While you are looking for a WORD solution, can a PDF solution work? Try http://www.fpdf.org if so. But then again, this will not work if you absolutely must have WORD as the final result. If you do not need a user to enter a document, PDF files are usually better because they do not allow the user to modify.

0
source

According to your question, I understand that you want HTML in Word with all style (Css Apply)

I have such requirenmnet in which I implemented below code that it works for me. please check below code, maybe it will help you completely

here I create a Word file from a GridView, and I applied Style to this grid.it, creating the same Grid file in Word as in the browser. You only need to change the associated style tag (css) for your work.

 Protected Sub CreateHTMlToWord() Try Dim sHtml As New StringBuilder Dim htmlForm As New HtmlForm grdHTMLData.GridLines = GridLines.Both 'Grid View Fill with data Response.ClearContent() Response.AddHeader("content-disposition", "attachment; filename=estPage.doc") Response.ContentType = "application/vnd.doc" Dim str As New IO.StringWriter Dim htex As New HtmlTextWriter(str) htmlForm.Controls.Add(grdHTMLData) htmlForm.EnableViewState = False Me.Controls.Add(htmlForm) htmlForm.RenderControl(htex) sHtml.Append("<html>") sHtml.Append("<head>") sHtml.Append("<style type='text/css'>") sHtml.Append(".mGrid{width: 100%; background-color: #F8FCFE; margin: 5px 0 10px 0; border-collapse: collapse;}") sHtml.Append(".mGrid td{ padding: 2px; color: black;} .mGrid td a:link{ color: #000;}") sHtml.Append(".mGrid th{ padding: 4px 2px; color: #fff; background: #4A7298; font-size: 0.9em;}") sHtml.Append(".mGrid th a:link{ color: #fff; font-weight: bold;} .mGrid .alt{ background-color: #E1EEF7;}") sHtml.Append(".mGrid .pgr{ background: #E1EEF7;} .mGrid .pgr table{ margin: 5px 0;}") sHtml.Append(".mGrid .pgr td span{ border-width: 0; font-weight: bold; color: #666; line-height: 12px;}") sHtml.Append(".mGrid .pgr td a{ color: #666;} .mGrid .pgr td a:link{ color: #4A7298; padding: 0 5px; text-decoration: underline;}") sHtml.Append(".mGrid .pgr td a:active{ text-decoration: none; font-weight: bold;}") sHtml.Append(".mGrid .pgr td a:hover{ color: #fff; background-color: #4A7298; text-decoration: none;} .mGrid a:hover{ text-decoration: underline;}") sHtml.Append(".mGridHdr th{ text-align: left;}") sHtml.Append("</style>") sHtml.Append("</head>") sHtml.Append("<body>") sHtml.Append(str.ToString) sHtml.Append("</body>") sHtml.Append("</html>") Response.Write(sHtml.ToString) Response.Flush() Response.Close() Catch ex As Exception End Try End Sub 
0
source

Pandoc allows you to convert between html and text documents (among many other formats). Pandoc is a haskel library, but there is a built-in installer for the entire platform. To convert a document, you will need to use this command.

 pandoc -o file.doc file.html 
0
source

What I could imagine is as follows:

  • Translates HTML into OpenXML,
  • then create files that match the structure of the word document,
  • Zip to docx.
0
source

All Articles