Kendo SaveAsExcel 南
Kendo SaveAsExcel nan
我正在生成一个分布sheet,有时数据会以 NaN 形式出现。没问题
但是,当我 "SaveAsExcel",并在 Excel 2016 年打开价差 sheet 时,我得到
"We found a problem with some content in 'reportname'. Do you want us to try and recover as much as we can? If you trust the source of this workbook, click yes"
单击是,我发现 Excel 能够使用以下内容打开文件:
"Repaired Records: Cell information from /xl/worksheets/sheet1.xml part"
和一个 link 到一个日志文件,它显示...什么都没有
error072200_01.xmlErrors 在文件 MyFileName.xlsx 中检测到'已修复的记录:来自 /xl/worksheets/sheet1.xml 部分
的单元格信息
现在,如果我删除 sheet 上的 NaN,我没有任何问题。有人知道我该如何解决这个问题吗?
我重新创建了问题并提出了一个解决方案 - 遍历 sheet 的所有单元格并检查单元格的值是否为 NaN
并验证为数字,如果是,将值更改为“”。
您当然可以将解决方案更改为更适合您需求的解决方案。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.rtl.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.silver.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.mobile.all.min.css"/>
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2017.2.621/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script>
</head>
<body>
<button id="export">Export to Excel</button>
<div id="spreadsheet"></div>
<script>
$("#spreadsheet").kendoSpreadsheet({
sheets: [{
name: "Food Order",
mergedCells: [
"A1:G1"
],
rows: [{
height: 70,
cells: [{
value: "My Company", fontSize: 32, textAlign: "center"
}]
}, {
cells: [{
value: NaN,
textAlign: "center",
validation: {
from: "1",
to: "2",
comparerType: "between",
dataType: "number",
messageTemplate: "Number should match the validation."
}
}]
}],
}],
excelExport: function(e) {
e.workbook.sheets[0].rows.forEach(function(row) {
row.cells.forEach(function(cell) {
if (isNaN(cell.value) && cell.validation && cell.validation.dataType === "number") {
cell.value = "";
}
});
});
console.log(e.workbook.sheets[0]);
}
});
$("#export").click(function(e) {
var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
spreadsheet.saveAsExcel();
});
</script>
<!-- Load JSZIP library to enable Excel export -->
<script src="http://kendo.cdn.telerik.com/2017.2.621/js/jszip.min.js"></script>
</body>
</html>
我正在生成一个分布sheet,有时数据会以 NaN 形式出现。没问题
但是,当我 "SaveAsExcel",并在 Excel 2016 年打开价差 sheet 时,我得到 "We found a problem with some content in 'reportname'. Do you want us to try and recover as much as we can? If you trust the source of this workbook, click yes" 单击是,我发现 Excel 能够使用以下内容打开文件:
"Repaired Records: Cell information from /xl/worksheets/sheet1.xml part"
和一个 link 到一个日志文件,它显示...什么都没有
error072200_01.xmlErrors 在文件 MyFileName.xlsx 中检测到'已修复的记录:来自 /xl/worksheets/sheet1.xml 部分
的单元格信息现在,如果我删除 sheet 上的 NaN,我没有任何问题。有人知道我该如何解决这个问题吗?
我重新创建了问题并提出了一个解决方案 - 遍历 sheet 的所有单元格并检查单元格的值是否为 NaN
并验证为数字,如果是,将值更改为“”。
您当然可以将解决方案更改为更适合您需求的解决方案。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Kendo UI Snippet</title>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.common.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.rtl.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.silver.min.css"/>
<link rel="stylesheet" href="http://kendo.cdn.telerik.com/2017.2.621/styles/kendo.mobile.all.min.css"/>
<script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2017.2.621/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2017.2.621/js/kendo.all.min.js"></script>
</head>
<body>
<button id="export">Export to Excel</button>
<div id="spreadsheet"></div>
<script>
$("#spreadsheet").kendoSpreadsheet({
sheets: [{
name: "Food Order",
mergedCells: [
"A1:G1"
],
rows: [{
height: 70,
cells: [{
value: "My Company", fontSize: 32, textAlign: "center"
}]
}, {
cells: [{
value: NaN,
textAlign: "center",
validation: {
from: "1",
to: "2",
comparerType: "between",
dataType: "number",
messageTemplate: "Number should match the validation."
}
}]
}],
}],
excelExport: function(e) {
e.workbook.sheets[0].rows.forEach(function(row) {
row.cells.forEach(function(cell) {
if (isNaN(cell.value) && cell.validation && cell.validation.dataType === "number") {
cell.value = "";
}
});
});
console.log(e.workbook.sheets[0]);
}
});
$("#export").click(function(e) {
var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
spreadsheet.saveAsExcel();
});
</script>
<!-- Load JSZIP library to enable Excel export -->
<script src="http://kendo.cdn.telerik.com/2017.2.621/js/jszip.min.js"></script>
</body>
</html>