ken_nogi/NodeJS/SheetsProtectUnlock/index.js
Kenichiro NOGI 51a95c5e21 NodeJS
2025-07-10 10:12:37 +09:00

36 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
if (process.argv.length < 3) {
console.error('使い方: node index.js <フォルダパス>');
process.exit(1);
}
const targetDir = process.argv[2];
fs.readdir(targetDir, (err, files) => {
if (err) {
console.error('ディレクトリの読み込みに失敗:', err);
process.exit(1);
}
files.filter(file => file.endsWith('.xml')).forEach(file => {
const filePath = path.join(targetDir, file);
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(`${file} の読み込みに失敗:`, err);
return;
}
// sheetProtectionタグを削除
const newData = data.replace(/<sheetProtection[\s\S]*?\/>/g, '');
fs.writeFile(filePath, newData, 'utf8', err => {
if (err) {
console.error(`${file} の書き込みに失敗:`, err);
} else {
console.log(`${file} の sheetProtection タグを削除しました。`);
}
});
});
});
});