12345678910111213141516171819 |
- const xlsx = require('xlsx');
- const fs = require('fs');
- const path = require('path');
- // 读取 Excel 文件
- const workbook = xlsx.readFile(path.join(__dirname, '/xlsx/核心素养-小班上.xlsx'));
- // 获取第一个工作表
- const sheetName = workbook.SheetNames[0];
- const worksheet = workbook.Sheets[sheetName];
- // 将工作表转换为 JSON 对象
- const json = xlsx.utils.sheet_to_json(worksheet);
- // 将 JSON 对象写入文件(可选)
- fs.writeFileSync('output.json', JSON.stringify(json, null, 2));
- // 打印 JSON 数据
- console.log(json);
|