Kendo出口excell缺少$号

时间:2019-02-04 12:56:54

标签: asp.net-mvc kendo-grid kendo-asp.net-mvc

我正在使用kendo导出来实现excell功能,并且通过使用columns.Bound(x => x.TotalAccountValue).Format("{0:c}");此代码,我能够在Grid中看到$符号,但是当我尝试导出$符号时,Excel导出中却缺少该符号。

1 个答案:

答案 0 :(得分:0)

当您要在剑道的Excel中导出GRID时。这是一个如何编辑标题以及如何格式化每个列值的有效示例。

此示例可能对您有所帮助。

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

  //Excel output - create a header row
  $("#grid .k-grid-header .k-link").each(function (i) { //for each column header in the grid...
      firstRow.cells[i].value = $(this).text(); //set cell text from grid column text
      firstRow.cells[i].background = "#0070C0"; //set cell to "blue" color
  });


  //Excel output - column formatting
  var formatColMask = null;

  for (var rowIndex = 1; rowIndex < sheet.rows.length; rowIndex++) { //begin on first row (skip header)
      var row = sheet.rows[rowIndex]; //get each row from Excel file

      for (var colIndex = 0; colIndex < row.cells.length; colIndex++) { //for each row, check each cell by field name

            switch (this.columns[colIndex].field) {
                case "Field1":
                    formatColMask = "###,##0";
                    break;
                case "Field2":
                    formatColMask = "$#,##0";
                    break;
                case "Field3":
                    formatColMask = "$#,##0";
                    break;
                default:
                    break;
            }
            row.cells[colIndex].format = formatColMask; //apply column format mask
        }
    }
},