在Kendo电子表格中获取特殊列的值

时间:2019-04-01 00:11:52

标签: javascript jquery kendo-ui spreadsheet kendospreadsheet

例如,我有一列这样的内容:

A

50

65

73

NULL

63

我可以获得选定范围内的值

let sh = $("#spreadsheet").getKendoSpreadsheet();
var sheet = sh.activeSheet();
var range = sheet.selection();
var values = range.values(); 

,并希望获取所有 A 列的值而无需选择。我想要的剑道电子表格中有一种方法吗?我该怎么办?

1 个答案:

答案 0 :(得分:1)

您可以使用range函数来获得特定范围内的值,如下所示:

var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
var values = spreadsheet.sheets()[0].range("A1:A3").values();

您可以在以下片段中看到一个演示:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>Kendo UI Snippet</title>

    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.common.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.rtl.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.silver.min.css"/>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.1.220/styles/kendo.mobile.all.min.css"/>

    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2019.1.220/js/jszip.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2019.1.220/js/kendo.all.min.js"></script>
</head>
<body>
  
<button id="test">Test</button>
<div id="spreadsheet"></div>
<script>
    $("#spreadsheet").kendoSpreadsheet({
        sheets: [{
            rows: [{
                cells: [{ value: "A" }, { value: "B" }, { value: "C" }]
            }, {
                cells: [{ value: "1" }, { value: "2" }, { value: "3" }]
            }, {
                cells: [{ value: "4" }, { value: "5" }, { value: "6" }]
            }]
        }]
    });
  
    $("#test").click(function(e) {
        var spreadsheet = $("#spreadsheet").data("kendoSpreadsheet");
        alert(spreadsheet.sheets()[0].range("A1:A3").values().join(", "));
    });
</script>
</body>
</html>