マイタスクは、特定の行に文字列が存在するかどうかに基づいてExcelブックの行を非表示/非表示にすることです。私が直面している問題は、次のコードで1000行でこのタスクを実行するのに約20秒かかります。ファイルに2k〜3k行の行があり、このローディング時間を短縮したいと考えています。VSTOアプリケーションでExcelの行を表示/非表示C#
私は、行全体を隠す/隠すコード(currentFind.EntireRow.Hidden =!isShown;)をコメントすると、ファイルの読み込みにはわずか4-5秒しかかかりません。これは、文字列部分の検索ではなく時間がかかる行隠蔽部分であると結論づけます。
Worksheet activeWorksheet= Globals.ThisAddIn.Application.ActiveSheet;
Range usedRange = activeWorksheet.UsedRange;
Range currentFind = null;
Range firstFind = null;
currentFind = activeWorksheet.UsedRange.Find(searchInput);
while (currentFind != null)
{
// Keep track of the first range you find.
if (firstFind == null)
{
firstFind = currentFind;
}
// If you didn't move to a new range, you are done.
else if (currentFind.get_Address(XlReferenceStyle.xlA1)
== firstFind.get_Address(XlReferenceStyle.xlA1))
{
break;
}
currentFind.EntireRow.Hidden = !isShown;
currentFind = usedRange.FindNext(currentFind);
}
ソリューションは機能しましたか?もしそれが答えとしてマークしてください – dgorti