docs.sheetjs.com/tests/data/alasql-bun.ps1

45 lines
1.2 KiB
PowerShell
Raw Normal View History

2026-01-29 04:58:19 +00:00
#!/usr/bin/env pwsh
# https://docs.sheetjs.com/docs/demos/data/alasql/#nodejs-example
$oldDir = Get-Location
$tempDir = Join-Path -Path $env:TEMP -ChildPath "sheetjs-alasql"
if (Test-Path -Path $tempDir) { Remove-Item -Path $tempDir -Recurse -Force }
New-Item -ItemType Directory -Path $tempDir | Out-Null
Set-Location -Path $tempDir
@'
{
"overrides": {
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
}
}
'@ | Out-File -FilePath "package.json" -Encoding utf8
bun i --save alasql@3.1.0 https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
Invoke-WebRequest -Uri "https://docs.sheetjs.com/pres.numbers" -OutFile "pres.numbers"
@'
const { promise: alasql } = require("alasql");
(async() => {
/* read data from spreadsheet to JS */
const data = await alasql(`
SELECT \`Name\`, \`Index\`
FROM XLSX("pres.numbers", {autoExt:false})
WHERE \`Index\` < 45
`);
console.log(data);
/* write data from JS to spreadsheet */
data.push({ Name: "SheetJS Dev", Index: 47 });
await alasql(`SELECT * INTO XLSX("SheetJSAlaSQL1.xlsx") FROM ?`, [data]);
})();
'@ | Out-File -FilePath "SheetJSAlaSQL.js" -Encoding utf8
bun run SheetJSAlaSQL.js
bunx xlsx-cli SheetJSAlaSQL1.xlsx
Set-Location $oldDir
Remove-Item -Path $tempDir -Recurse -Force