c# - Find and replace using Microsoft.Office.Interop.Word does not support line break vb.net -


i using word document template predefined fields(bookmarks)! bookmarks problematically updated actual value @ run time , works fine, of word in document not marked bookmark using find & replace feature of microsoft.office.interop.word replace word actual value, when replace word text contains line breaks line break not appear in document whole text comes in single line. in below code have replaced text "address" in document following text

park royal house no: 3301 wing - d city: xxxx state: yy zip: 100215 

but comes in document this

park royal house no: 3301 wing - d city: xxxx state: yy zip: 100215 

following sample code replace text in word doc

private sub replaceworkdoctext()     dim objapplication microsoft.office.interop.word.applicationclass = nothing     dim objdocument microsoft.office.interop.word.document = nothing     dim findtext string = "address"     dim replacetext string = "park royal house no: 3301 wing - d" + _                                 vbcrlf + "city: xxxx" + _                                 vbcrlf + "state: yy" + _                                 vbcrlf + "zip: 100215"      objapplication = new microsoft.office.interop.word.applicationclass()     objdocument = objapplication.documents.open("c:\test\form0001.docx")     objdocument.range.find         .text = findtext         .replacement.text = replacetext         .forward = true         .execute(replace:=microsoft.office.interop.word.wdreplace.wdreplaceone)     end end sub 

please me how replace word in document line break.

i use work around same, working fine.

private sub replaceworkdoctext()     dim objapplication microsoft.office.interop.word.applicationclass = nothing     dim range microsoft.office.interop.word.range      dim objdocument microsoft.office.interop.word.document = nothing     dim findtext string = "address"     dim replacetext string = "park royal house no: 3301 wing - d" + _                                 vbcrlf + "city: xxxx" + _                                 vbcrlf + "state: yy" + _                                 vbcrlf + "zip: 100215"      objapplication = new microsoft.office.interop.word.applicationclass()     objdocument = objapplication.documents.open("c:\test\form0001.docx")      range= objdocument.range     range.find         .text = findtext         .forward = true     end      while range.find.execute(findtext, matchwholeword:=true)         range.text = replacetext         exit while     end while end sub 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -