Excel.Range.Find method

后端 未结 1 1031
攒了一身酷
攒了一身酷 2020-12-17 02:19

I am using Excel interop object and trying to find a date in a specified range by below method

Excel.Range rngFind = WS.get_Range(strFromRange, strToRange).F         


        
相关标签:
1条回答
  • 2020-12-17 03:08

    Using Office 2007, Interop generated directly from Visual Studio. I used the following code to find the cell in question:

    using System.Reflection;
    using Microsoft.Office.Interop.Excel;
    
    object False = false;
    object True = true;
    
    _Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
    
    Workbook wb = excel.Workbooks._Open(@"C:\tmp\StackOverflow.xlsx",False, False,Missing.Value,Missing.Value,False,False,Missing.Value,Missing.Value,False,Missing.Value,Missing.Value,True);
    
    _Worksheet ws = (_Worksheet)wb.Worksheets[1];
    
    string from = "A1";
    string to = "B1";
    
    Range rng = ws.get_Range(from,to);
    
    Range findRng = rng.Find("Sep-08",Missing.Value,XlFindLookIn.xlValues,Missing.Value,Missing.Value,XlSearchDirection.xlNext,False,False,Missing.Value);
    

    You can find the Microsoft example at How to automate Excel by using Visual C# to fill or to obtain data in a range by using arrays.

    0 讨论(0)
提交回复
热议问题