This is a migrated thread and some comments may be shown as answers.

Export to excel - format date to have am/pm

1 Answer 332 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 06 Aug 2015, 10:19 PM

Hello,

I have the code to export to excel, and to even format the date cells, but when I try to format to include am/pm it is not working. I am using the same format text to display am/pm in the grid successfully with "tt" but it does not seem to apply to excel's cell. It displays, for example, "08/06/2015 21:33:02 tt" instead of "8/6/2015  9:33:02 PM" which is the desired result.

excelExport: function(e) {
                var sheet = e.workbook.sheets[0];
 
                for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) {
                    var row = sheet.rows[rowIndex];
                    for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex ++) {
                        row.cells[cellIndex].format = "MM/dd/yyyy hh:mm tt"
                    }
                }
            }

1 Answer, 1 is accepted

Sort by
0
Roger
Top achievements
Rank 1
answered on 07 Aug 2015, 01:12 PM

I have found the answer in Excel's custom formatting options, you must use "AM/PM" in the cell format but when you are formatting the Kendo grid you must use "tt". Hope this will help others.

 

row.cells[cellIndex].format = "MM/dd/yyyy hh:mm AM/PM"
 

Tags
Grid
Asked by
Roger
Top achievements
Rank 1
Answers by
Roger
Top achievements
Rank 1
Share this question
or