使用以下代码进行测试:
using Aspose.Cells;
var wb = new Workbook("input.xlsx");
var worksheet = wb.Worksheets[0];
var style = worksheet.Cells["A14"].GetDisplayStyle();
var cellColor = wb.CreateCellsColor();
cellColor.Color = style.Font.Color;
// filter Sheet1.A14 Cell font color fail
var filter = worksheet.AutoFilter;
filter.AddFontColorFilter(0, cellColor);
filter.Refresh(true);
Console.WriteLine("Sheet1 row 14 hidden: " + worksheet.Cells.Rows[13].IsHidden);
// can't get correct filter color
Console.WriteLine("Expect color:" + cellColor.Color);
Console.WriteLine("Actual color:" + (filter.FilterColumns[0].Filter as ColorFilter).GetColor(wb.Worksheets));
// filter Sheet1.A14 Cell fill color fail
var foregroundColor = wb.CreateCellsColor();
var backgroundColor = wb.CreateCellsColor();
foregroundColor.Color = style.ForegroundColor;
backgroundColor.Color = style.BackgroundColor;
filter.AddFillColorFilter(0, style.Pattern, foregroundColor, backgroundColor);
filter.Refresh(true);
Console.WriteLine("Sheet1 row 14 hidden: " + worksheet.Cells.Rows[13].IsHidden);
worksheet = wb.Worksheets[1];
filter = worksheet.AutoFilter;
// filter Sheet2.B3 Cell fill color success
style = worksheet.Cells["B3"].GetDisplayStyle();
foregroundColor.Color = style.ForegroundColor;
backgroundColor.Color = style.BackgroundColor;
filter.AddFillColorFilter(1, style.Pattern, foregroundColor, backgroundColor);
filter.Refresh(true);
Console.WriteLine("Sheet2 row 3 hidden: " + worksheet.Cells.Rows[2].IsHidden);
// filter Sheet2.A4 Cell fill color fail
style = worksheet.Cells["A4"].GetDisplayStyle();
foregroundColor.Color = style.ForegroundColor;
backgroundColor.Color = style.BackgroundColor;
filter.AddFillColorFilter(0, style.Pattern, foregroundColor, backgroundColor);
filter.Refresh(true);
Console.WriteLine("Sheet2 row 4 hidden: " + worksheet.Cells.Rows[3].IsHidden);
样例文件:
input.zip (8.3 KB)
出现的问题:
- 条件格式的背景颜色与字体颜色不能正常筛选(行14,27)
- ColorFilter.GetColor 函数返回的颜色不是筛选的值(行17)
- 直接设置的单元格颜色筛选有时可以,有时不可以(行38,46)