Appearance
CDN
引用外部文件。
document.getElementById("run").addEventListener("click", run);
async function run() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getActiveWorksheet();
const data = [
{ a: 1, b: 10 },
{ a: 2, b: 20 },
{ a: 1, b: 30 },
{ a: 1, b: 40 },
{ a: 3, b: 50 },
];
const result = alasql("SELECT a, SUM(b) AS b FROM ? GROUP BY a", [data]).map(x => [x.a, x.b]);
sheet.getRange("A1").getResizedRange(result.length - 1, 1).values = result;
await context.sync();
});
}<button id="run">Run</button>https://appsforoffice.microsoft.com/lib/1/hosted/office.js
https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts
https://cdn.jsdelivr.net/npm/alasql@latest/dist/alasql.min.js| A | B |
|---|---|
| 1 | 80 |
| 2 | 20 |
| 3 | 50 |