我创建了一个小型项目,我使用的是TimeSpan数据类型,我正在尝试登录和注销时间,但是当导出到Excel时,时间不会显示在Excel列中。
请帮帮我。
这是我使用时间跨度的代码:
public TimeSpan PunchIn { get; set; }
[NotMapped]
public string Month
{
get
{
var In = TimeZoneInfo.ConvertTimeFromUtc(PunchDate.Date + PunchIn,
TimeZoneInfo.FindSystemTimeZoneById(User.RegisteredTimeZone));
return In.ToString("MMMM");
}
}
这是kendo网格代码:
@(Html.Kendo().Grid(Model)
.Name("TimeTrackingLogsGrid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Hidden(true).HtmlAttributes(new {style="text-align:center;"});
columns.Bound(c => c.IsDeleted).Hidden(true);
columns.Bound(c => c.ApprovalRequired).Visible((bool)ViewBag.IsAdmin).ClientTemplate("# if (ApprovalRequired == true && Approved == false && '"+ (ViewBag.IsAdmin).ToString() + "'=== 'True') {# Yes: <a data-ajax='true' data-ajax-complete='refreshGrid' data-ajax-method='POST' href='/Punch/Approve/#:Id#' class='grid-link' >Approve</a>#} else{# No #}#");
columns.Bound(c => c.EmployeeName).Filterable(ftb => ftb.Multi(true).Search(true));
columns.Bound(c => c.Month).Hidden(true).Filterable(ftb => ftb.Multi(true));
columns.Bound(c => c.PunchDate)
.ClientFooterTemplate("#= getFormattdDate(data.PunchDate.min) # - #= getFormattdDate(data.PunchDate.max) # ")
.ClientGroupHeaderTemplate("#:convetUtcDateToLocalDate(PunchDate)#").HtmlAttributes(new { @class = "utc-date", utc_date_value = "#:PunchDate#" });
columns.Bound(c => c.PunchInPic).Hidden(true).Visible((bool)ViewBag.IsAdmin).ClientTemplate("<img class='punchPic' width='100' src='data: image / png; base64,#:PunchInPic#'/>").HtmlAttributes(new { style="text-align:center;"});
columns.Bound(c => c.PunchIn).Groupable(false).Filterable(false).ClientTemplate("#:PunchIn.Hours#:#:PunchIn.Minutes#").HtmlAttributes(new { @class = "utc-time", utc_time_value = "#:PunchIn.Hours#:#:PunchIn.Minutes#" });
columns.Bound(c => c.PunchOutPic).Hidden(true).Visible((bool)ViewBag.IsAdmin).ClientTemplate("<img class='punchPic' width='100' src='data: image / png; base64,#:PunchOutPic#'/>").HtmlAttributes(new { style = "text-align:center;" });
columns.Bound(c => c.PunchOut).Groupable(false).Filterable(false).ClientTemplate("#:PunchOut == null ? 0 :PunchOut.Hours #:#: PunchOut == null ? 0 : PunchOut.Minutes #").HtmlAttributes(new {@class= "utc-time", utc_time_value = "#: PunchOut == null ? 0 : PunchOut.Hours#:#:PunchOut == null ? 0 : PunchOut.Minutes #" });
columns.Bound(c => c.Duration).Groupable(false).Filterable(false)
.ClientFooterTemplate("#= SecondsToTime(data.DurationInSeconds.sum) # ")
.ClientTemplate("#:formatDuration(Duration.Hours,Duration.Minutes) #").HtmlAttributes(new { @class = "" });
columns.Bound(c => c.Comments).Visible((bool)ViewBag.IsAdmin).Filterable(false).Groupable(false).ClientTemplate("# if (ApprovalRequired == true && Approved == false && '" + (ViewBag.IsAdmin).ToString() + "' !== 'True') {# Please get this time log approved #} else{#<span class='comments' (#:Comments# == null ? '' : title='<ul> #:Comments# </ul>')> view <span>#}#");
columns.Command(command =>
{
// command.Edit().Text(" ");
command.Destroy().Text(" ");
}).Width(50);
})
.HtmlAttributes(new { @class = "full-screen-dashboard" })
//.Scrollable()
.Groupable()
.Sortable()
.Filterable()
.Navigatable()
.ColumnMenu()
.ToolBar(toolbar => {
//toolbar.Create();
//toolbar.Save();
toolbar.Pdf();
toolbar.Excel();
toolbar.Custom().Text("Clear Filter").HtmlAttributes(new { @class= "clearGridFilter" });
})
.Excel(exl=>exl.AllPages(true).Filterable(true).FileName("Timesheet.xlsx")
.ProxyURL(Url.Action("ExportSave", "Punch")))