diff --git a/.gitignore b/.gitignore index 2ffc2a2..f8900c9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ dist/*.json ~*.xlsx -node_modules/ \ No newline at end of file +node_modules/ + +企业信息*.xlsx \ No newline at end of file diff --git a/exportJson.js b/exportJson.js new file mode 100644 index 0000000..45071e0 --- /dev/null +++ b/exportJson.js @@ -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) +} diff --git a/package.json b/package.json index 0e41c77..091893a 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/yarn.lock b/yarn.lock index 116c0b0..0ad558a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" diff --git a/国服小助手.xlsx b/国服小助手.xlsx index 5ecf7cb..545ccdf 100644 Binary files a/国服小助手.xlsx and b/国服小助手.xlsx differ diff --git a/国际服小助手.xlsx b/国际服小助手.xlsx index 3c21b0e..1df9a67 100644 Binary files a/国际服小助手.xlsx and b/国际服小助手.xlsx differ diff --git a/生涯地图.xlsx b/生涯地图.xlsx index ee27243..ff4623d 100644 Binary files a/生涯地图.xlsx and b/生涯地图.xlsx differ