Kendo Grid 导出到 Excel 货币格式 [英] Kendo Grid Export To Excel Currency formatting
问题描述
我正在尝试将我的剑道网格导出到 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 文档明确指出:
要在将 Grid 导出到 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,它发生了变化每个单元格
的格式.
注意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";
}
}
}
}
这篇关于Kendo Grid 导出到 Excel 货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!