1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| private DataTable convertAODateTime(DataTable excelData, List<ColumnInfo> colInfo)
{
for (int i = 0; i < colInfo.Count; i++)
{
if (colInfo[i].type.Equals("DateTime"))
{
int firstPart = excelData.Rows.Count / 2;
Action firstAction = delegate
{
for (int j = 0; j < firstPart; j++)
{
excelData.Rows[j][i] = convert(excelData.Rows[j][i].ToString());
}
};
Action secondAction = delegate
{
for (int k = firstPart; k < excelData.Rows.Count; k++)
{
excelData.Rows[k][i] = convert(excelData.Rows[k][i].ToString());
}
};
IAsyncResult firstHandle = firstAction.BeginInvoke(null, null);
IAsyncResult secondHandle = secondAction.BeginInvoke(null, null);
firstAction.EndInvoke(firstHandle);
secondAction.EndInvoke(secondHandle);
}
}
return excelData;
}
private string convert(string data)
{
double value;
if (double.TryParse(data, out value))
{
try
{
data= DateTime.FromOADate(value).ToString();
}
catch
{
}
}
return data;
} |
Partager