年度总结页面
This commit is contained in:
30
public/res/year-statistic/data/read-excel.js
Normal file
30
public/res/year-statistic/data/read-excel.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const XLSX = require('xlsx');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
// Excel文件路径
|
||||
const excelPath = 'C:\\Users\\chenhaid\\Documents\\WXWork\\1688858118476511\\Cache\\File\\2026-02\\供应商年度KPIv5.xlsx';
|
||||
|
||||
// 输出JSON文件路径
|
||||
const outputPath = path.join(__dirname, 'kpi.json');
|
||||
|
||||
// 读取Excel文件
|
||||
const workbook = XLSX.readFile(excelPath);
|
||||
|
||||
// 获取第一个工作表名称
|
||||
const sheetName = workbook.SheetNames[0];
|
||||
console.log('工作表列表:', workbook.SheetNames);
|
||||
|
||||
// 获取工作表
|
||||
const worksheet = workbook.Sheets[sheetName];
|
||||
|
||||
// 转换为JSON
|
||||
const jsonData = XLSX.utils.sheet_to_json(worksheet);
|
||||
|
||||
console.log('读取到', jsonData.length, '条数据');
|
||||
console.log('第一条数据示例:', JSON.stringify(jsonData[0], null, 2));
|
||||
|
||||
// 写入JSON文件
|
||||
fs.writeFileSync(outputPath, JSON.stringify(jsonData, null, 2), 'utf8');
|
||||
|
||||
console.log('已保存到:', outputPath);
|
||||
Reference in New Issue
Block a user