docs.sheetjs.com/tests/dom-jsdom.sh

37 lines
907 B
Bash
Executable File

#!/bin/bash
# https://docs.sheetjs.com/docs/demos/net/dom#jsdom
cd /tmp
rm -rf sheetjs-jsdom
mkdir sheetjs-jsdom
cd sheetjs-jsdom
npm i --save https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz
cat >SheetJSDOM.js <<EOF
const XLSX = require("xlsx");
const { readFileSync } = require("fs");
const { JSDOM } = require("jsdom");
/* obtain HTML string. This example reads from SheetJSTable.html */
const html_str = readFileSync("SheetJSTable.html", "utf8");
/* get first TABLE element */
const doc = new JSDOM(html_str).window.document.querySelector("table");
/* generate workbook */
const workbook = XLSX.utils.table_to_book(doc);
XLSX.writeFile(workbook, "SheetJSDOM.xlsx");
EOF
curl -LO https://docs.sheetjs.com/dom/SheetJSTable.html
for n in {10..24}; do
rm -f SheetJSDom.xlsx
npm i --save jsdom@$n
npm ls | grep jsdom
node SheetJSDom.js
npx -y xlsx-cli SheetJSDom.xlsx | head -n 3
done