Date format exported to Excel

1 Answer 36 Views
Excel Export Grid
Victor
Top achievements
Rank 1
Victor asked on 10 Jan 2024, 09:46 PM

Hi

I'd like to fix an issue we have about the columns using dates, we have a dashboard and when user export the dash to Excel. 

seems like there's no problem or something, however when we proceed to open the Excel file. 

if we take a look to those columns displaying dates,  then we select any of these cells,  right click, "format cell"

Catogory is displayed as "General",  instead of date and any of the possible types-formats

so when user is trying to apply filter in excel, values for date columns are not recognized as dates.

I have been trying to modify the date format like these

 //attempt3

  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("dd MMM yyyy HH:mm:ss zzz").format(requestHeaderView.pcagatecurrentdate) : null
  //attempt4
  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("MM-dd-yy HH:mm:ss zzz").format(requestHeaderView.pcagatecurrentdate) : null
  //attempt5
  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("MM-dd-yy 07:00:00").format(requestHeaderView.pcagatecurrentdate) : null
  //attempt6
  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("MM-dd-yy 19:00:00").format(requestHeaderView.pcagatecurrentdate) : null
  //attempt7
  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("MM-dd-yy'T'HH:mm:ss.SSSZ").format(requestHeaderView.pcagatecurrentdate) : null
  //attempt8
  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(requestHeaderView.pcagatecurrentdate) : null
  //attempt9
  //pcagatecurrentdate requestHeaderView.pcagatecurrentdate ? new SimpleDateFormat("MM-dd-yyyy'T'HH:mm:ss.SSSZ").format(requestHeaderView.pcagatecurrentdate) : null

 

this is how it looks like in the front end,

<kendo-grid-column
field="pcagatecurrentdate"
[columnMenu]="true"
title="{{ getTitle('pcagatecurrentdate') }}"
tooltip=""
[locked]="false"
width="110"
>
<ng-template
kendoGridFilterMenuTemplate
let-filter
let-column="column"
let-filterService="filterService"
>
<app-date-range-filter
[field]="column.field"
[filter]="filter"
[filterService]="filterService"
>
</app-date-range-filter>
</ng-template>
<ng-template kendoGridCellTemplate let-dataItem>
<span
[ngClass]="{
okProjectStatus:
dataItem.projectConceptApprovedStatus ==
'ok',
warningProjectStatus:
dataItem.projectConceptApprovedStatus ==
'warning',
dangerProjectStatus:
dataItem.projectConceptApprovedStatus ==
'danger'
}"
>
{{
dataItem.pcagatecurrentdate != null
? (dataItem.pcagatecurrentdate
| date : 'dd-MMM-yyyy')
: ''
}}
</span>
</ng-template>
</kendo-grid-column>

 

but at the end all the dates still displayed as "General"

 

and this is the target I would like to reach

 

I appreciate any suggestions you may have

Thanks

Victor M.

1 Answer, 1 is accepted

Sort by
0
Yanmario
Telerik team
answered on 15 Jan 2024, 08:24 AM

Hi Victor,

Thank you for the provided details.

I did some testing and if the provided date in the cell is a valid JavaScript Date it is exported as a Date:

https://stackblitz.com/edit/angular-vcpxvf?file=src%2Fapp%2Fapp.component.ts,src%2Fapp%2Fproducts.ts

If the dates are string on your side, I will suggest casting them to a valid JavaScript Date and formatting them as desired for the Grid cell. 

I hope this helps.

Regards,
Yanmario
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
Tags
Excel Export Grid
Asked by
Victor
Top achievements
Rank 1
Answers by
Yanmario
Telerik team
Share this question
or