从Excel表格中计数值

我需要在一定时间内计算Excel表格中特定值的精度。 现在我有这个部分:

string sub = range.Cells[rCnt, 7].Value.ToString(); char[] delimiterChars = { ' ', '/', '.', ':', '\t' }; string date = range.Cells[rCnt, 4].Value.ToString(); string[] d = date.Split(delimiterChars); if (d[0] == "1" && d[2] == "2012" || d[0] == "2" && d[2] == "2012" || d[0] == "3" && d[2] == "2012") { if (sub == "AM") { AM[0]++; } } 

我想这样做,如果date是2012年1月2日或3月,值为"AM" ,则"AM"的第一项将加1。

时间格式为" M/D/YH:M:S" ,表格中有300个项目在这几个月内有这个值,但是它会返回大约1000

它可能是什么东西

 List<int> AM = Enumerable.Repeat(0, 16).ToList(); 

因为这就是代码中唯一改变列表中值的其他东西

为什么不使用DateTime来parsing值:

 DateTime dateTime = DateTime.ParseExact(date.Trim(), "M/d/yyyy H:mm:ss", CultureInfo.InvariantCulture); if((dateTime.Month == 1 || dateTime.Month == 2 || dateTime.Month == 3) && dateTime.Year == 2012) { if (sub == "AM") { AM[0]++; } } 

testing了这种格式的date:“2012/1/1 20:00:00”,它的工作。