Kendo Grid导出到Excel货币格式 [英] Kendo Grid Export To Excel Currency formatting

查看:227
本文介绍了Kendo Grid导出到Excel货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Kendo网格导出为Excel.它工作正常,但缺少格式.我认为这是因为我正在使用模板.

I am trying to export my Kendo grid to excel. It works fine except the formatting is missing. I think it is because I am using a template.

Telerik文档明确指出:

要在将网格导出到Excel的过程中设置单元格值的格式,请设置 单元格的格式选项.

To format the cell values during the export of the Grid to Excel, set the format option of the cells.

我已经尝试过了,但是它不起作用:

I have tried this and it is not working:

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' #"
    }];    

我也具有此功能(用于Excel网格定义):

I also have this function (for excel grid defintiion):

    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
        });
    },

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

Do I need to parse each cell here? Am I doing something wrong? I would think this would be really simple, since the whole Export to Excel is straightforward??

推荐答案

我认为template对导出的数据没有任何影响(因为excelExport基于dataSource).

I don't think template should have any effect on the data being exported (as the excelExport is based on the dataSource).

这是 excelExport 的工作示例的jsFiddle,它会更改每个文件的格式cell.

请注意excelExport代码之间的区别:

Note the difference between the excelExport code:

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";
            }
        }
    }      
  }

这篇关于Kendo Grid导出到Excel货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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