// Source directory path. U16String srcDir("SourceDirectory\\"); // Output directory path. U16String outDir("OutputDirectory\\"); // Path of the input excel file U16String samplePivotTable = srcDir + u"SamplePivotTable.xlsx"; // Path of the output excel file U16String outputHiddenRowPivotTable = outDir + u"outputHiddenRowPivotTable.xlsx"; // Load the sample excel file Workbook workbook(samplePivotTable); // Access the first worksheet Worksheet worksheet = workbook.GetWorksheets().Get(0); // Access the pivot table PivotTable pivotTable = worksheet.GetPivotTables().Get(0); // Get pivot table body range CellArea dataBodyRange = pivotTable.GetDataBodyRange(); // Pivot table starting row int currentRow = 5; // Pivot table ending row int rowsUsed = dataBodyRange.EndRow; // Iterate through the rows, compare the cell value and hide the rows. for (int i = currentRow; i < rowsUsed; i++) { Cell cell = worksheet.GetCells().GetCell(i, 4); if (cell.GetStringValue() == "Orange") { worksheet.GetCells().HideRow(i); } } // Refresh and calculate the data in the pivot table. pivotTable.RefreshData(); pivotTable.CalculateData(); // Save the output excel file workbook.Save(outputHiddenRowPivotTable);