如何找到"{{}}"来自.doc文件.我有.doc文件,其中某些字符串位于{{}}中,所以我想找到它&用其他字符串替换 [英] how to find "{{ }}" from .doc file.i have .doc file in which some string are in {{ }} .so i want to find it & replace it with some other string

查看:51
本文介绍了如何找到"{{}}"来自.doc文件.我有.doc文件,其中某些字符串位于{{}}中,所以我想找到它&用其他字符串替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将sim查找为字符串
昏暗的sReplace作为字符串
sFind ="{{"& "和}}"
sReplace ="Naresh sharma"
昏暗的Word作为Word.Application
Dim oDoc as Word.Document
''Dim oWord作为对象
''将oDoc视作对象

试试

oWord = CreateObject("Word.Application")
''soWord.Visible = True
oDoc = oWord.Documents.Add

oDoc = oWord.Documents.Open(TextBox1.Text)
oDoc.Activate()
将myStoryRange设置为Microsoft.Office.Interop.Word.Range
对于oDoc.StoryRanges中的每个myStoryRange

如果myStoryRange.StoryType = Word.WdStoryType.wdMainTextStory或myStoryRange.StoryType = Word.WdStoryType.wdTextFrameStory然后
使用myStoryRange.Find
.Text = sFind
.Replacement.Text = sReplace
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(替换:= Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
结尾为

如果结束
myStoryRange = myStoryRange.NextStoryRange
循环播放,直到myStoryRange无效为止
下一个myStoryRange
oDoc.Save()
''System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc)
''元帅.ReleaseComObject(oDoc)
''''oDoc.Close()

''oDoc =没什么
''元帅.ReleaseComObject(oWord)
''oWord.Application.Quit()
''oWord =没什么
如果oDoc一无所有,那么
元帅.ReleaseComObject(oDoc)
oDoc =没什么
如果结束
如果oWord一无所有,那么
元帅.ReleaseComObject(oWord)
oWord =没什么
如果结束
捕获为ExternalException
MessageBox.Show(例如,ErrorCode,错误代码编号")
MessageBox.Show(例如StackTrace)
作为例外捕获Ex



结束Try

Dim sFind As String
Dim sReplace As String
sFind = "{{" & "" & "}}"
sReplace = "Naresh sharma"
Dim oWord As Word.Application
Dim oDoc As Word.Document
'' Dim oWord As Object
''Dim oDoc As Object

Try

oWord = CreateObject("Word.Application")
''soWord.Visible = True
oDoc = oWord.Documents.Add

oDoc = oWord.Documents.Open(TextBox1.Text)
oDoc.Activate()
Dim myStoryRange As Microsoft.Office.Interop.Word.Range
For Each myStoryRange In oDoc.StoryRanges
Do
If myStoryRange.StoryType = Word.WdStoryType.wdMainTextStory Or myStoryRange.StoryType = Word.WdStoryType.wdTextFrameStory Then
With myStoryRange.Find
.Text = sFind
.Replacement.Text = sReplace
.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue
.Execute(Replace:=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll)
End With

End If
myStoryRange = myStoryRange.NextStoryRange
Loop Until myStoryRange Is Nothing
Next myStoryRange
oDoc.Save()
''System.Runtime.InteropServices.Marshal.ReleaseComObject(oDoc)
''Marshal.ReleaseComObject(oDoc)
''''oDoc.Close()

''oDoc = Nothing
''Marshal.ReleaseComObject(oWord)
''oWord.Application.Quit()
''oWord = Nothing
If oDoc IsNot Nothing Then
Marshal.ReleaseComObject(oDoc)
oDoc = Nothing
End If
If oWord IsNot Nothing Then
Marshal.ReleaseComObject(oWord)
oWord = Nothing
End If
Catch ex As ExternalException
MessageBox.Show(ex.ErrorCode, "Error code no")
MessageBox.Show(ex.StackTrace)
Catch Ex As Exception



End Try

推荐答案

另一种解决方案,只需在单词中找到"{{",然后将其替换即可.没有漫长的过程
Other One Solution that Simply we can find "{{" in the word and after that replace it. there is no long process


这篇关于如何找到"{{}}"来自.doc文件.我有.doc文件,其中某些字符串位于{{}}中,所以我想找到它&用其他字符串替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆