[英]SpreadsheetLight does not accept the timespan type
I'm using spreadsheetlight for exporting datas to excel. 我正在使用sheetlightlight将数据导出到excel。 I have time values which defined string and i want to convert or parse to Timespan but spreadsheetlight does not accept Timespan value.
我有定义字符串的时间值,并且我想将其转换或解析为Timespan,但sheetlightlight不接受Timespan值。 How can i define Timespan with spreadsheetlight?
如何使用电子表格光定义Timespan?
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);
}
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. 如果需要数周,数月等,请开发一种划分天数的方法并输出该结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.