parent
c53d5c0650
commit
6699ede0fa
@ -1,7 +1,5 @@ |
||||
# XLSX-TOOL |
||||
# 狂野飙车9数据表 |
||||
|
||||
运行命令 |
||||
|
||||
```cmd |
||||
node exportJson 文件名 表名 |
||||
``` |
||||
+ 国服全车数据表 |
||||
+ 国际全车服数据表 |
||||
+ 生涯地图表 |
||||
@ -1,53 +1,52 @@ |
||||
const xlsx=require('xlsx') |
||||
const fs=require('fs') |
||||
|
||||
const handle={ |
||||
topSpeed:value=>Number(Number(value).toFixed(1)), |
||||
acceleration:value=>Number(Number(value).toFixed(2)), |
||||
handling:value=>Number(Number(value).toFixed(2)), |
||||
nitro:value=>Number(Number(value).toFixed(2)), |
||||
nitroDuration:value=>Number(Number(value).toFixed(2)), |
||||
car_id:value=>''+value |
||||
const xlsx = require('xlsx') |
||||
const fs = require('fs') |
||||
|
||||
const handle = { |
||||
topSpeed: (value) => Number(Number(value).toFixed(1)), |
||||
acceleration: (value) => Number(Number(value).toFixed(2)), |
||||
handling: (value) => Number(Number(value).toFixed(2)), |
||||
nitro: (value) => Number(Number(value).toFixed(2)), |
||||
nitroDuration: (value) => Number(Number(value).toFixed(2)), |
||||
car_id: (value) => '' + value, |
||||
} |
||||
|
||||
const copy=obj=>JSON.parse(JSON.stringify(obj)) |
||||
const copy = (obj) => JSON.parse(JSON.stringify(obj)) |
||||
|
||||
const useHandle=(obj,handle)=>{ |
||||
let res=copy(obj) |
||||
Object.keys(handle).forEach(key=>{ |
||||
if(res[key]){ |
||||
res[key]=handle[key](res[key]) |
||||
const useHandle = (obj, handle) => { |
||||
let res = copy(obj) |
||||
Object.keys(handle).forEach((key) => { |
||||
if (res[key]) { |
||||
res[key] = handle[key](res[key]) |
||||
} |
||||
|
||||
}) |
||||
return res |
||||
} |
||||
|
||||
const exportJsonLines=(xlsxFilePath,sheetName)=>{ |
||||
const table=xlsx.readFile(xlsxFilePath) |
||||
const dataPath=`dist\\${xlsxFilePath}.${sheetName}.line.json` |
||||
const dataJson=xlsx.utils.sheet_to_json(table.Sheets[sheetName]) |
||||
const exportJsonLines = (xlsxFilePath, sheetName) => { |
||||
const table = xlsx.readFile(xlsxFilePath) |
||||
const dataPath = `dist\\${xlsxFilePath}.${sheetName}.line.json` |
||||
const dataJson = xlsx.utils.sheet_to_json(table.Sheets[sheetName]) |
||||
// console.log(table.Sheets[sheetName]["!merges"])
|
||||
const dataLines=dataJson |
||||
.map(obj=>useHandle(obj,handle)) |
||||
.map(dataItem=>JSON.stringify(dataItem)).join('\n') |
||||
const dataBuffer=Buffer.from(dataLines) |
||||
const dataLines = dataJson |
||||
.map((obj) => useHandle(obj, handle)) |
||||
.map((dataItem) => JSON.stringify(dataItem)) |
||||
.join('\n') |
||||
const dataBuffer = Buffer.from(dataLines) |
||||
|
||||
fs.writeFileSync(dataPath,dataBuffer) |
||||
fs.writeFileSync(dataPath, dataBuffer) |
||||
} |
||||
|
||||
//运行命令 node exportJsonLines 文件名 表名,即可导出文件
|
||||
|
||||
// node ./exportJsonLines.js ./狂野飙车9生涯数据-地图.xlsx forJson
|
||||
|
||||
const [,,xlsxFilePath,sheetName]=process.argv |
||||
|
||||
try{ |
||||
const [, , xlsxFilePath, sheetName] = process.argv |
||||
|
||||
if(xlsxFilePath&&sheetName){ |
||||
exportJsonLines(xlsxFilePath,sheetName) |
||||
try { |
||||
if (xlsxFilePath && sheetName) { |
||||
exportJsonLines(xlsxFilePath, sheetName) |
||||
console.log('执行成功') |
||||
} |
||||
}catch(e){ |
||||
} |
||||
} catch (e) { |
||||
console.log(e) |
||||
} |
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue