26 lines
667 B
JavaScript
26 lines
667 B
JavaScript
const XLSX = require('xlsx');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const data = [
|
|
['word', 'meaning'],
|
|
['apple', 'n. 苹果'],
|
|
['banana', 'n. 香蕉'],
|
|
['persistent', 'adj. 执着的,持久的'],
|
|
['eloquent', 'adj. 雄辩的,有口才的']
|
|
];
|
|
|
|
const ws = XLSX.utils.aoa_to_sheet(data);
|
|
const wb = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(wb, ws, 'Words');
|
|
|
|
const staticDir = path.join(__dirname, 'static');
|
|
if (!fs.existsSync(staticDir)) {
|
|
fs.mkdirSync(staticDir);
|
|
}
|
|
|
|
const outFile = path.join(staticDir, 'import_template.xlsx');
|
|
XLSX.writeFile(wb, outFile);
|
|
|
|
console.log('Template generated at:', outFile);
|