import xlsx from "node-xlsx";
|
import * as fs from 'fs';
|
import * as path from 'path';
|
|
const EXCEL_FILE = "C:\\Users\\lyg\\Downloads\\book-list3.xlsx"
|
|
const bookMap = {};
|
const titleList = [];
|
const datas = [['id', 'Title', 'Author', 'ISBN']];
|
const dir = "C:\\Users\\lyg\\Downloads\\booklist";
|
// 获取所有日志文件
|
const files = fs.readdirSync(dir, { withFileTypes: true });
|
// 遍历日志文件
|
for (const file of files) {
|
const workSheets = xlsx.parse(path.join(dir, file.name));
|
const sheet = workSheets[0];
|
sheet.data.shift();
|
sheet.data.forEach((row) => {
|
const id = row[0];
|
const title = row[1];
|
const author = row[2]
|
const isbn = row[3];
|
if (bookMap[isbn]) {
|
return;
|
}
|
datas.push([id, title, author, isbn]);
|
bookMap[isbn] = 1;
|
titleList.push(title);
|
});
|
}
|
|
const buffer = xlsx.build([{ name: "Sheet1", data: datas }]);
|
fs.writeFileSync(EXCEL_FILE, buffer, (err) => { });
|
console.log("保存完成: ", EXCEL_FILE);
|