lyg
2024-08-01 ce8cb9c851fa66c7c2902ceb57e369d3cecf1a28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import xlsx from "node-xlsx";
import * as fs from 'fs';
import * as path from 'path';
 
const EXCEL_FILE = "C:\\Users\\lyg\\Downloads\\book-list2.xlsx"
 
const bookMap = {};
const titleList = [];
const datas = [['Title','Author','Year','Publisher','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 title = row[0];
    const author = row[1]
    const isbn10 = row[2];
    const isbn13 = row[3];
    const isbn = isbn13 || isbn10;
    if (bookMap[isbn]) {
      return;
    }
    datas.push([title, author, 0, null, 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);