Excel Interop"FindAll"方法

Chr*_*ris 5 c# excel interop

这可能是一个重复的问题,但实际上不知道如何标题.

有没有人能够在Excel Interop Library中找到一个方法,从"查找和替换"对话框中公开"查找全部"功能?

有Find,FindNext和FindPrevious,但没有FindAll,这很奇怪.

到目前为止,这是我这样做的方式,我第一次尝试它,可以这么说......

    //FindRange() is an extension method which wraps Worksheet.Cells.Find()
    Range start = sheet.FindRange(searchText, 
                                XlLookAt.xlPart, 
                                XlSearchOrder.xlByColumns, 
                                XlSearchDirection.xlNext);

    HashSet<int> matches = new HashSet<int>();

    Range next = start;

    while (true)
    {
        next = sheet.Cells.FindNext(next.get_Offset(1, 0));
        if (!matches.Add(next.Row))
            break;
    }
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

Ant*_*Ant 3

恐怕你现在采取的方法也是我过去采取的方法。没有公开 FindAll 方法,因此我们只能假设 Excel 也在这样做!