Convert spreadsheets from Excel, Numbers, CSV, TSV or other tabular format to JSON. A separate JSON object is output for each sheet.
import { read, utils } from "https://cdn.jsdelivr.net/npm/xlsx@0.18.5/+esm"
export const take = [
{ type: "file", label: "Spreadsheet", read: "buffer" },
{
type: "dropdown",
label: "Format",
options: [
{ label: "Use keys from first row" },
{ label: "Use column names for keys", value: "A" },
{ label: "Use nested arrays with no keys", value: 1 },
],
},
{
type: "toggle",
label: "Extract raw values",
detail: "Use raw values, rather than formatted strings.",
value: true,
},
]
export const make = ([arrayBuffer, header, raw]) => {
if (arrayBuffer) {
const value = read(arrayBuffer)
const opts = {
raw,
header,
}
return Object.entries(value.Sheets).map(([label, sheet]) => {
return { type: "json", label, value: utils.sheet_to_json(sheet, opts) }
})
}
}