This commit is contained in:
cheney
2026-07-25 20:53:20 +08:00
parent 11451aac40
commit 477914858b
2 changed files with 191 additions and 0 deletions
+26
View File
@@ -50,6 +50,28 @@ function sheetToRows(sheet) {
return XLSX.utils.sheet_to_json(sheet, { header: 1, defval: null, blankrows: false });
}
// 去掉指定列(按表头名精确匹配)单元格值中的所有冒号(含全角)
function stripColonInColumn(rows, columnName) {
if (!rows || rows.length === 0) return 0;
const header = rows[0];
const colIndex = header.findIndex(h => h != null && String(h).trim() === columnName);
if (colIndex === -1) {
console.warn(` [警告] 未找到列 "${columnName}",跳过冒号清理`);
return 0;
}
let changed = 0;
for (let i = 1; i < rows.length; i++) {
const v = rows[i][colIndex];
if (v == null) continue;
const str = String(v);
if (str.includes(':') || str.includes(':')) {
rows[i][colIndex] = str.replace(/[::]/g, '');
changed++;
}
}
return changed;
}
// ---------- 收集子文件夹 ----------
const subDirs = fs.readdirSync(rootDir, { withFileTypes: true })
.filter(d => d.isDirectory() && d.name.startsWith('7.'))
@@ -132,6 +154,8 @@ const outWb = XLSX.utils.book_new();
if (shangluHeader) {
const data = [shangluHeader, ...shangluRows];
const n1 = stripColonInColumn(data, '结算账户');
if (n1) console.log(` 商旅"结算账户"列清理冒号: ${n1} 个单元格`);
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(outWb, ws, '商旅');
} else {
@@ -140,6 +164,8 @@ if (shangluHeader) {
if (jizhiHeader) {
const data = [jizhiHeader, ...jizhiRows];
const n2 = stripColonInColumn(data, '*对账单/项目名称');
if (n2) console.log(` 吉智"*对账单/项目名称"列清理冒号: ${n2} 个单元格`);
const ws = XLSX.utils.aoa_to_sheet(data);
XLSX.utils.book_append_sheet(outWb, ws, '吉智');
} else {