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
source share