public void TestAddReportFilter() { int columnIndex = 0; pivotTable.AddReportFilter(columnIndex); CT_PageFields fields = pivotTable.GetCTPivotTableDefinition().pageFields; CT_PageField field = fields.pageField[(0)]; Assert.AreEqual(field.fld, columnIndex); Assert.AreEqual(field.hier, -1); Assert.AreEqual(fields.count, 1); }
/** * Add filter for the column with the corresponding index and cell value * @param columnIndex index of column to filter on */ public void AddReportFilter(int columnIndex) { AreaReference pivotArea = GetPivotArea(); int lastColIndex = pivotArea.LastCell.Col - pivotArea.FirstCell.Col; int lastRowIndex = pivotArea.LastCell.Row - pivotArea.FirstCell.Row; if (columnIndex > lastColIndex && columnIndex < 0) { throw new IndexOutOfRangeException(); } CT_PivotFields pivotFields = pivotTableDefinition.pivotFields; CT_PivotField pivotField = new CT_PivotField(); CT_Items items = pivotField.AddNewItems(); pivotField.axis = (/*setter*/ ST_Axis.axisPage); pivotField.showAll = (/*setter*/ false); for (int i = 0; i <= lastRowIndex; i++) { items.AddNewItem().t = (/*setter*/ ST_ItemType.@default); } items.count = (/*setter*/ items.SizeOfItemArray()); pivotFields.SetPivotFieldArray(columnIndex, pivotField); CT_PageFields pageFields; if (pivotTableDefinition.pageFields != null) { pageFields = pivotTableDefinition.pageFields; //Another filter has already been Created pivotTableDefinition.multipleFieldFilters = (/*setter*/ true); } else { pageFields = pivotTableDefinition.AddNewPageFields(); } CT_PageField pageField = pageFields.AddNewPageField(); pageField.hier = (/*setter*/ -1); pageField.fld = (/*setter*/ columnIndex); pageFields.count = (/*setter*/ pageFields.SizeOfPageFieldArray()); pivotTableDefinition.location.colPageCount = (/*setter*/ pageFields.count); }