master
WalterBright 3 years ago
parent 6699ede0fa
commit e4a6af3ceb
  1. 4
      .gitignore
  2. 59
      exportJson.js
  3. 19
      package.json
  4. 5
      yarn.lock
  5. BIN
      国服小助手.xlsx
  6. BIN
      国际服小助手.xlsx
  7. BIN
      生涯地图.xlsx

4
.gitignore vendored

@ -2,4 +2,6 @@ dist/*.json
~*.xlsx
node_modules/
node_modules/
企业信息*.xlsx

@ -0,0 +1,59 @@
const xlsx = require('xlsx')
const fs = require('fs')
const dayjs = require('dayjs')
const dayFromExcel=(value) =>
dayjs('1900-01-01')
.add(value + 2 * 365, 'day')
.format('YYYY-MM-DD')
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,
注册日期: dayFromExcel,
合同开始日期: dayFromExcel,
合同到期日期: dayFromExcel,
}
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])
}
})
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])
// console.log(table.Sheets[sheetName]["!merges"])
const dataLines = dataJson.map((obj) => useHandle(obj, handle))
const dataBuffer = Buffer.from(JSON.stringify(dataLines))
fs.writeFileSync(dataPath, dataBuffer)
}
//运行命令 node exportJson文件名 表名,即可导出文件
// node ./exportJson.js ./狂野飙车9生涯数据-地图.xlsx forJson
const [, , xlsxFilePath, sheetName] = process.argv
try {
if (xlsxFilePath && sheetName) {
exportJsonLines(xlsxFilePath, sheetName)
console.log('执行成功')
}
} catch (e) {
console.log(e)
}

@ -5,20 +5,19 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"gl:carList":"node .\\exportJsonLines.js .\\国际服小助手.xlsx 数据卡片",
"gl:versionNote":"node .\\exportJsonLines.js .\\国际服小助手.xlsx versionNoteGL",
"gl:careerSeason":"node .\\exportJsonLines.js .\\生涯地图.xlsx careerSeasonGL",
"al:carList":"node .\\exportJsonLines.js .\\国服小助手.xlsx 数据卡片",
"al:versionNote":"node .\\exportJsonLines.js .\\国服小助手.xlsx versionNoteAL",
"al:careerSeason":"node .\\exportJsonLines.js .\\生涯地图.xlsx careerSeasonAL",
"tracks":"node .\\exportJsonLines.js .\\生涯地图.xlsx track",
"mapTheme":"node .\\exportJsonLines.js .\\生涯地图.xlsx mapTheme"
"gl:carList": "node .\\exportJsonLines.js .\\国际服小助手.xlsx 数据卡片",
"gl:versionNote": "node .\\exportJsonLines.js .\\国际服小助手.xlsx versionNoteGL",
"gl:careerSeason": "node .\\exportJsonLines.js .\\生涯地图.xlsx careerSeasonGL",
"al:carList": "node .\\exportJsonLines.js .\\国服小助手.xlsx 数据卡片",
"al:versionNote": "node .\\exportJsonLines.js .\\国服小助手.xlsx versionNoteAL",
"al:careerSeason": "node .\\exportJsonLines.js .\\生涯地图.xlsx careerSeasonAL",
"tracks": "node .\\exportJsonLines.js .\\生涯地图.xlsx track",
"mapTheme": "node .\\exportJsonLines.js .\\生涯地图.xlsx mapTheme"
},
"author": "",
"license": "ISC",
"dependencies": {
"dayjs": "^1.11.5",
"xlsx": "^0.15.4"
}
}

@ -46,6 +46,11 @@ crc-32@~1.2.0:
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-1.2.2.tgz#3cad35a934b8bf71f25ca524b6da51fb7eace2ff"
integrity sha512-ROmzCKrTnOwybPcJApAA6WBWij23HVfGVNKqqrZpuyZOHqK2CwHSvpGuyt/UNNvaIjEd8X5IFGp4Mh+Ie1IHJQ==
dayjs@^1.11.5:
version "1.11.5"
resolved "https://mirrors.cloud.tencent.com/npm/dayjs/-/dayjs-1.11.5.tgz#00e8cc627f231f9499c19b38af49f56dc0ac5e93"
integrity sha512-CAdX5Q3YW3Gclyo5Vpqkgpj8fSdLQcRuzfX6mC6Phy0nfJ0eGYOeS7m4mt2plDWLAtA4TqTakvbboHvUxfe4iA==
exit-on-epipe@~1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz#0bdd92e87d5285d267daa8171d0eb06159689692"

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save