ワークブックのオプションで反復計算を有効/無効にすることができます。
反復計算を無効にすると、すべての循環参照のセルは値が0になり、それらを参照しているその他のセルも0になります。
反復計算を有効にすると、すべての循環参照は、値の変化量が iterativeCalculationMaximumChange より小さくなるか、または反復回数が iterativeCalculationMaximumIterations になるまで反復計算を行います。
APIは以下の通りです。
iterativeCalculation: 反復計算を有効または無効にします。
iterativeCalculationMaximumIterations: 反復計算時の最大反復回数。デフォルト値は1000。値の範囲は1〜32767です。
iterativeCalculationMaximumChange: 反復計算時の最大変化量。デフォルトは0.01。値の範囲は0~MaxDouble(1.79769313486232e308)です。
isCircularReference プロパティが Events.UserFormulaEntered イベントの引数に追加されました。ユーザーが循環参照を入力した場合は trueになります。
以下のように、ワークブック内のすべての循環参照は、getCircularReference メソッドで取得できます。
window.onload = function () {
var spread = new GC.Spread.Sheets.Workbook(_getElementById("ss"));
initSpread(spread);
};
function initSpread(spread) {
var sheet = spread.getActiveSheet();
spread.suspendPaint();
spread.suspendCalcService();
sheet.setColumnWidth(1, 130);
sheet.setColumnWidth(2, 120);
sheet.getCell(2, 3).foreColor("blue");
sheet.getCell(6, 3).foreColor("blue");
sheet.getCell(10, 3).foreColor("blue").formatter("0.0%");
sheet.getRange(2, 3, 7, 1).formatter("0.0");
sheet.setFormula(0, 0, '=A1+1');
sheet.setValue(2, 2, "Cash Revenue");
sheet.setValue(3, 2, "Interest Expense");
sheet.setValue(4, 2, "Cash Profit");
sheet.setValue(6, 2, "Beginning Debt");
sheet.setValue(7, 2, "Ending Debt");
sheet.setValue(8, 2, "Average Debt");
sheet.setValue(10, 2, "Interest");
sheet.setValue(2, 3, 100);
sheet.setFormula(3, 3, '=D11*D9');
sheet.setFormula(4, 3, '=D3-D4');
sheet.setValue(6, 3, 150);
sheet.setFormula(7, 3, '=D7-D5');
sheet.setFormula(8, 3, '=AVERAGE(D7:D8)');
sheet.setValue(10, 3, 0.05);
sheet.setFormula(3, 4, '=FORMULATEXT(D4)');
sheet.setFormula(4, 4, '=FORMULATEXT(D5)');
sheet.setFormula(7, 4, '=FORMULATEXT(D8)');
sheet.setFormula(8, 4, '=FORMULATEXT(D9)');
sheet.setValue(16, 1, "Use the Leibniz formula to approximate π")
sheet.setValue(17, 1, "n: 1→∞")
sheet.setValue(18, 1, {"richText":[{"text":"Pn: 4*(-1)"},{"style":{"vertAlign":1},"text":"n+1"},{"text":"/(2n-1)"}],"text":"Pn=4*(-1)n+1/(2n-1)"});
sheet.setValue(19, 1, "π: P1+P2+P3+...+Pn")
sheet.setFormula(19, 2, '=IFERROR(C19,0)+C20');
sheet.setFormula(18, 2, '=IF(C18<1,0,4/(2*C18-1)*POWER(-1,C18+1))');
sheet.setFormula(17, 2, '=C18+1'); // set the n in the last to make sure that added from n=1
spread.resumeCalcService();
spread.resumePaint();
bindEvent(spread);
}
function bindEvent (spread) {
_getElementById("IterativeCalculation").addEventListener('change', function () {
spread.options.iterativeCalculation = this.checked;
});
_getElementById("MaximumIterations").addEventListener('change', function () {
spread.options.iterativeCalculationMaximumIterations = this.value;
});
_getElementById("MaximumChange").addEventListener('change', function () {
spread.options.iterativeCalculationMaximumChange = this.value;
});
_getElementById("RecalcAll").addEventListener('click', function () {
spread.getActiveSheet().recalcAll(true);
});
}
function _getElementById(id) {
return document.getElementById(id);
}
<!doctype html>
<html style="height:100%;font-size:14px;">
<head>
<meta charset="utf-8" />
<meta name="spreadjs culture" content="ja-jp" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
<script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.min.js" type="text/javascript"></script>
<script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
<script src="app.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div class="sample-tutorial">
<div id="ss" class="sample-spreadsheets"></div>
<div class="options-container">
<div class="option-row">
<input style="width: 20px;float: left;" type="checkbox" id="IterativeCalculation" checked="checked"/>
<label for="IterativeCalculation">反復計算を行う</label>
</div>
<div class="option-row">
<label for="MaximumIterations">最大反復回数:</label>
<input type="number" id="MaximumIterations" value="1000">
</div>
<div class="option-row">
<label for="MaximumChange">変化の最大値:</label>
<input type="number" id="MaximumChange" value="0.01">
</div>
<div class="option-row">
<button id="RecalcAll">再計算</button>
</div>
</div>
</div></body>
</html>
.sample-tutorial {
position: relative;
height: 100%;
overflow: hidden;
}
.sample-spreadsheets {
width: calc(100% - 280px);
height: 100%;
overflow: hidden;
float: left;
}
.options-container {
float: right;
width: 280px;
padding: 12px;
height: 100%;
box-sizing: border-box;
background: #fbfbfb;
overflow: auto;
}
.option-row {
font-size: 14px;
padding: 5px;
margin-top: 10px;
}
input {
margin-bottom: 5px;
padding: 2px 4px;
width: 100%;
box-sizing: border-box;
}
body {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}