[{"id":"747121ac-49bc-471f-bc1f-0133870ee875","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"39c6ef9f-b47f-468b-8a45-04778ad1454f","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"7f774c2b-b28e-41ae-81ac-183442215b95","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"824f32c9-3d2d-4e0c-8bf9-1c2a80cb5f20","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"da48e9e7-aa3e-48e6-885c-24cd573a865c","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"f2c0b7a3-7408-4bd7-9231-25964deea82b","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"c17720a0-f9c9-40e3-9672-26624219e8d5","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"92fb4492-b5b0-45f0-821d-41746aab90d9","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"1070c201-fb4f-43d9-8ed5-44a24a41b94e","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"53c62891-30fd-4a36-b187-4ec844b88209","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"be16fbd7-0143-464b-a141-58ef3d591d2e","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"c1678172-6644-4e8e-9443-5ca0ad3758b8","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"3598d6df-cd0c-4ef5-8960-64cd765d97bc","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"3e535e34-01bb-4774-8d3a-6586619f935c","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"cec9554a-4f21-49e7-af09-6c064d2fd987","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"2c834bb0-6205-410a-91ae-6f244e77ba67","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"7a798f45-e434-41dd-8eec-767f47c93c6e","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"eb1b46dc-ef67-4261-98bb-77796b51f708","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"a219559a-5427-4a48-82ba-7fd4ebc1b4a2","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"f3565254-b7cd-41df-98ff-93802efb8de4","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"fc8628bd-2baa-4986-86f0-93bca5f0ce6a","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"f9fd9204-20b3-4966-ad86-a67eee8df4e2","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"b4333f37-fda5-41c1-bfbb-a8f2f539a682","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"fab5687c-4d05-4bd4-9d18-b14c696f3e9f","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"3ec14a40-47aa-4569-8e84-b575e1f3107e","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"e102b4d6-1235-42bf-9180-b70ba5ed1fc8","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"81df5251-a207-4b22-a3e7-c8e422b68d47","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"fac5f39e-339c-44de-81d6-c98ce52a7d5b","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]},{"id":"6446ae46-3073-40f5-a385-d3c80d4987f1","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"77595f09-3c3a-4bf7-a628-dca3969f8a48","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"6b1c4c88-5cba-4f4c-9cc3-dcf75a4fa444","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"e979ca93-1262-4139-8ae0-e510fcc6f32f","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"3729e0d4-a56c-4e6e-8f9f-f555dd94e1f8","tags":[{"name":"New","color":"Red","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"6c1a6899-1b88-404c-9a73-4a0c6c9090a3"}]},{"id":"f088427d-98d8-4ea0-af40-f8d29c80565d","tags":[{"name":"Upd","color":"Blue","productId":"66a69675-7df9-45b2-867a-4ab2613535fa","links":null,"id":"2f522515-8c88-4017-855d-905bc4b0ea3c"}]}]
        
(Showing Draft Content)

数式の設定

Spread.Sheetsでは、WorksheetクラスのsetFormulaメソッドを使用して、セルに数式を設定できます。 次の図は、さまざまな数式が適用された後の列Bの結果を示しています。

Cell formulas

セルに数式の設定

次のサンプルコードは、セルに数式を設定します。

window.onload = function()
{
   var spread =
   new GC.Spread.Sheets.Workbook(document.getElementById("ss"),
   {sheetCount:3});
   var activeSheet = spread.getActiveSheet();
   activeSheet.setRowCount(5);
   activeSheet.setColumnCount(2);
   activeSheet.getRange(-1, 1, -1, 1)
   .backColor("lightYellow")
   .width(120);
   activeSheet.setValue(0, 0, 10);
   activeSheet.setValue(1, 0, 20);
   activeSheet.setValue(2, 0, 30);
   activeSheet.setValue(3, 0, 40);
   activeSheet.setValue(4, 0, 50);

   // SUM関数を設定します(全パラメータ値を合計)。
   activeSheet.setFormula(0, 1, "SUM(A1:A5)");
 
   // PRODUCT関数を設定します(全パラメータ値を乗算)。
   activeSheet.setFormula(1, 1, "PRODUCT(A1:A5)");

   // AVERAGE関数を設定します(全パラメータ値の平均を計算)。
   activeSheet.setFormula(2, 1, "AVERAGE(A1:A5)");

  // セル(0,0)とセル(4,0)の合計を計算します。
  activeSheet.setFormula(3, 1, "A1 + A5");

  // セル(0,0)の値が10より大きい場合はこの値に2を乗算し、そうでない場合は3を乗算します。
    otherwise multiply it by 3. */
   activeSheet.setFormula(4, 1, "IF(A1>10, A1*2, A1*3)");
}

クロスシート参照の使用

数式内で、他のシートを参照できます。

編集状態を維持したまま数式内で他のシートを参照するには、シートタブまたは [すべてのシート]ボタン(ハンバーガーボタン)から対象シートを選択して、そのシートのセル範囲を選択します。

type=warning

メモ:すべてのシートのリストが表示されているときに、キーボードを使用して数式を入力することはできません。いったんシートの他の領域をクリックしてリストを閉じ、数式の編集状態を終了する必要があります。

次の図に示すように、数学 - 3 年生シートの B5 から F5 の値が、「山田 慎吾」シートの合計スコアを計算するために使用されます。

cross-worksheet-reference

次のサンプルコードは、クロスシート参照を使用します。

window.onload = function () {
    // コンストラクターを呼び出してスプレッドシートを作成します。
    let spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
    initSpread(spread);
};

function initSpread(spread) {
    spread.suspendPaint();
    // テンプレートをロードします。
    spread.fromJSON(template);

    //「山田 慎吾」シートに数式を設定します。
    let sheet = spread.getSheetFromName("山田 慎吾")

    sheet.setText(3,0,"平均スコア:"); 
    sheet.setFormula(3,1,"=Average('数学 - 3 年生'!C5:G5)"); 
    sheet.setText(4,0,"合計"); 
	sheet.setFormula(4,1, "=Sum('数学 - 3 年生'!C5:G5)");

小計の使用

次の図に示すように、SUBTOTAL数式を設定できます。

Subtotals

次のサンプルコードは、小計を計算する数式を使用します。

$(document).ready(function ()
{
    var spread =
    new GC.Spread.Sheets.Workbook(document.getElementById("ss"),
    {sheetCount:3});
   
    var activeSheet = spread.getActiveSheet();
    activeSheet.setColumnCount(2);
    activeSheet.options.colHeaderAutoText = GC.Spread.Sheets.HeaderAutoText.blank;
    activeSheet.setText(0, 1, "Value", GC.Spread.Sheets.SheetArea.colHeader);
    activeSheet.options.gridline = {showHorizontalGridline: false};
    activeSheet.setText(3, 0, "Sub-Total1");
    activeSheet.setText(7, 0, "Sub-Total2");
    activeSheet.setText(8, 0, "Aggregate");
    activeSheet.getRange(3, -1, 1, -1).backColor("lemonChiffon");
    activeSheet.getRange(7, -1, 1, -1).backColor("lemonChiffon");
    activeSheet.getRange(8, -1, 1, -1).backColor("lightPink");
    activeSheet.setValue(0, 1, 100);
    activeSheet.setValue(1, 1, 200);
    activeSheet.setValue(2, 1, 300);
    activeSheet.setValue(4, 1, 400);
    activeSheet.setValue(5, 1, 500);
    activeSheet.setValue(6, 1, 600);
  
   // SUBTOTAL関数を使用して、小計と総計を設定します。
   activeSheet.setFormula(3, 1, "SUBTOTAL(9,B1:B3)");
   activeSheet.setFormula(7, 1, "SUBTOTAL(9,B5:B7)");
   activeSheet.setFormula(8, 1, "SUBTOTAL(9,B1:B7)");
});