私はこの記事を理解しようとしていますhttp://bensprogrammingwork.blogspot.com/2012/01/progressbar-in-wpf.html
Button_Click
イベントに次のコードがあります。
FileInfo existingFile = new FileInfo("C:\\Users\\cle1394\\Desktop\\Apple Foreign Tax Payment Sample Layout Proposed - Sample Data.xlsx");
ConsoleApplication2.Program.ExcelData data = ConsoleApplication2.Program.GetExcelData(existingFile);
メソッドが完了するまでに数分かかるため、GetExcelData()
完了までの推定時間を示すプログレス バーを表示したいと思います。
ただし、上記のチュートリアルのメソッドを以下のコードに適用する方法がわかりませんGetExcelData()
。
public static ExcelData GetExcelData(FileInfo file)
{
ExcelData data = new ExcelData();
data.Countries = new List<Country>();
using (ExcelPackage xlPackage = new ExcelPackage(file))
{
// get the first worksheet in the workbook
ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets[1];
List<string> countryNames = new List<string>
{
"Australia"/*,
"China - Beijing",
"China - Shanghai",
"Hong Kong",
"Hungary",
"Ireland",
"Spain",
"United Kingdom"*/
};
List<string> monthNames = new List<string>
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
foreach (string name in countryNames)
{
Country country = new Country();
Console.WriteLine(name);
country.Name = name;
country.Months = new List<Month>();
foreach (string _name in monthNames)
{
country.Months.Add(GetMonthDataRows(_name, GetMonth(_name, GetCountry(name, worksheet), worksheet), worksheet));
}
country.Totals = GetTotals(country);
data.Countries.Add(country);
// this is where I would like to update the progressbar
}
} // the using statement calls Dispose() which closes the package.
return data;
}
上記の foreach ループでプログレスバーを更新したいと思います。誰かがこれを行う方法の例を教えてもらえますか?