console.log("Hello world! - js.jsrun.net ");
const XLSX = require('xlsx');
const fs = require('fs');
const path = require('path');
const workbook = XLSX.readFile('C:\Users\liyaxin\Desktop\1.xlsx');
const sheetName = 'Sheet1';
const worksheet = workbook.Sheets[sheetName];
const outputFolderPath = 'C:\Users\liyaxin\Desktop\photo';
if (!fs.existsSync(outputFolderPath)) {
fs.mkdirSync(outputFolderPath, { recursive: true });
}
for (let cell in worksheet) {
if (cell.startsWith('A')) {
const image = worksheet[cell].v;
if (image && image.indexOf('data:image') !== -1) {
const imageBase64 = image.replace(/^data:image\/\w+;base64,/, '');
const buffer = Buffer.from(imageBase64, 'base64');
const correspondingCell = `B${cell.substring(1)}`;
const imageNameInfo = worksheet[correspondingCell].v;
const imageName = `${imageNameInfo}.png`;
const imagePath = path.join(outputFolderPath, imageName);
fs.writeFileSync(imagePath, buffer, 'base64');
console.log(`图片 ${imageName} 已保存至 ${outputFolderPath}!`);
}
}
}