Code Monkey home page Code Monkey logo

sy-excel2json's Introduction

sy-excel2json

一个简单的将 .xlsx 转化输出为 .json 的工具

安装

npm i sy-excel2json -g

excel 内容示例

key 简体中文 English
title 标题 Title
nav.home 首页 Home
tip.success 成功 Success

使用

outputType为object时,表格第一列用于生成对象的键,剩下的列用于生成值

sy-e2j filePath outputPath outputType [key1,key2...] [type1,type2,...]

filePath: 表示要转换的 .xlsx 文件路径

outputPath 表示转换后的 .json 文件路径

outputType 表示转换后的 .json 文件格式 目前支持数组(array)及对象(object) 类型,默认为array

key 表示表头(列名)转换后的键

type 表示列转换后值的类型
  type的可选类型为: string | number | boolean | date
  1. 直接使用(使用表头作为 key 的值)
  • 1.1 outputType为默认值:array
sy-e2j ./test.xlsx base
or
sy-e2j ./test.xlsx base.json

输出内容为:

[
  { "key": "title", "简体中文": "标题", "English": "Title" },
  { "key": "nav.home", "简体中文": "首页", "English": "Home" },
  { "key": "tip.success", "简体中文": "成功", "English": "Success" },
]
  • 1.2 outputType为object
sy-e2j ./test.xlsx base object
or
sy-e2j ./test.xlsx base.json object

输出内容为:

{
  "简体中文": {
    "title": "标题",
    "nav": {
      "home": "首页"
    },
    "tip": {
      "success": "成功"
    },
  },
  "English": {
    "title": "Title",
    "nav": {
      "home": "Home"
    },
    "tip": {
      "success": "Success"
    },
  }
}
  1. 使用自定义 key
  • 2.1 outputType为默认值:array
sy-e2j ./test.xlsx base array key,zh_CN,EN

输出内容为:

[
  {"key": "title", "zh_CN": "标题", "EN": "Title" },
  {"key": "nav.home", "zh_CN": "首页", "EN": "Home" },
  {"key": "tip.success", "zh_CN": "成功", "EN": "Success" },
]
  • 2.2 outputType为object
sy-e2j ./test.xlsx base object key,zh_CN,EN

输出内容为:

{
  "zh_CN": {
    "title": "标题",
    "nav": {
      "home": "首页"
    },
    "tip": {
      "success": "成功"
    }
  },
  "EN": {
    "title": "Title",
    "nav": {
      "home": "Home"
    },
    "tip": {
      "success": "Success"
    }
  }
}
  1. 使用自定义类型 若值类型为Number且该值无法转为Number时, 则为空字符串
index value
1 11
2
3 13
sy-e2j ./test.xlsx base array label,value string,number

输出内容为:

[
  { "label": "1", "value": 11 },
  { "label": "2", "value": "" },
  { "label": "3", "value": 13 }
]

sy-excel2json's People

Contributors

sssx-li avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.