11

そのため、Excelドキュメントで検索を行っていますが、他のユーザーがフィルターをオンにしてそのままにしておくことは非常に一般的です。これらのフィルターがオンの場合、それらのセルはワークシートのセル範囲に含まれません。

これらのカスタムフィルターをオフにして、シート内のすべてのセルにアクセスできるようにする方法はありますか?

これは私が方法を見つけるために使用する方法です

Microsoft.Office.Interop.Excel.Range find = sheet.Cells.Find(tapeID, Type.Missing,
Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues, Microsoft.Office.Interop.Excel.XlLookAt.xlPart, 
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false, Type.Missing, Type.Missing); 

フィルタがオンの場合、nullオブジェクトが返され、何もできません。フィルタをオフにすると、必要なものが取得されます。

フィルタをオフにするためのヒントはありますか?

4

4 に答える 4

13

最初にフィルターが適用されているかどうかをテストし、適用されている場合は無効にします。

if (xlSheet.AutoFilter != null)
{
    xlSheet.AutoFilterMode = false;
}

これにより、適用されたフィルタリングが削除され、フィルターの矢印ボタンが削除されます。

于 2012-11-03T00:59:31.560 に答える
3

You can disable all filters by calling the AutoFilter method on the range twice with no parameters.

sheet.Cells.AutoFilter();
sheet.Cells.AutoFilter();

I'm not very Interop savvy, but you may need to pass 5 Type.Missing or Missing.Value as parameters.

The first call will turn AutoFilter off if it's on, and the second will turn it on if it's off and vice versa. But in either case there will no longer be hidden cells due to filtering.

于 2012-11-03T00:23:28.473 に答える
3

私は次のコードを使用しましxlSheet.AutoFilterMode = falseた。xlSheet.AutoFilterModetrue

if (xlSheet.AutoFilter != null && xlSheet.AutoFilterMode == true)
{
    xlSheet.AutoFilter.ShowAllData();
}

Sid Hollandが述べたように、これによりすべてのフィルターがクリアされ、フィルターの矢印も保持されます。

于 2018-06-22T11:07:23.233 に答える