Kendo Grid 导出到 Excel 货币格式

Aus*_*Joe 3 c# jquery kendo-ui kendo-grid

我正在尝试将我的剑道网格导出为 excel。除了格式丢失之外,它工作正常。我认为这是因为我正在使用模板。

Telerik 文档明确指出:

要在将 Grid 导出到 Excel 期间设置单元格值的格式,请设置单元格的格式选项。

我试过这个,但它不起作用:

columns: [
    {
        field: "EntryWage",
        headerTemplate: entryLevelWageColumnHeading + "<span name='EntryWage' class='k-icon k-i-close remove' style='float: right;'></span>",
        width: 125,
        attributes: { style: "text-align:right;" },
        format: "{0:c}",
        template: "#= (EntryWage != null) ? kendo.toString(EntryWage, 'C') : 'N/A' #"
    }];    
Run Code Online (Sandbox Code Playgroud)

我也有这个功能(用于 excel 网格定义):

    excelExport: function (e) {
        var sheet = e.workbook.sheets[0];
        var row = sheet.rows[0];
        $("#grid .k-grid-header .k-link").each(function (index) { //for each column header in the grid...
            row.cells[index].value = $(this).text(); //set cell text from grid column text
            row.cells[index].background = "#0070C0"; //set cell to "blue" color
        });
    },
Run Code Online (Sandbox Code Playgroud)

我需要在这里解析每个单元格吗?难道我做错了什么?我认为这真的很简单,因为整个导出到 Excel 很简单??

San*_*man 5

我认为template应该不会对导出的数据产生任何影响(因为excelExport它基于dataSource)。

这是一个工作示例的excelExportjsFiddle,它更改了每个cell.

注意excelExport代码之间的区别:

excelExport: function(e) {      
  var sheet = e.workbook.sheets[0];

  for (var rowIndex = 0; rowIndex < sheet.rows.length; rowIndex++) {
    var row = sheet.rows[rowIndex];        
    for (var cellIndex = 0; cellIndex < row.cells.length; cellIndex++) {
        var cell = row.cells[cellIndex];
        if (row.type === "data") {
            //if (cellIndex == 2) { 
            if (sheet.rows[0].cells[cellIndex].value == "unitPrice") {// like this
                cell.format = "number";
                cell.background = "#0070C0"
                cell.hAlign = "right";
            }
        }
    }      
  }
Run Code Online (Sandbox Code Playgroud)