First I'd like to emphasize, that I read any possible topic related with dates and field formats.
Because I'm trying the possibilities of this library (but also I'm learning programming) I wanted to check whether the imported field from excel sheet is a date, datetime, time or any other stuff I prepared some excel with the dates and other type of fields.
Unfortunately I can't determine correctly what type of field is delivered in the excel sheet. To make my project faster and less time consuming I tried the method which I found on this forum. Instead of:
DataFromExcel[row, column] = excelReader[column].ToString();
DataFromExcel[row, column] = excelReader.GetValue(column).ToString();
" should fix the problem with receiving field value with it's format without any changes. So for my test I did an excel sheet saved as XLS and XLSX. This is how I fill the array with data and then I display it with the messageBox:
DataFromExcel = new object[rows, cols+1];
for (int column = 0; column<cols; column++)
if (excelReader[column] != null)
DataFromExcel[row, column] = excelReader.GetValue(column).ToString(); // read the data from the excel sheet field
DataFromExcel[row, column] = "";
if (excelReader != null) // check the type of the field (in my case it's DateTime )
DataFromExcel[row, 5] = excelReader.GetValue(2).GetType();
for (int i = 1; i < rows; i++) // check what's imported.
MessageBox.Show("ROW " + i + ": " + DataFromExcel[i, 0] + " ^ " + DataFromExcel[i, 1] + " ^ " + DataFromExcel[i, 2] + " ^ " + DataFromExcel[i, 3] + " ^ " + DataFromExcel[i, 4] + " ^ " + DataFromExcel[i, 5]);
And those are the results: For the XLSX file the datetime field is correctly imported (and shown in messageBox) and the provided type is
. However for the XLS file instead of correct date I get the value e.g. '40613,3476851852
' and the value type is shown as 'System.Double
My questions are:
- Is it possible to correctly check what is the type of the field in Excel sheet, so I could prepare some formatting for delivered data?
- Is it a bug with this dates format provided by the same method (GetValue) from the XLS file?
- Is there any other method to "download" data from Excel file with the values as they are written in the sheet (regardless to their type and format)?
I'd like to say, that I'd like to do something with the values delivered from the Excel sheet but I would like to assume, that the format of the excel sheet may be different every time I'd like to load it.
I'd appreciate for the support.