AutoFilterをリフレッシュした後のすべての非表示行のインデックスを取得(C++使用)

可能な使用シナリオ

ワークシートセルにオートフィルタを適用すると、一部の行が自動的に非表示になります。ただし、Excelエンドユーザーによって手動で非表示にされた行があり、それがオートフィルタによって非表示にされている行かどうかがわかりにくい場合があります。Aspose.Cellsはこの問題を解決するためにint[] AutoFilter.Refresh(bool hideRows)を使用します。このメソッドはオートフィルタによって非表示にされた行の行インデックスを返し、Excelエンドユーザーによって手動で非表示にされた行の行インデックスではありません。

オートフィルタの更新後の非表示行インデックスの取得

サンプルExcelファイルを読み込み、Excelエンドユーザーによって手動で非表示にされた行の一部を示しています。コードはオートフィルタを適用し、int[] AutoFilter.Refresh(bool hideRows)メソッドを使用して自動フィルタによって非表示にされたすべての行の行インデックスを取得し、非表示にされた行のインデックスとセル名、値をコンソールに出力します。

サンプルコード

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;

int main()
{
    Aspose::Cells::Startup();

    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
    U16String inputFilePath = srcDir + U16String(u"sampleGetAllHiddenRowsIndicesAfterRefreshingAutoFilter.xlsx");
    Workbook workbook(inputFilePath);

    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    AutoFilter autoFilter = worksheet.GetAutoFilter();
    autoFilter.AddFilter(0, u"Orange");

    Vector<int32_t> rowIndices = autoFilter.Refresh(true);

    std::cout << "Printing Rows Indices, Cell Names and Values Hidden By AutoFilter." << std::endl;
    std::cout << "--------------------------" << std::endl;

    for (int32_t i = 0; i < rowIndices.GetLength(); i++)
    {
        int32_t r = rowIndices[i];
        Cell cell = worksheet.GetCells().Get(r, 0);
        std::cout << r << "\t" << cell.GetName().ToUtf8() << "\t" << cell.GetStringValue().ToUtf8() << std::endl;
    }

    Aspose::Cells::Cleanup();
    return 0;
}

コンソール出力

Printing Rows Indices, Cell Names and Values Hidden By AutoFilter.

\--------------------------

1       A2      Apple

2       A3      Apple

3       A4      Apple

6       A7      Apple

7       A8      Apple

11      A12     Pear

12      A13     Pear