2017-07-31 47 views
1

當我嘗試從Kendo網格中導出excel時,日期格式不正確。Kendo網格導出日期格式不正確

此Warranty_Start_Date在我的表格列中可以爲空,以下是網格列的模板。

customColumns.push({ 
     title: customHeaders[i], 
     field: headers[i], 
     width: 150, 
     template: 
      "#= " + headers[i] + " ? kendo.toString(kendo.parseDate(" + headers[i] + "), 'dd/MM/yyyy') : 'N/A' #", 
    }); 

和網格,我使Excel導出功能,並試圖以自定義某些列的格式爲:

  var grid = $("#gridHardwares").kendoGrid({ 
     excel: { 
      fileName: "excelfile.xlsx", 
      allPages: true, 
      filterable:true 
     }, 
     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 ++) { 
        if (cellIndex >= 9 && cellIndex <= 11) 
        { 
         row.cells[cellIndex].format = "yy-MM-dd hh:mm:ss"; 
        } 
        if (cellIndex >= 13) 
         row.cells[cellIndex].format = "0.00"; 
       } 
      } 
     }, 

我不明白,因爲這兩位小數格式工作正常,但日期格式不是。 導出結果在Excel: date is not in readable format

我也試過這種方法,它保持柱模板,但我打了一個錯誤「取代未定義」

  excelExport: function(e) { 
      var sheet = e.workbook.sheets[0]; 
      var template = kendo.template(this.columns[13].template); 
      for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) { 
       var row = sheet.rows[rowIndex]; 

       for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex ++) { 
        if (cellIndex >= 9 && cellIndex <= 11) 
        { 
         var dataItem = { 
          Warranty_Start_Date: row.cells[13].value 
         }; 

         row.cells[13].value = template(dataItem); 
         row.cells[cellIndex].format = "yy-MM-dd hh:mm:ss"; 
        } 
        if (cellIndex >= 13) 
         row.cells[cellIndex].format = "0.00"; 
       } 
      } 
     }, 

error occur when export

也許這個模板方法不適合我的情況,我不知道。但是,有沒有其他方法將此日期字符串/ Date(1382544000000)/轉換爲適當的「dd-MM-yyyy」格式?需要幫助的迫切:(

+0

無關,與你的問題,但「YY-MM-DD HH:毫米: ss「將會產生一個12小時不明確的時間,而不是am/pm。請考慮」yy-MM-dd HH:mm:ss「。 – RobG

回答

0

那麼好吧,該解決方案只設置此字段類型爲「日」瘋狂 enter image description here