SpreadsheetLight does not accept the timespan type

211 Views Asked by At

I'm using spreadsheetlight for exporting datas to excel. I have time values which defined string and i want to convert or parse to Timespan but spreadsheetlight does not accept Timespan value. How can i define Timespan with spreadsheetlight?

Here is my codes:

var longTimeStyle = Document.CreateStyle();
longTimeStyle.Alignment.Horizontal = HorizontalAlignmentValues.Right;
longTimeStyle.FormatCode = CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern;

    for (int i = 0; i < shiftStatus.Count; i++)
  {
     Document.SetCellStyle(i + 2, 7, longTimeStyle);
     //shiftStatus[i].PreperationTime is string
     Document.SetCellValue(i + 2, 7, shiftStatus[i].PreperationTime); 
  }
1

There are 1 best solutions below

0
On

Here is my solution to this problem:

public string ConvertTimeSpanForExcel(TimeSpan ts)
{

  return String.Format($"{ts.Days} d. {ts.Hours} h. {ts.Minutes} min. {ts.Seconds} sec.");

}

Document.SetCellStyle(i + 2, 7, ConvertTimeSpanForExcel(shiftStatus[i].PreperationTime));

If you need weeks, months, etc., then develop a method for dividing days and output this result.