【发布时间】:2014-01-26 16:52:06
【问题描述】:
我有以下来自 Excel 工作表的数据:
06:07:00 6:07
Data1
Data2
Data3
Data4
06:15:00 06:15
Data5
Data6
Data7
Data8
我想将此与文本文件中的以下数据进行比较:
XXXXXXXXXX 06:08:32 13.0 Data1
XXXXXXXXXX 06:08:45 6.0 Data2
xxxxxxxxxx 06:08:51 5.0 Data3
xxxxxxxxxx 06:08:56 13.0 Data4
xxxxxxxxxx 06:13:44 9.0 Data5
xxxxxxxxxx 06:13:53 11.0 Data6
xxxxxxxxxx 06:14:04 6.0 Data7
xxxxxxxxxx 06:14:10 13.0 Data8
由于我想使用时间来比较两个文件(excel 与文本),因此每个组的时间都不同。 Group1(data1 到 Data4),group2(Data5-data8)。
有没有人知道如何处理这种情况。
编辑1:
这是我尝试做的:
private void doTest(string time)
{
TimeSpan ts = TimeSpan.Parse(time);
int hours = ts.Hours;
int min = ts.Minutes;
int sec = ts.Seconds;
int minstart, minend;
string str;
minstart = min - 5;
minend = min + 5;
while (min != minend)
{
sec = sec + 1;
if (sec < 60)
{
if (hours < 10)
str = hours.ToString().PadLeft(2, '0');
else str = hours.ToString();
if (minstart < 10)
str = str + minstart.ToString().PadLeft(2, '0');
else str = str + minstart.ToString();
if (sec < 10)
str = str + sec.ToString().PadLeft(2, '0');
else str = str + sec.ToString();
chkwithtext(str);
}
else if (sec == 60)
{
sec = 00;
min = min + 1;
str = hours.ToString() + min.ToString() + sec.ToString();
chkwithtext(str);
}
}
}
private void chkwithtext(string str)
{
// check with the text file here if time doesn't match go
// back increment the time with 1sec and then check here again
}
【问题讨论】:
-
请参阅我的 EDIT1。这种实现我想要的方法似乎很复杂,有没有人有更短的方法。
-
我不明白“比较两个文件”是什么意思。我看不出 doTest() 方法与 excel-txt 比较有什么关系。
-
我也不知道你想做什么。您能解释一下数据的来源以及您负责处理这些数据的工作吗?