excel表格轉換為json格式字符串


日常工作中遇到一些Excel表格的數據,需要轉換成json格式的字符串,怎么處理呢?可以使用這個工具:excel2json

下載地址:https://github.com/neil3d/excel2json/releases

 

 

用cmd進入文件解壓所在的地址,敲入命令

excel2json --excel E:\a\student.xlsx --json E:\a\student.json --header 1 --array true
意思是 把E:\a\student.xlsx這個文件,轉成E:\a\student.json這個,頭有1行 轉換成數組格式的。

student.xlsx的格式是這樣:頭就是第一行。目前只支持轉換.xlsx文件。

 

 

 

各參數解釋:

-e, --excel Required. input excel file path.

-j, --json export json file path.

-s, --sql export SQL file path.

-p, --csharp export C# data struct code file path.

-h, --header Required. number lines in sheet as header.

-c, --encoding (Default: utf8-nobom) export file encoding.

-l, --lowcase (Default: False) convert filed name to lowcase.

-a, --array (Default: False) export as array, otherwise as dict object.

 

導出的student.json內容如下:

[{
"StringID": "p1",
"vzh_rCN": "最流行",
"vus": "Charts",
"vth": "แผนภูมิ",
"vms": "Carta",
"vin": "Tangga lagu",
},
{
"StringID": "p2",
"vzh_rCN": "1個月",
"vus": "1 month",
"vth": "1 เดือน",
"vms": "1 bulan",
"vin": "1 bulan",

}]

然后將這個json文件后綴改為js,在代碼里面加:

export const json =
 
然后在APP.vue中:
import { json } from '@/utils/student.js'

let obj = {}
json.map(item => {
Object.keys(item).map(ite => {
if (ite != 'StringID') {
if (obj[ite]) {
obj[ite][item.StringID] = item[ite]
} else {
obj[ite] = {
[item.StringID]: item[ite]
}
}
} else {
obj[ite] = {}
}
})
})
console.log(obj)

然后在控制台找到想要復制的對象右鍵 store as global variable
copy(temp1) 執行完,內容已經放在系統粘貼板中,ctrl+v 粘貼到student.js中。
此時student.js內容如下:
export const json = {
  "vzh_rCN": {
    "p1": "最流行",
    "p2": "1個月",
  },
  "vus": {
    "p1": "Charts",
    "p2": "1 month",
  },
  "vth": {
    "p1": "แผนภูมิ",
    "p2": "1 เดือน",
  },
  "vms": {
    "p1": "Carta",
    "p2": "1 bulan",
  },
  "vin": {
    "p1": "Tangga lagu",
    "p2": "1 bulan",
  },
}

 
也可以用網站直接轉:https://tableconvert.com/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM