All examples
advanced
Batch convert a directory
Walk a folder and emit JSON for every spreadsheet.
A Node.js script that scans a directory, converts each supported file to JSON, and writes the result alongside.
js
import fs from 'node:fs/promises';
import path from 'node:path';
import tabularjs from 'tabularjs';
const SUPPORTED = /\.(xlsx?|ods|csv|tsv|dbf|xml|slk|dif|wk[1-4s])$/i;
async function walk(dir) {
for (const entry of await fs.readdir(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) await walk(full);
else if (SUPPORTED.test(entry.name)) {
const result = await tabularjs(full);
await fs.writeFile(full + '.json', JSON.stringify(result, null, 2));
console.log('wrote', full + '.json');
}
}
}
walk(process.argv[2] || '.');Live Preview
Sample output for a file with employee data.
stdout
{
"worksheets": [
{
"name": "Sheet1",
"data": [
["Name", "Department", "Salary", "Start Date"],
["Alice Johnson", "Engineering", 95000, "2021-03-15"],
["Bob Smith", "Marketing", 72000, "2022-01-10"],
["Carol Williams", "Engineering", 88000, "2020-07-22"],
["David Brown", "Design", 68000, "2023-02-08"],
["Eve Davis", "Engineering", 102000, "2019-11-30"]
]
}
]
}
