我正在将旧的传统VB程序转换为C#。其中一种方法涉及在Word文档中查找(和返回)与特定Word样式相匹配的文本。将Word.VBA中的.Selection.Find.Style转换为C#
原VB代码,有下面的代码行:
With objword
...
.Selection.Find.Style = .ActiveDocument.Styles(StyleCode)
...
End With
这就是我想在C#中做的(使用Word互操作):
_wordObject.Selection.Find.Style = _wordObject.ActiveDocument.Styles[styleCode];
当我尝试编译该程序我收到一条错误消息,说:
'Microsoft.Office.Interop.Word.Find.Style' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.Word.Find.get_Style()' or 'Microsoft.Office.Interop.Word.Find.set_Style(ref object)'
当我尝试使用get_Style时,我被告知我t不使用任何参数,并使用索引属性,或者我不能将索引应用于'method group'类型的表达式
我需要在C#中如何在Word文档中查找文本样式?
样式是方法还是数组?是否用非方括号调用它?另请参阅http://stackoverflow.com/a/2300917/495455 - 尝试使用替代ActiveDocument –
.Selection.Find.Style似乎是一个属性,但看起来我无法为其分配值。另外,我不明白发送的链接。再次,我只想通过使用Word样式在Word文档中查找文本。 –