BYCOL関数

各列にLAMBDA関数を適用し、その結果の配列を返します。例として、元の配列が3列×2行の場合、返される配列は3列×1行となります。

構文 BYCOL関数の構文には、以下の引数とパラメータがあります: array 列で区切られた配列。 lambda 唯一のパラメータとして列を受け取り、結果を計算するLAMBDA関数です。LAMBDA関数は1つのパラメータをとります: column 配列に含まれる列。 ヒント この関数を使用する前に、allowDynamicArray オプションを有効にする必要があります。 基本的な使い方 各列の最大値を返します。
var data = { values: { 1: { 1: "例" }, 3: { 1: "例1: 各列の最大値を返します" }, 4: { 1: "データ:", 5: "数式:" }, 5: { 1: 1, 2: 2, 3: 3, 5: "結果:" }, 6: { 1: 4, 2: 5, 3: 6 }, 8: { 1: "例2: 配列の要素を2乗した値の合計を返します" }, 9: { 1: "データ:", 5: "数式:" }, 10: { 1: 1, 2: 2, 3: 3, 5: "結果:" }, 11: { 1: 4, 2: 5, 3: 6 }, }, formulas: { 4: { 6: "FORMULATEXT(G6)" }, 5: { 6: "BYCOL(B6:D7,LAMBDA(array,MAX(array)))" }, 9: { 6: "FORMULATEXT(G11)" }, 10: { 6: "BYCOL(B11:D12,LAMBDA(array,SUMSQ(array)))" }, }, cellStyles: { "B2:C2": 0, "B4:G4": 1, B5: 2, C5: 3, D5: 4, F5: 5, "G5:I6": 6, "J5:K5": 6, "B6:D7": 7, F6: 8, "B9:J9": 1, B10: 2, C10: 3, D10: 4, F10: 5, "G10:I11": 6, "J10:K10": 6, "B11:D12": 7, F11: 8, }, styles: { records: [ { foreColor: 0, font: 0, border: [null, null, 0] }, { foreColor: 0, font: 1, border: [null, null, 1] }, { backColor: 2, foreColor: 1, font: 1, border: [null, null, 2, 3] }, { backColor: 2, foreColor: 1, font: 1, border: [4, null, 2] }, { backColor: 2, foreColor: 1, font: 1, border: [4, 3, 2] }, { backColor: 2, foreColor: 1, font: 1, border: [3, 2, 3, 3] }, { backColor: 4, foreColor: 3, font: 1, border: [2, 2, 2, 2] }, { backColor: 6, foreColor: 5, border: [2, 2, 2, 2] }, { backColor: 2, foreColor: 1, font: 1, border: [3, 3, 3, 3] }, ], borders: [ { color: "#accdea", style: 5 }, { color: "#9bc3e6", style: 2 }, { color: "#7f7f7f", style: 1 }, { color: "#9bc3e6", style: 1 }, { color: "#000000", style: 1 }, ], colors: ["#44546a", "#ffffff", "#5b9bd5", "#fa7d00", "#f2f2f2", "#3f3f76", "#ffcc99"], fonts: ["700 17.3px Calibri", "700 14.7px Calibri"], }, others: { columnWidth: { 0: 30 }, rowHeight: { 1: 24, 2: 21, 3: 21, 8: 21 }, spans: ["B5:D5", "B10:D10"], }, }; window.onload = function () { var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss")); workbook.options.allowDynamicArray = true; workbook.suspendPaint(); initSheet1(workbook.getSheet(0)); workbook.resumePaint(); }; function initSheet1(sheet) { setSheetPr(sheet); setCells(sheet); } function setCells(sheet) { foreachObj(data.values, function (r, row) { foreachObj(row, function (c, v) { setValue(sheet, Number(r), Number(c), v); }); }); foreachObj(data.formulas, function (r, row) { foreachObj(row, function (c, v) { setFormula(sheet, Number(r), Number(c), v); }); }); foreachObj(data.cellStyles, function (ref, id) { setStyle(sheet, ref, data.styles.records[id]); }); } function setValue(sheet, r, c, v) { if (v === undefined || v === null) return; sheet.setValue(r, c, v); } function setFormula(sheet, r, c, v) { if (v === undefined || v === null) return; sheet.setFormula(r, c, v); } function setStyle(sheet, ref, v) { if (v === undefined || v === null) return; var styles = data.styles; var range = sheet.getRange(ref); var foreColor = styles.colors[v.foreColor]; var backColor = styles.colors[v.backColor]; var font = styles.fonts[v.font]; var wordWrap = v.wordWrap; if (foreColor) { range.foreColor(foreColor); } if (backColor) { range.backColor(backColor); } if (font) { range.font(font); } if (wordWrap) { range.wordWrap(wordWrap); } var border = v.border || []; var borderTop = styles.borders[border[0]]; var borderRight = styles.borders[border[1]]; var borderBottom = styles.borders[border[2]]; var borderLeft = styles.borders[border[3]]; if (borderTop) { range.borderTop(createLineStyle(borderTop)); } if (borderBottom) { range.borderBottom(createLineStyle(borderBottom)); } if (borderLeft) { range.borderLeft(createLineStyle(borderLeft)); } if (borderRight) { range.borderRight(createLineStyle(borderRight)); } } function setSheetPr(sheet) { // set column width foreachObj(data.others.columnWidth, function (index, v) { sheet.setColumnWidth(Number(index), v); }); // set row height foreachObj(data.others.rowHeight, function (index, v) { sheet.setRowHeight(Number(index), v); }); // set spans var spans = data.others.spans || []; for (var i = 0; i < spans.length; i++) { var range = sheet.getRange(spans[i]); sheet.addSpan(range.row, range.col, range.rowCount, range.colCount); } } function createLineStyle(v) { return new GC.Spread.Sheets.LineBorder(v.color, v.style); } function foreachObj(obj, func) { if (!obj) return; var keys = Object.keys(obj); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var v = obj[key]; func(key, v); } }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/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> </body> </html>
input[type="text"] { width: 200px; margin-right: 20px; } label { display: inline-block; width: 110px; } .sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: 100%; height: 100%; overflow: hidden; float: left; } label { display: block; margin-bottom: 6px; } input { padding: 4px 6px; } input[type=button] { margin-top: 6px; display: block; width:216px; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } code { border: 1px solid #000; }