public class ExcelConvert
{
public int toExcelDate(int nDay, int nMonth, int nYear) {
if (nDay == 29 && nMonth == 02 && nYear==1900)
return 60;
long nSerialDate = (int)(( 1461 * ( nYear + 4800 + (int)(( nMonth - 14 ) / 12) ) ) / 4) +
(int)(( 367 * ( nMonth - 2 - 12 * ( ( nMonth - 14 ) / 12 ) ) ) / 12) -
(int)(( 3 * ( (int)(( nYear + 4900 + (int)(( nMonth - 14 ) / 12) ) / 100) ) ) / 4) +
nDay - 2415019 - 32075;
if (nSerialDate < 60) {
nSerialDate--;
}
return (int)nSerialDate;
}
public object convertArray(object anarray) {
object[,] ary = (object[,])anarray;
int rows = ary.GetUpperBound(0) + 1;
int cols = ary.GetUpperBound(1) + 1;
for ( int row = 0 ; row < rows ; row++ ) {
for ( int col = 0 ; col < cols ; col++ ) {
object result;
string value = (string) ary[row,col];
try {
result = Convert.ToDouble(value);
}
catch ( FormatException e ) {
try {
DateTime dt = DateTime.Parse(value);
result = toExcelDate(dt.Day, dt.Month, dt.Year);
}
catch ( FormatException e2 ) {
result = value;
}
}
ary[row,col] = result;
}
}
return ary;
}
}