我正在尝试在一列上设置筛选器。这是我在Interop中所做的方式:
private void CheckMasterFile(string path) {
var xlApp = new Excel.Application();
var xlWorkbook = xlApp.Workbooks.Open(path);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
foreach (var project in projects) {
if (string.IsNullOrEmpty(project.ProjectID.Value)) {
continue;
}
var xlRange = xlWorksheet.UsedRange;
if (xlWorksheet.AutoFilter != null) {
xlWorksheet.AutoFilterMode = false;
}
xlRange.AutoFilter(Field: 2, Criteria1: project.ProjectID.Value);
var result = xlRange.SpecialCells(Excel.XlCellType.xlCellTypeVisible, Type.Missing);//only shows filtered values
double sum = 0;
foreach (Excel.Range row in result.Rows) {
if (row.Cells[2, 2].Value2() != null) {
if (!NOT_ALLOWED_RUBRIQUES.Contains((string)row.Cells[2, 8].Value2())) {//check if rubrique is allowed or not
//finish method
}
}
}
}
xlWorkbook.Close(SaveChanges: false);
xlApp.Quit();
}
但在 EPPlus 中,我只能启用或禁用 autofilter,而不能根据特定值对列进行筛选。 类似于这样:
sheet.Cells["A RANGE HERE"].AutoFilter = true;
我在这里想要做的是对一个巨大的Excel文件进行筛选,只显示包含特定值的行。