user1009073
user1009073

Reputation: 3238

Determine if rows are filtered by user

I have written an Excel plugin. Everything is working fine, up to a point. Assume I am iterating through all rows, doing some work... The user may have enabled a filter, so that the current row is not visible due to that filter. How do I determine what data should not be processed because it is not visible due to the filter?

Upvotes: 0

Views: 132

Answers (2)

Dmitriy Olhovsky
Dmitriy Olhovsky

Reputation: 141

The decision of the previous answer did not working for me, so I found another more simple solution by using aSheet.Rows[RowNum].Hidden property:

function IsRowVisible(aSheet: OLEVariant; aRowNum: Integer): Boolean;
begin
  Result := not aSheet.Rows[aRowNum].Hidden;
end;

In this function aSheet - excel worksheet and aRowNum - row number. Same solution can be used for columns.

Upvotes: 0

user1009073
user1009073

Reputation: 3238

Answer found. There does not appear to be a row.filtered property. There is a Hidden property, but it is on ranges, not rows.

Solution: Build a range, based on entire row, then check Hidden property.

function IsRowVisible(RowNum: Integer): Boolean;
var
  FilterRange: OleVariant;
  RangeText: String;
begin
  RangeText := 'A' + IntToStr(RowNum);
  // aws is my activesheet
  FilterRange := aws.Range[RangeText, RangeText].EntireRow;
  Result := not(FilterRange.EntireRow.Hidden);
end;

Upvotes: 2

Related Questions