如何从.net应用程序中搜索Excel中的值? [英] How to Search a value in an Excel from .net application?

查看:54
本文介绍了如何从.net应用程序中搜索Excel中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从Excel中搜索超过5000条记录的值.

I have to search for a value over 5000 records from excel.

在Windows .net应用程序中完成此操作的最佳方法是什么?

What is the best approach to accomplish this in windows .net application?

推荐答案

由于您要搜索5000条记录,因此我认为您必须尝试搜索值.您可以使用interop API中的"Range.Find"来做到这一点.

Since you are trying to search thro' 5000 records, I assume you must be attempting to search thro' values. You could use the "Range.Find" from the interop API to do it.

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); 
        }
    }
}

进一步阅读:如何:在工作表范围内搜索文本

这篇关于如何从.net应用程序中搜索Excel中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆