Hello,
I'm trying to execute a find command on my Excel obj to find if a value exists in only one column, not the whole worksheet, what I had before that works (if the whole worksheet is searched):
************************************************** ***********************************
Microsoft.Office.Interop.Excel.Application ExcelObj = new Microsoft.Office.Interop.Excel.Application();
Workbook theWorkbook = ExcelObj.Workbooks.Open("C:\\Documents and Settings\\MarkW\\Desktop\\ZipCode Mapping.xlsx", 0, true, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
Sheets sheets = theWorkbook.Worksheets;
Worksheet worksheet = (Worksheet)sheets.get_Item(1);
Range range = worksheet.Cells.Find(searchString, worksheet.Cells[1,1], XlFindLookIn.xlValues, XlLookAt.xlPart, Missing.Value, XlSearchDirection.xlNext, false, Missing.Value, false);
************************************************** ***************************
works good in finding what I want to search but finds the search string inside longer strings (that I don't need).
For instance I'm trying to search column 2 (area codes) only for say "512". Since all the area codes are length of 3, this should be no problem, but searching the worksheet I find other strings/numbers that contain 512, but they are not what I need,
temp solution is this:
************************************************** ******************************
string add = range.get_Address(true, true, XlReferenceStyle.xlA1, Missing.Value, Missing.Value);
int row = range.Row;
int column = range.Column;
string[] location = new string[4];
string value = ((Range)worksheet.Cells[row, column]).Value2.ToString();
if (value.Length == searchString.Length)
{
// do what needs to be done
}
************************************************** ************************
I'd rather search what column I need, than testing if the string is the same length.
I've tried:
Range range = worksheet.Cells.Find(searchString, worksheet.Columns[1,1],
but I'm not sure what needs to be in the indexes.
thanks!
-Mark