Excel Interop“FindAll”方法

这可能是一个重复的问题,但真的不知道如何去标题。

有没有人能够findExcel Interop库中的方法,从“查找和replace”对话框公开“查找所有”function?

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

有什么想法吗?

恐怕你采取的方法也是我过去采取的方法。 没有FindAll方法暴露,所以我们只能假设这也是Excel的做法!