AI支援による数式生成と数式の説明

このデモでは、SpreadJS内で数式を生成・説明するAI機能を紹介します。

新しいウィンドウでデモを開くとデザイナーが開きます このデモでは、数式の作成と解析を簡素化するために設計された、AI支援による数式生成・説明機能を紹介します。 この機能には以下が含まれます: AI数式生成: 「金額の合計」や「売上の平均」などのユーザー入力やコンテキストに基づいて、自動的に数式を生成します。 数式の説明: 生成された数式や既存の数式について、ユーザーがそのロジックと応用を理解できるように、順を追って詳細な説明を提供します。 使用方法: 数式エディターパネルの右下にある「」ボタンをクリックすると、「スマート数式生成」パネルが表示されます。 必要な数式についての要件を入力します(例:「テーブル'table1'には各営業担当者の売上データが含まれています。営業担当者ごとの売上を合計し、最も売上の高い営業担当者を表示する数式を作成してください。」)。 「」ボタンをクリックすると、入力内容に合わせてAIが提案する数式を受け取ることができます。 数式を確認し、スプレッドシートに適用します。 数式エディターパネル内の任意の数式について、「」ボタンをクリックすると、AIが数式を分析し、その仕組みの詳細な説明を取得することができます。 この機能により、スプレッドシートの専門知識の有無に関わらず、ユーザーはより効率的に数式を操作できるようになります。 AIが提供する情報や提案をご利用の際は、内容の正確性や適切性を十分にご確認いただき、ご自身の判断と責任のもとでご利用ください。
let designer, spread; window.onload = function () { const spread = createSpreadAndDesigner(); injectAI(spread); initData(spread); }; function initData(spread) { spread.suspendPaint(); spread.options.allowDynamicArray = true; var sheet = spread.sheets[0]; sheet.setValue(0, 0, "Grade"); sheet.setValue(0, 6, 72); sheet.setFormula( 0, 1, '=LET(score, G1, IF(score >= 90, "A", IF(score >= 80, "B", IF(score >= 70, "C", IF(score >= 60, "D", "F")))))' ); sheet.setValue(1, 0, "Most Frequent"); sheet.setArray(1, 6, [[1, 2, 6, 6, 6, 5]]); sheet.setFormula( 1, 1, '=LET(data, G2:L2, unique_data, UNIQUE(data), count_data, COUNTIF(data, unique_data), max_count, MAX(count_data), most_frequent, INDEX(unique_data, MATCH(max_count, count_data, 0)), IF(max_count > 1, most_frequent, ""))' ); sheet.setValue(2, 0, "GUID"); sheet.setFormula( 2, 1, '=CONCATENATE(DEC2HEX(RANDBETWEEN(0, 4294967295), 8), "-", DEC2HEX(RANDBETWEEN(0, 65535), 4), "-", DEC2HEX(RANDBETWEEN(16384, 20479), 4), "-", DEC2HEX(RANDBETWEEN(32768, 49151), 4), "-", DEC2HEX(RANDBETWEEN(0, 65535), 4), DEC2HEX(RANDBETWEEN(0, 4294967295), 8))' ); sheet.setActiveCell(0, 1); const showDesigner = top === window; if (!showDesigner) { document.getElementById("location").innerText = "Sheet1>B1"; } sheet.setColumnWidth(0, 100); const dataSource = [ ["name", "product", "date", "amount", "price", "sales"], ["chris", "desk", new Date("2020-10-08T16:00:00.000Z"), 5, 199, 995], ["radow", "pen", new Date("2020-09-15T16:00:00.000Z"), 2, 5, 10], ["peyton", "pencil", new Date("2021-06-22T16:00:00.000Z"), 6, 1.5, 9], ["johnson", "chair", new Date("2021-07-19T16:00:00.000Z"), 7, 68, 476], ["vic", "notebook", new Date("2021-01-13T16:00:00.000Z"), 7, 3.2, 22.4], ["lan", "desk", new Date("2021-03-12T16:00:00.000Z"), 9, 199, 1791], ["chris", "pen", new Date("2021-03-06T16:00:00.000Z"), 4, 5, 20], ["chris", "pencil", new Date("2020-09-02T16:00:00.000Z"), 10, 1.5, 15], ["radow", "chair", new Date("2020-08-09T16:00:00.000Z"), 3, 68, 204], ["peyton", "notebook", new Date("2021-02-08T16:00:00.000Z"), 9, 3.2, 28.8], ["johnson", "desk", new Date("2021-07-03T16:00:00.000Z"), 7, 199, 1393], ["vic", "pen", new Date("2021-06-27T16:00:00.000Z"), 8, 5, 40], ["lan", "pencil", new Date("2020-10-10T16:00:00.000Z"), 2, 1.5, 3], ["chris", "chair", new Date("2021-03-04T16:00:00.000Z"), 2, 68, 136], ["chris", "notebook", new Date("2021-02-21T16:00:00.000Z"), 11, 3.2, 35.2], ["radow", "desk", new Date("2021-06-03T16:00:00.000Z"), 6, 199, 1194], ]; sheet.setArray(5, 0, dataSource); sheet.tables.add("table1", 5, 0, 17, 6); spread.resumePaint(); } function createSpreadAndDesigner() { const demoHost = document.getElementById("demo-host"); if (window !== top) { const spread = new GC.Spread.Sheets.Workbook(demoHost, { sheetCount: 1 }); const formulaEditor = new GC.Spread.Sheets.FormulaPanel.FormulaEditor( document.getElementById("editor") ); formulaEditor.attach(spread); const save_btn = document.getElementById("save"); save_btn.addEventListener("click", () => { formulaEditor .commandManager() .execute({ cmd: "commitContentToActiveCell" }); }); const location = document.getElementById("location"); spread.bind("ActiveCellChanged", (eventType, args) => { location.innerText = `${spread.getActiveSheet().name()}>${toColumnIndex( args.col )}${args.row + 1}`; }); return spread; } else { const designer = new GC.Spread.Sheets.Designer.Designer( demoHost, undefined, undefined, { sheetCount: 1 } ); const panel = document.getElementById("panel"); panel.style.display = "none"; designer.setData("formulaEditorPanel_Visible", true); return designer.getWorkbook(); } } function toColumnIndex(index) { let column = ""; while (index >= 0) { column = String.fromCharCode((index % 26) + 65) + column; index = Math.floor(index / 26) - 1; } return column; } function injectAI(spread) { const serverCallback = async (requestBody) => { const response = await fetch(getAIApiUrl(), { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody) }); if (response.status === 429) { alert('The server is busy, please try again later.'); return; } if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return response; }; spread.injectAI(serverCallback); } function getAIApiUrl() { return ( window.location.href.match(/http.+spreadjs\/demos\//)[0] + "server/api/queryAI" ); }
<!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" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-designer/styles/gc.spread.sheets.designer.light.min.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-formula-panel/dist/gc.spread.sheets.formulapanel.min.js" type="text/javascript" ></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-ai-addon/dist/gc.spread.sheets.ai.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> const designerDependencyScripts = [ "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-barcode/dist/gc.spread.sheets.barcode.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-shapes/dist/gc.spread.sheets.shapes.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-charts/dist/gc.spread.sheets.charts.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-print/dist/gc.spread.sheets.print.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-pdf/dist/gc.spread.sheets.pdf.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-pivot-addon/dist/gc.spread.pivot.pivottables.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-slicers/dist/gc.spread.sheets.slicers.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-tablesheet/dist/gc.spread.sheets.tablesheet.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-ganttsheet/dist/gc.spread.sheets.ganttsheet.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-reportsheet-addon/dist/gc.spread.report.reportsheet.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-io/dist/gc.spread.sheets.io.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-designer-resources-ja/dist/gc.spread.sheets.designer.resource.ja.min.js", "$DEMOROOT$/ja/purejs/node_modules/@mescius/spread-sheets-designer/dist/gc.spread.sheets.designer.all.min.js", "$DEMOROOT$/spread/source/js/designer/license.js", ]; function appendScriptNode(src) { const script = document.createElement("script"); script.src = src; script.async = false; script.type = "text/javascript"; document.head.appendChild(script); } if (top === window) { // not in iframe designerDependencyScripts.forEach(appendScriptNode); } </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="demo-host"></div> <div id="panel"> <div id="header"> <div id="save"></div> <div id="location"></div> </div> <div id="editor"></div> </div> </div> </body> </html>
body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; } .sample-tutorial { position: relative; height: 100%; overflow: hidden; display: flex; flex-direction: row; } #demo-host { width: 69vw; height: 100%; flex-grow: 1; } #panel { margin-left: 10px; width: 30vw; display: flex; flex-direction: column; } #header { display: flex; flex-direction: row; justify-content: flex-start; align-items: center; } #save { margin-left: 7px; height: 30px; width: 30px; cursor: pointer; background-position: center; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNiIgaGVpZ2h0PSIyNiI+PGcgZmlsbD0iIzY5Njk2OSIgZmlsbC1ydWxlPSJub256ZXJvIj48cGF0aCBzdHJva2U9IiM2NjYiIHN0cm9rZS13aWR0aD0iLjciIGQ9Ik0xMC44NzIgMnEuNTgyIDAgLjkzNS4yOS4zNTUuMjg4LjM1NC42MjQtLjAwMS4yNy0uMTc2LjQ0N2EuNjIuNjIgMCAwIDEtLjQ1NC4xNzcuNTcuNTcgMCAwIDEtLjM5Mi0uMTM0LjQyLjQyIDAgMCAxLS4xNTMtLjMyM3EwLS4xMi4xMDEtLjI5OS4xLS4xNzUuMS0uMjMzYS4yLjIgMCAwIDAtLjA2Ni0uMTU4cS0uMDk2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jcuMTI5YTQuOCA0LjggMCAwIDEtMS4yMzMgMS40NzRxLS40Mi4zMjYtLjcxNS4zMjYtLjQzLjAwMS0uNjg4LS40NjYtLjE2Mi0uMjk3LS42Ny0yLjUyOC0xLjE5MyAyLjAzNS0xLjkxOCAyLjYyLS40NjguMzc0LS45MDcuMzc0YS44Ni44NiAwIDAgMS0uNTY0LS4yMTUuNTguNTggMCAwIDEtLjE4Mi0uNDQ4LjU2OC41NjggMCAwIDEgLjU4My0uNTc3cS4yNDggMCAuNTI2LjI0My4yLjE3Ni4zMDUuMTc2LjA5NSAwIC4yMzktLjEyLjM2My0uMjkuOTgzLTEuMjM3LjYyLS45NDYuODEzLTEuMzY2YTEwMCAxMDAgMCAwIDAtLjUwNy0xLjkzMmMtLjEyMi0uMzItLjI3Ny0uNTUyLS40NjgtLjY4NXEtLjI4Ny0uMi0uODMxLS4xOTktLjE4MSAwLS40MS4wMDl2LS4yNzFsMi4wNTQtLjM1M3EuMzcuMzkxLjU2My43ODMuMTQyLjI3LjQ1OCAxLjQxOGwuNjc3LS45ODlxLjI2OS0uMzY0LjY1LS42OS4zODItLjMyOC42NzktLjQzOGEuOTYuOTYgMCAwIDEgLjQxLS4wODRaIi8+PHBhdGggZD0ibTExLjcxMiAyNS4yNi0uNjE3LS42MDdMNCAxOC43MjZsMS40NDItMS40ODYgNi4yNyA1LjE1NUwyMy42NiAxMCAyNSAxMS4yMzYgMTIuMzAxIDI0LjY1MyIvPjwvZz48L3N2Zz4=); } #save:hover { transform: scale(1.1); } #location { margin-left: 12px; line-height: 30px; font-size: 18px; } #editor { height: calc(100% - 30px); }