45 lines
1.2 KiB
PowerShell
45 lines
1.2 KiB
PowerShell
#!/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
|
|
|
|
npm 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
|
|
|
|
node SheetJSAlaSQL.js
|
|
|
|
npx xlsx-cli SheetJSAlaSQL1.xlsx
|
|
|
|
Set-Location $oldDir
|
|
Remove-Item -Path $tempDir -Recurse -Force |