加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – Kendo Grid导出到Excel货币格式

发布时间:2020-12-15 23:39:10 所属栏目:百科 来源:网络整理
导读:我正在尝试将我的Kendo网格导出为ex??cel.它工作正常,除了缺少格式.我认为这是因为我使用的是模板. The Telerik documentation明确指出: To format the cell values during the export of the Grid to Excel,set the format option of the cells. 我试过这
我正在尝试将我的Kendo网格导出为ex??cel.它工作正常,除了缺少格式.我认为这是因为我使用的是模板.

The Telerik documentation明确指出:

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

我试过这个并没有用:

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网格定义):

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很简单?

解决方法

我认为模板不会对正在导出的数据产生任何影响(因为excelExport基于dataSource).

这是一个working example of excelExport的jsFiddle,它改变了每个单元格的格式.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读