1

I am pulling Cells from an excel sheet that are supposed to be stored in a string. This has been working with simple strings and ints (for instance the word John in a cell and the number 752 in a cell will return with the string John and the string 752 respectively) in my excel sheet until I came across dates and times (for instance 1/13/2016 and 11:00:00).

Application excelApp = new Application();
Workbook xlWorkbook = excelApp.Workbooks.Open(fileLocation);
Worksheet xlWorksheet = xlWorkbook.Worksheets[worksheetLocation];
Range xlRange = xlWorksheet.UsedRange;

Console.WriteLine(Convert.ToString(xlRange.Cells[i, 14].Value2));

I have tried using the following variations of the conversion:

Convert.ToString(xlRange.Cells[i, 14].Value2);
xlRange.Cells[i, 14].Value2.ToString();
xlRange.Cells[i, 14].Value2.ToString("HH:mm");`

and numerous other variations as well to no avail.

As in the previous example I discussed with the date 1/13/2016, the value that it is returning with is 42382 and the time 11:00:00 is returning with 0.458333333333333. I feel like there could be a quick fix with converting these two numbers back to their original values (for example I saw that 12:00:00 = 0.5) but I am unsure if I want to/should do this.

Any fix would really help a lot. Thank you.

Shirleehee
  • 11
  • 1

0 Answers0