Custom number format [hh]:mm:ss

Nov 10, 2014 at 10:13 PM
Edited Nov 10, 2014 at 10:14 PM
I'm trying to set a cell with custom number format code [hh]:mm:ss so that the visible value always follows an hr:min:sec format. The cell value is set to a string which is in this format (for example, "12:00:00"). Everything seems to work until the hours value is greater than 24.

Here's the code I'm using to create the spreadsheet:
for(int i = 0; i < output.Count; i++)
            {
                newCol.Cell(ExcelRowStart + i).Value = output[i];

                if (Regex.Match(output[i], "\\d{2,}.\\d{2,}.\\d{2,}").Success)
                {
                    newCol.Cell(ExcelRowStart + i).Style.NumberFormat.Format = "[hh]:mm:ss";
                }
            }
Here's an image of the result where I increment the hour value by 1 for each row:

Image

What can I do to get this to display like I want?
Coordinator
Nov 10, 2014 at 10:23 PM
You have 2 options:
1) Format output[i] in a way that .Net's TimeSpan.Parse likes (using explicit days).
2) Convert output[i] to a TimeSpan and assign it to the cell's value.

See:
http://closedxml.codeplex.com/discussions/566791
http://msdn.microsoft.com/en-us/library/3z48198e%28v=vs.110%29.aspx
Nov 10, 2014 at 10:57 PM
Thanks!