我正在研究这种过滤 2 列以查找具有不同值的行、选择这些列中的值并将单元格区域着色为黄色的方法。我无法正确选择值。由于某种原因,我现在使用的所有选择方法都不能正常工作。范围值是单个单元格,我正在尝试选择列的整个使用范围。他们要么不选择整个使用的范围,要么选择整个列,包括空白单元格,或工作表最底部的颜色单元格。这是我的代码示例:
static public void FilterFunction(Excel.Application Oxl, Excel.Worksheet PSheet, Excel.Range Rng, Excel.Range Find)
{
Excel.Range Filler = null;
Rng.AutoFilter(Rng.Column, "Found");
Find.AutoFilter(Find.Column, "Missing");
Rng.Columns.Select();
Filler = Oxl.Selection as Excel.Range;
Filler.Cells.Interior.Color = ColorTranslator.ToOle(Color.Yellow);
Find.End[Excel.XlDirection.xlDown].Select();
Filler = Oxl.Selection as Excel.Range;
Filler.Cells.Interior.Color = ColorTranslator.ToOle(Color.Yellow);
Rng.AutoFilter(Rng.Column, "Missing");
Find.AutoFilter(Find.Column, "Found");
Rng.EntireColumn.Select();
Filler = Oxl.Selection as Excel.Range;
Filler.Cells.Interior.Color = ColorTranslator.ToOle(Color.Yellow);
Find.End[Excel.XlDirection.xlDown].Select();
Filler = Oxl.Selection as Excel.Range;
Filler.Cells.Interior.Color = ColorTranslator.ToOle(Color.Yellow);
PSheet.ShowAllData();
}