我正在尝试使用下面显示的方法在excel文件中搜索,但我收到的错误是
System.Runtime.InteropServices.COMException未处理消息: 来自HRESULT的异常:0x800A01A8
在下面的代码行
if (currentRange.get_Address(true, true, Excel.XlReferenceStyle.xlR1C1).Equals(startAddress))
方式
private void SearchResults(Excel.Range usedRange, string searchString, System.Data.DataTable dt)
{
Excel.Range startAddress = null;
Excel.Range currentRange;
currentRange = usedRange.Find(TB_First_Name.Text,
Type.Missing,
Excel.XlFindLookIn.xlValues,
Excel.XlLookAt.xlPart,
Excel.XlSearchOrder.xlByRows,
Excel.XlSearchDirection.xlNext,
false,
Type.Missing,
Type.Missing);
while (currentRange != null)
{
//Keep track of the first range you find.
if (startAddress == null)
{
startAddress = currentRange;
}
//if current address is same as the starting address stop searching
else if (currentRange.get_Address(true, true, Excel.XlReferenceStyle.xlR1C1).Equals(startAddress))
{
break;
}
//keep searching for next value
currentRange = usedRange.FindNext(currentRange);
AddExcelRowToDataTable(usedRange, currentRange, dt);
}
}