2

I have a variable time which contains string with time in format h:m:s.ms

I was trying to write in a cell this time, but when I open excel I saw smth like 12:34:14 PM. But I want to see 12:34:14.1354

How can I solve this problem?

var line = "2019-07-18 11:07:42.6101";
var time = line.Substring(11, 13);

worksheet.Cell(row, column).Value = time;
Anthony14
  • 105
  • 6

2 Answers2

1

Try something like

worksheet.Cell(row,column).Style.NumberFormat.Format = "h:mm:ss.SSSS";

I am not 100% sure whether the format string is correct. Maybe you start trying out by leaving away the milliseconds part. Compare this: https://github.com/ClosedXML/ClosedXML/wiki/Data-Types

UPDATE: Reflecting anthony14's comment to the answer, the correct code is

worksheet.Cell(row,column).Style.NumberFormat.Format = "h:mm:ss.ms";
Hermann.Gruber
  • 1,257
  • 1
  • 12
  • 37
0

Use format string like "h:mm:ss.000" with zeroes count from 1 to 3. It is worked for me:

worksheet.Cell(row,column).Style.NumberFormat.Format = "h:mm:ss.000"