Excel.Range.Find Method

I am using an Excel interaction object and trying to find a date in the specified range below using

Excel.Range rngFind = WS.get_Range(strFromRange, strToRange).Find(strFind, Type.Missing, Excel.XlFindLookIn.xlFormulas, Excel.XlLookAt.xlPart, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, false, false); 

but I get rngFind as null always my strFind = "Sep-08", which I tried with both Excel.XlFindLookIn.xlFormulas and Excel.XlFindLookIn.xlValues

My excel file is as follows

 Sep-08 Oct-08 Nov-08 Dec-08 Jan-09 Feb-09 Mar-09 Apr-09 May-09 Jun-09 Jul-09 

where, as when you click on Sep-08 cell, I get 9/1/2008 in the formula field in Excel I also tried searching on 9/1/2008, but it changes the system system according to the RegionalSettings date format ...

Please help me. basically i do to get the address bar cell

+4
source share
1 answer

Using Office 2007, Interop, created 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 a Microsoft example in How to automate Excel using Visual C # to populate or retrieve data in a range using arrays .

+4
source

Source: https://habr.com/ru/post/1306679/


All Articles