vb.net - WebBrowser.DocumentText Property in WPF -
i have browser control, feeted text & plots etc. looks fine in browser control.
now want export browser content word file can exported pdf/html/doc etc
this works fine windows forms. use webbrowser1.documenttext property , write file etc. command:
(system.io.file.writealltext(tempfilename, webbrowser1.documenttext)
unfortunaley webbrowser.documenttext property no more available in wpf. how can solve problem ?
here´s code forms:
imports system.drawing imports microsoft.office.interop.word imports system.windows.forms imports system.io private sub button4_click(sender object, e eventargs) handles button4.click ' save document html, mhtm (embedded), document or pdf if dlgsavedoc.showdialog = system.windows.forms.dialogresult.ok ' create temp file of web browser document dim tempfilename string tempfilename = system.io.path.gettemppath() & "\" & now.tostring().replace(":", "") & "_repgen" & ".html" system.io.file.writealltext(tempfilename, webbrowser1.documenttext) ' load temp file word dim oword microsoft.office.interop.word.application dim odoc microsoft.office.interop.word.document oword = createobject("word.application") try ' debug, show word oword.visible = true odoc = oword.documents.open(tempfilename) try ' depending on file type (extension), set save format dim sf wdsaveformat dim ext string = path.getextension(dlgsavedoc.filename).toupper() if ext.startswith(".htm") sf = wdsaveformat.wdformathtml if ext.startswith(".mht") sf = wdsaveformat.wdformatwebarchive if ext.startswith(".doc") sf = wdsaveformat.wdformatxmldocument if ext.startswith(".pdf") sf = wdsaveformat.wdformatpdf ' save file word odoc.saveas2(dlgsavedoc.filename, sf) odoc.close() odoc = nothing end try oword.quit() oword = nothing ' cleanup if file.exists(tempfilename) file.delete(tempfilename) end try end if end sub
this works fine ...even plots etc no problem:
i used wpf:
dim tempfilename string = "e:test.doc dim doc object = browser.document dim htmltext = doc.documentelement.innerhtml system.io.file.writealltext(tempfilename, htmltext)
instead of (for winforms)
system.io.file.writealltext(tempfilename, webbrowser1.documenttext)
Comments
Post a Comment