我看到Excel有查找方法,但我不知道如何使用它。
我想在范围(Microsoft.Office.Interop.Excel.Range)中搜索具有特定颜色的单元格。在Excel中,您将这样做:
我只想以编程的方式使用Excel来实现这一点。
谢谢你的阅读:)
发布于 2017-09-29 00:45:50
在调用Application.FindFormat
方法之前,需要设置Find()
属性。
例如,如果要使用“查找和替换”对话框的标准设置搜索红细胞,可以使用以下代码:
// These are the search options of the "Format" dialog.
_application.FindFormat.Font.Color = 255;
_application.FindFormat.Font.TintAndShade = 0;
// cell is null if nothing was found.
var cell = _application.Cells.Find(What: "", After: _application.ActiveCell,
LookIn: XlFindLookIn.xlFormulas, LookAt: XlLookAt.xlPart,
SearchOrder: XlSearchOrder.xlByRows, SearchDirection: XlSearchDirection.xlNext,
// It's important to set SearchFormat to true.
MatchCase: false, SearchFormat: true);
如果要搜索当前主题的重音颜色2,也可以这样做:
_application.FindFormat.Font.ThemeColor = XlThemeColor.xlThemeColorAccent2;
如果要模拟“查找和替换”对话框的确切行为,可以在找到单元格后调用cell.Activate()
。
https://stackoverflow.com/questions/46484067
复制相似问题