我一直在尝试理解这篇文章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 循环中的进度条。有人可以告诉我一个如何做到这一点的例子吗?