I'm getting problem in pasting HTML text in Excel 2007 whereas it is working fine in Excel 2003. The data pasted in excel 2007 is showing the the HTML code which is not desired. I need to have the text element as normal copy from HTML file in web browser is pasted in the opened excel cell (manual operation).
I'm enclosing the code I've written in the following :
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim sr As StreamReader = New StreamReader(WebBrowseSP.DocumentStream)
-
Dim xlAppOut As Excel.Application
-
Dim xlBookOut As Excel.Workbook
-
Dim xlSheet1 As Excel.Worksheet
-
xlAppOut = CreateObject("Excel.Application")
-
xlBookOut = xlAppOut.Workbooks.Add
-
xlSheet1 = xlBookOut.Worksheets.Item(1)
-
xlAppOut.Visible = True
-
Clipboard.Clear()
-
Dim strContent As String = GetSelection(WebBrowser1)
-
Clipboard.SetText(strContent)
-
xlSheet1.paste()
-
End Sub
-
-
Private Function GetSelection(ByVal webBrowser As WebBrowser) As String
-
GetSelection = ""
-
Dim doc As IHTMLDocument2 = CType(webBrowser.Document.DomDocument, IHTMLDocument2)
-
Dim sel As IHTMLSelectionObject = doc.selection
-
Dim range As IHTMLTxtRange = CType(sel.createRange, IHTMLTxtRange)
-
GetSelection = range.htmlText
-
End Function
-