Cell.Type property


#1

I am opening an uploaded Excel file with your control.

The Excel file contains a column with date values, but since the input is under the control of the user, I need to validate I have a valid date before I process it as a date.

I was trying to use the …

sheet.Cells[row, col].Type == CellValueType.IsDateTime

property to make this determination, but it seems the date values are coming through as CellValueType.IsNumeric. Will this always be the case for DateTime values? and will I never see a CellValueType.IsDateTime for imported data?

Is a better way to use try…catch blocks when looking for valid Date values? I am concerned about performance and there could potentially be lots of invalid data.

I just need to know what is valid data and what is invalid data.

Thanks,
John


#2

Dear John,

MS Excel save date values as integer or double values and show it according to the style number format. So if the users use the custom date format, Aspose.Excel may fail to distinguish it from numeric values. Anyway, if the type of cell is numberic, it can be converted into date value correctly.

And could you send me the uploaded excel file? I will investigate it to give you a more elegant solution.