导出kendoGrid上的日期更改 [英] date changes on export kendoGrid

查看:13
本文介绍了导出kendoGrid上的日期更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 kendoUI 制作了这张表,当用户将表导出到 excel 时,所有日期值都会发生变化,该问题仅出现在 chrome 中,firefox 工作正常.

I have this table made with kendoUI, When user export the table to excel, all dates values change, the issue appears only in chrome, firefox works fine.

您可以在此链接上尝试 runnable

var localData=[
    {cliente:'COMERCIALIZACION',lote:1323,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:10},            {cliente:'COMERCIALIZACION',lote:1324,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:80},{cliente:'COMERCIALIZACION',lote:1325,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:29},                {cliente:'COMERCIALIZACION',lote:1326,calidad:'PRIMERAS',fecha:'2017-07-07',sacos:5}];

推荐答案

该问题很可能是时区不同造成的.浏览器的时区是自动使用的.
尝试将 HH:mm 添加到网格中的日期格式,并在 Excel 表中显示时间并检查时差.

The problem is most likely caused by difference in time zones. The timezone of the browser is used automatically.
Try adding HH:mm to the format of the date in grid and also display the time in the Excel sheet and check the time difference.


如果您只对日期感兴趣而不对时间感兴趣,您可以将日期的小时部分设置为 12,这样即使相差几个小时,日期也将保持不变.


If you're interested only in the date and not the time, you can set the hours component of the date to 12 and that way even if the difference is several hours, the date will remain the same.

您可以使用以下代码来执行此操作:

You can use the following code to do this:

excelExport: (e) => {
    console.log("Excel export", e.workbook);

    e.workbook.sheets[0].rows.filter((row) => row.type === "data").forEach((row, index) => {
        row.cells[2].value.setHours(12);
    });

    console.log("Excel export", e.workbook);
}

如果您想使用更通用的方法而不是日期列的索引,您可以这样做:

If you want to use a more generic approach and not the index of the column with the date, you can do it like this:

e.workbook.sheets[0].rows.filter((row) => row.type === "data").forEach((row, index) => {
    row.cells.filter((cell) => cell.value instanceof Date).forEach((cell) => cell.value.setHours(12));
});

这篇关于导出kendoGrid上的日期更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆