From 3e90d357f7107b61321b53c8c5fd58b8946fc124 Mon Sep 17 00:00:00 2001
From: lyg <1543117173@qq.com>
Date: 星期五, 19 七月 2024 11:13:37 +0800
Subject: [PATCH] Excel合并

---
 src/excel-merge.mjs |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/src/excel-merge.mjs b/src/excel-merge.mjs
new file mode 100644
index 0000000..26ce284
--- /dev/null
+++ b/src/excel-merge.mjs
@@ -0,0 +1,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);
\ No newline at end of file

--
Gitblit v1.9.1