如何从.net应用程序在Excel中search值?

我必须从Excel中search超过5000条logging的值。

什么是最好的方法来完成这个在Windows .NET应用程序?

既然你正在试图search5000条logging,那么我认为你必须试图searchthro的值。 你可以使用interop API中的“Range.Find”来做到这一点。

private void OpenExcelFile() { Excel.Application exlApp = new Microsoft.Office.Interop.Excel.Application(); if (exlApp == null) { MessageBox.Show("Excel app object could not be created"); } else { exlFileSelector.FileName = @"*.xls"; if (exlFileSelector.ShowDialog() == DialogResult.OK) { Excel.Workbook wrkBook = exlApp.Workbooks.Open(exlFileSelector.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, true, true); Excel.Sheets sheetList = wrkBook.Sheets; Excel.Range search = exlApp.get_Range("A1", "C5"); search.Find("FindMe", null, Excel.XlFindLookIn.xlValues, Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByRows, Excel.XlSearchDirection.xlNext, false, null, null); } } } 

进一步阅读: 如何:在工作表范围中search文本

用于.NET的SpreadsheetGear是一个与Excel兼容的电子表格组件,它支持类似于Excel的Find API的Find API。 您可以search值或公式,或计算公式,然后根据需要search结果。 下面是一个加载工作簿并find以“John”开头的第一个单元的简单示例:

 // Open an xlsx workbook (can also open xls). IWorkbook workbook = Factory.GetWorkbook(@"C:\tmp\Data.xlsx"); // Find the first cell which starts with "John". IRange foundCell = workbook.Worksheets["Sheet1"].Cells.Find("John*", null, FindLookIn.Values, LookAt.Whole, SearchOrder.ByColumns, SearchDirection.Next, true); if (foundCell != null) Console.WriteLine("found {0} in cell {1}", foundCell.Text, foundCell.Address); 

你可以在这里下载免费评估。

免责声明:我自己的SpreadsheetGear LLC

您的价值是由电子表格公式之一产生的计算值,还是实际的预定值?

如果是后者,可以将电子表格保存为XML并适当地parsing它们
要么
根据您可用的索引技术,您可以对其进行索引,然后search索引并find合适的值。
(这是我首选的方法,现在我已经想到了。)

如果是前者,我能想到的唯一select是使用InterOp库打开每个库并使用API​​。