/// <summary> /// 设置Farpoint过滤功能,符合/不符合过滤条件的行将背景色将根据参数中设置的颜色进行显示 /// </summary> /// <param name="fp"></param> /// <param name="fitColor">符合过滤条件的数据背景色</param> /// <param name="notFitColor">不符合过滤条件的数据背景色</param> /// <param name="filterColumnIdxs">需要过滤功能的列</param> static public void SetFpCustomFilterProperties(FarPoint.Win.Spread.FpSpread fp, Color fitColor, Color notFitColor, int[] filterColumnIdxs) { if (filterColumnIdxs == null || filterColumnIdxs.Length == 0) { return; } FarPoint.Win.Spread.NamedStyle inStyle = new FarPoint.Win.Spread.NamedStyle(); FarPoint.Win.Spread.NamedStyle outStyle = new FarPoint.Win.Spread.NamedStyle(); inStyle.BackColor = fitColor; outStyle.BackColor = notFitColor; //被过滤掉的行会按照自定义样式进行显示 FarPoint.Win.Spread.StyleRowFilter rowFilter = new FarPoint.Win.Spread.StyleRowFilter(fp.ActiveSheet, inStyle, outStyle); rowFilter.FilterFrozenRows = false;//冻结行不进行过滤 //非空行字符串 rowFilter.NonBlanksString = Const.NONBLANK_STRING; //全部字符串,选择全部时过滤内容会没有符合条件的,因此ALL_STRING定义为“取消” rowFilter.AllString = Const.ALL_STRING; //空行字符串 rowFilter.BlanksString = Const.BLANK_STRING; int fcLen = filterColumnIdxs.Length; string[] curFilters = new string[fcLen]; for (int i = 0; i < fcLen; i++) { curFilters[i] = fp.ActiveSheet.RowFilter.GetColumnFilterBy(filterColumnIdxs[i]); //第二个参数为取消显示“非空白行”过滤条件 FarPoint.Win.Spread.FilterColumnDefinition fcd = new FarPoint.Win.Spread.FilterColumnDefinition(filterColumnIdxs[i], ~FarPoint.Win.Spread.FilterListBehavior.NonBlank & ~FarPoint.Win.Spread.FilterListBehavior.Blank);//取消显示“非空白行”和“空白行”过滤条件 rowFilter.AddColumn(fcd); } fp.ActiveSheet.RowFilter = rowFilter; //按照先前选中的过滤方式过滤 for (int i = 0; i < fcLen; i++) { if (curFilters[i] != null && curFilters[i].Length != 0) { fp.ActiveSheet.AutoFilterColumn(filterColumnIdxs[i], curFilters[i], 0); } } }
/// <summary> /// 设置Farpoint过滤功能,不符合过滤条件的行将被隐藏 /// 注意:Farpoint中的冻结行的数据将不会被过滤;若未设置冻结行,冻结行的内容也会被添加到过滤条件当中! /// </summary> /// <param name="fp"></param> /// <param name="filterColumnIdxs">需要过滤的列的索引</param> static public void SetFpFilterHideProperties(FarPoint.Win.Spread.FpSpread fp, int[] filterColumnIdxs) { if (filterColumnIdxs == null || filterColumnIdxs.Length == 0) { return; } FarPoint.Win.Spread.HideRowFilter rowFilter = new FarPoint.Win.Spread.HideRowFilter(fp.ActiveSheet); //冻结行不进行过滤 rowFilter.FilterFrozenRows = false; //非空行字符串 rowFilter.NonBlanksString = Const.NONBLANK_STRING; //全部字符串,选择全部时过滤内容会没有符合条件的,因此ALL_STRING定义为“取消” rowFilter.AllString = Const.ALL_STRING; //空行字符串 rowFilter.BlanksString = Const.BLANK_STRING; int fcLen = filterColumnIdxs.Length; string[] curFilters = new string[fcLen]; for (int i = 0; i < fcLen; i++) { if (fp.ActiveSheet.RowFilter != null) { curFilters[i] = fp.ActiveSheet.RowFilter.GetColumnFilterBy(filterColumnIdxs[i]); } FarPoint.Win.Spread.FilterColumnDefinition fcd = new FarPoint.Win.Spread.FilterColumnDefinition(filterColumnIdxs[i], ~FarPoint.Win.Spread.FilterListBehavior.NonBlank & ~FarPoint.Win.Spread.FilterListBehavior.Blank);//取消显示“非空白行”和“空白行”过滤条件 rowFilter.AddColumn(fcd); } fp.ActiveSheet.RowFilter = rowFilter; //按照先前选中的过滤方式过滤 for (int i = 0; i < fcLen; i++) { if (curFilters[i] != null && curFilters[i].Length != 0) { fp.ActiveSheet.AutoFilterColumn(filterColumnIdxs[i], curFilters[i], 0); } } }