C#通过Excel工作簿进行search

我想用c#search一个excel文件,find一个特定的文本(ASSEMBLY)。我有这个小小的代码writed:

private void button1_Click(object sender, EventArgs e) { string File_name = "C:\\test.xls"; Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook oWB; Microsoft.Office.Interop.Excel.Worksheet oSheet; try { object missing = System.Reflection.Missing.Value; oWB = oXL.Workbooks.Open(File_name, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Worksheets[3]; Microsoft.Office.Interop.Excel.Range oRng = GetSpecifiedRange("ASSEMBLY", oSheet); if (oRng != null) { MessageBox.Show("Text found, position is Row:" + oRng.Row + " and column:" + oRng.Column); } else { MessageBox.Show("Text is not found"); } oWB.Close(false, missing, missing); oSheet = null; oWB = null; oXL.Quit(); } catch (Exception ex) { } } private Microsoft.Office.Interop.Excel.Range GetSpecifiedRange(string matchStr, Microsoft.Office.Interop.Excel.Worksheet objWs) { object missing = System.Reflection.Missing.Value; Microsoft.Office.Interop.Excel.Range currentFind = null; Microsoft.Office.Interop.Excel.Range firstFind = null; currentFind = objWs.get_Range("A1", "AM100").Find(matchStr, missing, Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues, Microsoft.Office.Interop.Excel.XlLookAt.xlPart, Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false, missing, missing); return currentFind; } 

这工作正常,它可以从工作簿中find给定的string。 但是,工作簿有很多工作表,现在我只search一个(表3)。 如何search整个工作簿?

而且,这个excel文件多次有“ASSEMBLY”这个词。 如何继续search并显示所有结果,而不仅仅是第一个?

 k = 1; do { oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oWB.Worksheets[k]; } while (k <= oWB.Worksheets.Count);