using
Microsoft.Office.Interop.Excel;
Application myExcel =
new
Application();
//开启EXCEL 服务
object
missing = System.Reflection.Missing.Value;
myExcel.Application.Workbooks.Open(strExcelPath, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing, missing, missing);
Workbook myBook = myExcel.Workbooks[1];
//获取工作簿
_Worksheet sheet = (Worksheet)myBook.Sheets[
"RP750PDF"
];
//获取sheet
int
iCnt = sheet.UsedRange.Count;
Excel.Range rgUsed, rgFound;
rgUsed = sheet.get_Range(
"A2:A10"
);
//获取a2-10范围的梅子
rgFound = (Excel.Range)rgUsed.Find(
"RP757c-"
, Type.Missing,
//“RP757C-”即是要查找的字符串
Excel.XlFindLookIn.xlValues,
//查找值,或者xlFormulas查找公式等
Excel.XlLookAt.xlPart,
//这里用xlWhole返回的一直是空指针
Excel.XlSearchOrder.xlByRows,
//按行查找
Excel.XlSearchDirection.xlNext,
//建议就用xlNext
false
,
false
);
Range rgTmp = rgFound;
do
{
var item = rgTmp.get_Value();
int iRowNum = rgTmp.Row;
int iColNum = rgTmp.Column;
rgTmp = rgUsed.FindNext(rgTmp);
} while (rgTmp.Address != rgFound.Address);//记录第一个找到的range地址,当下一个单元格的地址与第一个相同,则跳出。