I'm able to format the dates the way I want in the grid, but they don't appear that way in my Excel export.
The code in my controller is:
1.
[HttpPost]
2.
public
ActionResult Excel_Export_Save(
string
contentType,
string
base64,
string
fileName)
3.
{
4.
var fileContents = Convert.FromBase64String(base64);
5.
return
File(fileContents, contentType, fileName);
6.
}
In my grid code below, lines 11 and 15 are the date fields in question. They appear in the grid as MM/dd/yy hh:mm tt, but in the export they appear as MM/dd/yyyy.
01.
@(Html.Kendo().Grid<ErmhsL2BudReqRawDto>()
02.
.Name(
"Grid"
)
03.
.Columns(columns =>
04.
{
05.
columns.Bound(c => c.Id).Hidden();
06.
columns.Bound(c => c.CharterId).Hidden();
07.
columns.Bound(c => c.CharterName).Width(400).Filterable(ftb => ftb.Cell(cell => cell.Operator(
"contains"
).SuggestionOperator(FilterType.Contains))).Locked(
true
);
08.
columns.Bound(c => c.EdcoeId).Width(100).Locked(
true
);
09.
columns.Bound(c => c.CdsCodeWithDashes).Locked(
true
).Width(150);
10.
columns.Bound(c => c.FiscalYear).Filterable(filterable => filterable.UI(
"fiscalYearFilter"
)).Locked(
true
).Width(100);
11.
columns.Bound(c => c.DateEntered).Format(
"{0:MM/dd/yy hh:mm tt}"
).HtmlAttributes(
new
{ style =
"text-align:right"
}).Width(100);
12.
columns.Bound(c => c.ProgressMonitoringFrequency).Width(500);
13.
columns.Bound(c => c.MonitorNameAndTitle).Width(300);
14.
columns.Bound(c => c.IsAmhpCertified).Filterable(filterable => filterable.Messages(m => m.IsFalse(
"No"
)).Messages(m => m.IsTrue(
"Yes"
))).ClientTemplate(
"#=IsAmhpCertified ? 'Yes': 'No'#"
).HtmlAttributes(
new
{ style =
"text-align:center"
}).Width(100);
15.
columns.Bound(c => c.AmhpDateEntered).Format(
"{0:MM/dd/yy hh:mm tt}"
).HtmlAttributes(
new
{ style =
"text-align:right"
}).Width(100);
16.
})
17.
.ToolBar(tools => tools.Excel())
18.
.Excel(excel => excel
19.
.AllPages(
true
)
20.
.FileName(
"ERMHS Level 2 Budget Requests.xlsx"
)
21.
.Filterable(
true
)
22.
.ProxyURL(Url.Action(
"Excel_Export_Save"
,
"FiscalReport"
))
23.
)
24.
.Filterable(filterable => filterable
25.
.Extra(
false
)
26.
.Operators(operators => operators
27.
.ForString(str => str.Clear()
28.
.StartsWith(
"Starts with"
)
29.
.IsEqualTo(
"Is equal to"
)
30.
.IsNotEqualTo(
"Is not equal to"
)
31.
))
32.
)
33.
.Groupable()
34.
.Pageable(m => m.PageSizes(
new
[] {
"25"
,
"50"
,
"100"
,
"All"
}))
35.
.Resizable(resizable => resizable.Columns(
true
))
36.
.Sortable()
37.
.Scrollable(s => s.Enabled(
true
))
38.
.HtmlAttributes(
new
{ style =
"height:700px;"
})
39.
.DataSource(dataSource => dataSource
40.
.Ajax()
41.
.PageSize(25)
42.
.Events(events => events.Error(
"error_handler"
))
43.
.Model(model =>
44.
{
45.
model.Id(p => p.Id);
46.
model.Field(p => p.Id).Editable(
false
);
47.
model.Field(p => p.CharterId).Editable(
false
);
48.
})
49.
.Sort(sort =>
50.
{
51.
sort.Add(p => p.CharterName);
52.
})
53.
.Read(read => read.Action(
"ErmhsL2BudgetRequests_Read"
,
"FiscalReport"
))
54.
)
55.
)