XmlMappedRange.Find 方法

尋找 XmlMappedRange 控制項中的指定資訊,並且在找到第一個儲存格的資訊時傳回 Range 物件。

命名空間:  Microsoft.Office.Tools.Excel
組件:  Microsoft.Office.Tools.Excel (在 Microsoft.Office.Tools.Excel.dll 中)

語法

'宣告
Function Find ( _
    What As Object, _
    After As Object, _
    LookIn As Object, _
    LookAt As Object, _
    SearchOrder As Object, _
    SearchDirection As XlSearchDirection, _
    MatchCase As Object, _
    MatchByte As Object, _
    SearchFormat As Object _
) As Range
Range Find(
    Object What,
    Object After,
    Object LookIn,
    Object LookAt,
    Object SearchOrder,
    XlSearchDirection SearchDirection,
    Object MatchCase,
    Object MatchByte,
    Object SearchFormat
)

參數

  • What
    型別:System.Object
    要搜尋的資料。可以是字串或任何 Microsoft Office Excel 資料型別。
  • After
    型別:System.Object
    搜尋起點後的儲存格。這個儲存格就是從使用者介面進行搜尋時的現用儲存格位置。請注意,After 必須是範圍內的單一儲存格。請記住,搜尋會在這個儲存格後開始,而直到此方法繞回指定儲存格後,才會搜尋這個儲存格。如果您未指定這個引數,則會從範圍左上角的儲存格後開始搜尋。
  • MatchCase
    型別:System.Object
    true 表示搜尋時區分大小寫。預設值是 false。
  • MatchByte
    型別:System.Object
    只有在您選取或安裝雙位元語言支援時才能使用。true 表示只會將雙位元組字元與雙位元組字元比對,否則為 false,表示將雙位元組字元與其對等的單位元組字元比對。

傳回值

型別:Microsoft.Office.Interop.Excel.Range
Range 表示找到含有指定資訊的第一個儲存格。

備註

如果找不到符合項目,這個方法會傳回 nullnull 參考 (即 Visual Basic 中的 Nothing)。

這個方法不會影響選取範圍或現用儲存格。

每次使用這個方法時,會儲存 LookIn、LookAt、SearchOrder 和 MatchByte 的設定。 如果沒有為這些引數指定值,下次您呼叫方法時便會使用已儲存的值。 設定這些引數會變更 [尋找] 對話方塊中的設定,而變更 [尋找] 對話方塊中的設定會變更您省略引數時使用的儲存值。 若要避免發生問題,每次使用這個方法時應明確設定這些引數。

您可以使用 FindNextFindPrevious 方法重複搜尋。

範例

下列程式碼範例將 XmlMappedRange 的值設定為字串 "Smith",然後使用 Find、FindNextFindPrevious 方法,找到第一個含 "Smith" 字串的儲存格。 因為 XmlMappedRange 必定只會包含一個儲存格,所以在每次搜尋時,都會找到同一個儲存格。 這個程式碼範例假設目前工作表包含名為 CustomerLastNameCell 的 XmlMappedRange

Private Sub FindSmith()
    Me.CustomerLastNameCell.Value2 = "Smith"

    ' Use Find to get the range with "Smith".
    Dim range1 As Excel.Range = Me.CustomerLastNameCell.Find( _
        "Smith", SearchDirection:=Excel.XlSearchDirection.xlNext)
    Dim address1 As String = range1.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("Find method found the range: " & address1)

    ' Use FindNext to get the range with "Smith".
    Dim range2 As Excel.Range = Me.CustomerLastNameCell.FindNext(range1)
    Dim address2 As String = range2.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("FindNext method found the range: " & address2)

    ' Use FindPrevious to get the range with "Smith".
    Dim range3 As Excel.Range = Me.CustomerLastNameCell.FindPrevious(range2)
    Dim address3 As String = range3.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("FindPrevious method found the range: " & address3)
End Sub
private void FindSmith()
{
    this.CustomerLastNameCell.Value2 = "Smith";

    // Use Find to get the range with "Smith".
    Excel.Range range1 = this.CustomerLastNameCell.Find("Smith",
        Excel.XlSearchDirection.xlNext);
    string address1 = range1.get_Address(missing, missing,
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("Find method found the range: " + address1);

    // Use FindNext to get the range with "Smith".
    Excel.Range range2 = this.CustomerLastNameCell.FindNext(range1);
    string address2 = range2.get_Address(
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("FindNext method found the range: " + address2);

    // Use FindPrevious to get the range with "Smith".
    Excel.Range range3 = this.CustomerLastNameCell.FindPrevious(range2);
    string address3 = range3.get_Address(
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("FindPrevious method found the range: " + address3);
}

.NET Framework 安全性

請參閱

參考

XmlMappedRange 介面

Microsoft.Office.Tools.Excel 命名空間