首先安装依赖
pnpm install xlsx file-saver
创建translate.js文件
import fs from 'node:fs'
import path from 'node:path'
import * as XLSX from 'xlsx'
export default function useParseLang() {
const filePath = process.argv[2]
if (!filePath) {
console.error('文件不存在')
return
}
const inputPath = path.resolve(filePath)
console.log('翻译文件', inputPath)
fs.readFile(inputPath, 'binary', (err, data) => {
if (err) {
throw new Error(err)
}
const workBook = XLSX.read(data, {
type: 'binary', cellDates: true })
const reg = /[\s\u00A0]+/g
workBook.SheetNames.forEach(name => {
const workSheet = workBook.Sheets[name]
console.log('workSheet: ', workSheet)
const rawList