Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: TimeSpan handling

$
0
0
Is there a reason why TimeSpan data types are handled wiered when values contains value over 24 hours. Even if TimeSpan data type is set for cell the value will be reformatted by Excel when opened.
In following example produced excel file shows other values than those set in code.
        var wb = new XLWorkbook();
        var ws = wb.Worksheets.Add("TimeSpan test");

        ws.Cell(1, 2).Value = "23:00:00";   // This is good
        ws.Cell(2, 2).Value = "25:00:00";   // Not good
        ws.Cell(3, 2).Value = "35:00:00";   // Not good -> Excel reformats this
        ws.Cell(3, 2).DataType = XLCellValues.TimeSpan; // even data type is set  
        ws.Cell(4, 2).Value = new TimeSpan(35, 0, 0); // This is good
        ws.Cell(5, 2).Value = new TimeSpan(35, 0, 0).ToString(); // This is good
And resulting excel contains following:
23:00:00
600:00:00
840:00:00
35:00:00
35:00:00

Is this something expected?
Thank you.

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>