Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
As i am new to C# programming i came across this problem.
I need to open an XL file find the cell which contains a particluar string.
But the problem i face is when there are more than one instances of the same string in different cells.
Eg: if cell [1,1] has "test" and cell [12,5] also has "test" then i get the returned value at [12,5] but i want [1,1], can any one please help me out how i can start searching from [1,1] which includes the cell [1,1].
Following is the snippet.

Excel.Application XLFile = new Excel.Application();
Excel.Workbook XLworkbook;
Excel.Worksheet XLSheet;

XLworkbook = XLFile.Workbooks.Open(@"C:\temp.xls",
        2,
        true,
        5,
        "",
        "",
        true,
        Excel.XlPlatform.xlWindows,
        0,
        false,
        false,
        false,
        false,
        true,
        Excel.XlCorruptLoad.xlNormalLoad);
XLSheet = (Excel.Worksheet)XLFile.ActiveSheet;
Excel.Range FindCell;
object Missing = System.Reflection.Missing.Value;
FindCell = XLSheet.Cells.Find("test", issing, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByColumns, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, true, false, false);
Posted

1 solution

Have you looked at this[^]?

It may help. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900