C# 3.0 在c中使用interop删除文档中的段落

C# 3.0 在c中使用interop删除文档中的段落,c#-3.0,C# 3.0,我在一段中搜索了一个词,如果在任何一段中找到了这个词,那么我需要删除该段。到目前为止,我已经尝试过了 Public Function StrikethroughPara(ByVal searchstring As String) As Boolean Dim Content As String For b As Integer = 1 To objword.ActiveDocument.Paragraphs.Count - 1 Content = objwor

我在一段中搜索了一个词,如果在任何一段中找到了这个词,那么我需要删除该段。到目前为止,我已经尝试过了

 Public Function StrikethroughPara(ByVal searchstring As String) As Boolean
    Dim Content As String

    For b As Integer = 1 To objword.ActiveDocument.Paragraphs.Count - 1
        Content = objword.ActiveDocument.Paragraphs(b).Range.Text
        Try

            If Regex.IsMatch(Content, searchstring) Then


                **objword.Selection.Font.StrikeThrough = 9999998**//This is not working
                'objword.Selection.Paragraphs.Style.StrikeThrough = WdConstants.wdToggle
            End If
        Catch ex As Exception
        End Try
    Next

End Function

如果可能,请提供解决方案。

您是否尝试获取段落范围,然后像这样设置Font.streethrough属性?int undefinedInt=intWord.WdConstants.wdUndefined;objword.Selection.parations.range.Font.删除线=未定义;您好,谢谢您的回复,我已经尝试过了,但它显示的错误是range不是microsoft.office.interop.Parague的成员。这是编译时错误。如果您对此plz响应有任何解决方案的话。我在一年多前的某个vsto项目中工作过,我几乎忘记了这一切。我刚刚测试了以下代码,它对我来说运行良好。你能试试吗?objword.Selection.parations[1]。Range.Font.StrikeThrough=intWdConstants.wdForward;您好,感谢上帝,它现在没有任何编译时错误,但在运行时它会抛出com异常System.runtime.InteropServices.COMException被捕获ErrorCode=-2146822347 HelpLink=wdmain11.chm25421 Message=请求的集合成员不存在。Source=Microsoft Word StackTrace:位于Microsoft.Office.Interop.Word.Pages.get_ItemInt32索引位于CommonCodeLibrary.ClsWinWord.StrikethrowParastring searchstring。如果您知道,我正在尝试解决此问题,然后可以提出建议。感谢您宝贵的回复。byeHi Tariqlazam,感谢您宝贵的建议。它对我帮助很大,我刚刚修改如下:-objword.ActiveDocument.Paragraphsb.Range.Font.streethrough=WdConstants.wdToggle。再次感谢您尝试获取段落的范围,然后像这样设置Font.streethrough属性?int undefinedInt=intWord.WdConstants.wdUndefined;objword.Selection.parations.range.Font.删除线=未定义;您好,谢谢您的回复,我已经尝试过了,但它显示的错误是range不是microsoft.office.interop.Parague的成员。这是编译时错误。如果您对此plz响应有任何解决方案的话。我在一年多前的某个vsto项目中工作过,我几乎忘记了这一切。我刚刚测试了以下代码,它对我来说运行良好。你能试试吗?objword.Selection.parations[1]。Range.Font.StrikeThrough=intWdConstants.wdForward;您好,感谢上帝,它现在没有任何编译时错误,但在运行时它会抛出com异常System.runtime.InteropServices.COMException被捕获ErrorCode=-2146822347 HelpLink=wdmain11.chm25421 Message=请求的集合成员不存在。Source=Microsoft Word StackTrace:位于Microsoft.Office.Interop.Word.Pages.get_ItemInt32索引位于CommonCodeLibrary.ClsWinWord.StrikethrowParastring searchstring。如果您知道,我正在尝试解决此问题,然后可以提出建议。感谢您宝贵的回复。byeHi Tariqlazam,谢谢你宝贵的建议。它对我帮助很大,我只是这样修改:-objword.ActiveDocument.Paragraphsb.Range.Font.StrikeThrough=WdConstants.wdToggle.再次感谢