I've a form where an webrowser contains a html file. I want to copy a selective portion of the html content and paste that content in an excel 2007 file where it will be pasted as a normal text (not in HTML code). I want to have the excel part should be as it is done manually (i.e. it should be in proper format as it is in the HTML file).
Platform/OS/Version : GUI/Windows XP/2005
Language :Vb.Net
Platform/OS/Version : GUI/Windows XP/2005
Language :Vb.Net
Code:
Private Sub frmParse_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
WebBrowser1.Navigate(New Uri("http://sec.gov/Archives/edgar/data/1089951/000119312508074840/0001193125-08-074840-index.htm"))
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim sr As StreamReader = New StreamReader(WebBrowser1.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