I am trying to read the text value of a specific cell from excel. The value in question is a formula which sums up multiple cells.
What Ive tried so far:
worksheet.Cells["E42"].Style.Numberformat.Format = "hh:mm"; //and [hh]:mm
result = worksheet.Cells["E42"].Text;
Converting the worksheet.Cells["E42"].Value to DateTime using FromAoDate doesnt work for me either.
The best result was 08:20 which is conveniently 24h less than the actual value.
EDIT: Results from the suggestions
worksheet.Cells["E42"].Style.Numberformat.Format = "[hh]:mm";
result = worksheet.Cells["E42"].Text; //returns "08"
worksheet.Cells["E42"].Style.Numberformat.Format = "hh:mm";
result = worksheet.Cells["E42"].Text; //returns "08:20"
worksheet.Cells["E42"].Style.Numberformat.Format = "hh:mm";
result = worksheet.Cells["E42"].Text;
result = TimeSpan.TryParse((string)result, out TimeSpan tres); //returns 08:20:00
worksheet.Cells["E42"].Style.Numberformat.Format = "[hh]:mm";
result = worksheet.Cells["E42"].Text;
result = TimeSpan.TryParse((string)result, out TimeSpan tres); //returns 8.00:00:00
//converting to DateTime has similar results
result = DateTime.FromOADate(Convert.ToDouble(worksheet.Cells["E42"].Value));
//returns 31.12.1899 08:20:00
