This is a desktop application. So how can I add '
<meta charset="utf-8" />' to it. Below is the code I used to convert html to docx.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles RadButton2.Click
Dim filepaths As String = Application.StartupPath & ("\analyserExport")
'Table start.
Dim html As String = "<table cellpadding='5' cellspacing='0' style='border: 1px solid #ccc;font-size: 9pt;font-family:tahoma'>"
html &= "<tr>"
For Each column As DataGridViewColumn In DataGridView2.Columns
html &= "<th style='background-color: #B8DBFD;border: 1px solid #ccc'>" & column.HeaderText & "</th>"
Next
html &= "</tr>"
'Adding DataRow.
For Each row As DataGridViewRow In DataGridView2.Rows
html &= "<tr>"
For Each cell As DataGridViewCell In row.Cells
html &= "<td style='width:250px;border: 1px solid #ccc'>" & cell.Value.ToString() & "</td>"
Next
html &= "</tr>"
Next
'Table end.
html &= "</table>"
'Save the HTML string as HTML File.
Dim htmlFilePath As String = filepaths & "\" & "Export.htm"
File.WriteAllText(htmlFilePath, html)
'Convert the HTML File to Word document.
Dim word As Microsoft.Office.Interop.Word.Application = New Microsoft.Office.Interop.Word.Application
Dim wordDoc As Microsoft.Office.Interop.Word.Document = word.Documents.Open(FileName:=htmlFilePath, ReadOnly:=False)
wordDoc.SaveAs(FileName:=filepaths & "\" & "Export.doc", FileFormat:=Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF)
CType(wordDoc, Microsoft.Office.Interop.Word.Document).Close()
CType(word, Microsoft.Office.Interop.Word.Application).Quit()
File.Delete(htmlFilePath)
End Sub