Spread.Sheets
setAsyncResult メソッド
非同期関数の評価結果。
非同期関数の評価結果をCalcEngineに設定します。CalcEngineはこの値を使用して、この非同期関数を含むセルとすべての依存セルを再計算します。
シンタックス
Javascript (Usage) 
var instance = new GC.Spread.CalcEngine.AsyncEvaluateContext(context);
var returnValue; // Type: any
returnValue = instance.setAsyncResult(value);
Javascript (Specification) 
function setAsyncResult( 
   value : object
) : any;

パラメータ

value
非同期関数の評価結果。
使用例
次のサンプルコードは、refresh数式を使用します。
<!DOCTYPE html>
<html>
<head>
    <title>Spread.Sheets</title>
<link href="./css/gc.spread.sheets.11.0.0.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./scripts/gc.spread.sheets.all.11.0.0.min.js"></script>
<!--jQuery References-->
<script src="http://code.jquery.com/jquery-2.0.2.js" type="text/javascript"></script>

  <script type="text/javascript">
                                window.onload = function(){
            var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});                                           
            var sheet = spread.getActiveSheet();

            var GetNumberFromServer = function () {
            }
            GetNumberFromServer.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("GETNUMBERFROMSERVER", 2, 2);
            GetNumberFromServer.prototype.evaluate = function (context, arg1, arg2) {
                var self = this;
                $.get('http://xa-tools-shdev/asyncfunction/api/values/' + (arg1 || 1), function (value) {
                    context.setAsyncResult(value);
                });
            }

            GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETNUMBERFROMSERVER", new GetNumberFromServer());
            sheet.setValue(0, 0, 'ChangeValue');
            sheet.setValue(0, 1, 'Formula');
            sheet.setValue(0, 2, 'Result');
            sheet.setValue(0, 3, 'Comments');
            sheet.setValue(1, 3, 'On A2 changed');
            sheet.setValue(2, 3, 'On A2 changed');
            sheet.setValue(3, 3, 'Evaluate once');
            sheet.setValue(4, 3, 'Every 2 seconds');
            sheet.setValue(1, 0, 1);
            sheet.setValue(1, 1, '=GetNumberFromServer(A2)');
            sheet.setValue(2, 1, '=Refresh(GetNumberFromServer(A2), 0)');
            sheet.setValue(3, 1, '=Refresh(GetNumberFromServer(A2), 1)');
            sheet.setValue(4, 1, '=Refresh(GetNumberFromServer(A2), 2, 2000)');
            sheet.setFormula(1, 2, '=GetNumberFromServer(A2)');
            sheet.setFormula(2, 2, '=Refresh(GetNumberFromServer(A2), 0)');
            sheet.setFormula(3, 2, '=Refresh(GetNumberFromServer(A2), 1)');
            sheet.setFormula(4, 2, '=Refresh(GetNumberFromServer(A2), 2, 2000)');
            sheet.setColumnWidth(0, 100);
            sheet.setColumnWidth(1, 300);
            sheet.setColumnWidth(2, 200);
            sheet.setColumnWidth(3, 200);
            sheet.setValue(7, 1, "=Refresh(now(), 2, 1000)");
            sheet.setValue(7, 3, "Every 1 seconds");
            sheet.setFormula(7, 2, "=Refresh(now(), 2, 1000)");

            var GetTimeFromServer = function () {
            }
            GetTimeFromServer.prototype = new GC.Spread.CalcEngine.Functions.AsyncFunction("GETTIMEFROMSERVER", 2, 2);
            GetTimeFromServer.prototype.evaluate = function (context) {
                $.get('http://xa-tools-shdev/asyncfunction/api/time/', function (value) {
                    context.setAsyncResult(value);
                });
            }
            GetTimeFromServer.prototype.evaluateMode = function () {
                return 2;
            };
            GetTimeFromServer.prototype.interval = function () {
                return 1000;
            };

            GC.Spread.CalcEngine.Functions.defineGlobalCustomFunction("GETTIMEFROMSERVER", new GetTimeFromServer());
            sheet.setValue(10, 1, "=GetTimeFromServer()");
            sheet.setValue(10, 3, "Every 1 seconds");
            sheet.setFormula(10, 2, "=GetTimeFromServer()");
            sheet.getCell(10, 2).hAlign(GC.Spread.Sheets.HorizontalAlign.right);
}
</script>
</head>
<body>
    <div id="ss" style="width:100%;height:500px;border:1px solid gray"></div>
</body>
</html>

関連トピック

参照

AsyncEvaluateContext タイプ

 

 


© 2016-2018, GrapeCity inc. All rights reserved.