npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

excel-tobe-json

v1.5.3

Published

excel to json, excel 表格转 json, json grammar

Downloads

7

Readme

语法规则

语法规则:

  • 带[],如 arr_index[]

  • 不带[],如 title_image

  • #require(sheet),可以引入其他sheet数据

带[]:数组,push原则,如有指定index,如index[1],则是赋值(替换)原则

  • 例如 demo 的 arr_table_cell 字段

不带[]:对象字段,赋值(替换)原则。

  • 例如 demo 的 title_image 字段

#require(sheet):该字段(可能也没有)的value来源其他sheet。

  • #号前可以有字段,引入的sheet大对象为该属性的value。如props#require(2)

示例

excel demo:

sheet1

| | | | |:---- |:--- |:----- | |filename |cn_lang |en_lang | |lang |cn |en | |title_image |body_cn_m.png | body_en_m.jpg | |apply_condition_c[0].c |1,招募条件的内容 |1,condition | |apply_condition_c[1].c |2,招募条件的内容 |2,condition | |arr_index[0] |1,test数组合并 |1,test arr | |arr_index[1] |2,test数组合并 |2,test arr | |arr_table_cell[] |1,数组,合并单元格 |1,merge table cell | | |2,数组,合并单元格 |2,merge table cell | | |3,数组,合并单元格 |3,merge table cell | |arr_push[] |1,数组 push |1,arr push | |arr_push[] |2,数组 push |2, arr push | |arr_table_cell[] |4,数组,push 单元格 |4,arr,push merge table cell | |arr_table_cell[1].c.a[0].b[0] |深度结构 |deep | |title_image |body_cn_m.jgp |body_en_m.jpg | |code_status#require(2) | | |

sheet2

| | | | |:---- |:--- |:----- | |200 | 成功 |success | |403 | 失效 |Invalid |

will to be

[
    {
        "filename": "cn_lang",
        "lang": "cn",
        "title_image": "body_cn_m.jgp",
        "apply_condition_c": [
            {
                "c": "1,招募条件的内容"
            },
            {
                "c": "2,招募条件的内容"
            }
        ],
        "arr_index": [
            "1,test数组合并",
            "2,test数组合并"
        ],
        "arr_table_cell": [
            "1,数组,合并单元格",
            {
                "c": {
                    "a": [
                        {
                            "b": [
                                "深度结构"
                            ]
                        }
                    ]
                }
            },
            "3,数组,合并单元格",
            "4,数组,push 单元格"
        ],
        "arr_push": [
            "1,数组 push",
            "2,数组 push"
        ],
        "code_status": {
            "200": "成功",
            "403": "失效"
        }
    },
    {
        "filename": "en_lang",
        "lang": "en",
        "title_image": "body_en_m.jpg",
        "apply_condition_c": [
            {
                "c": "1,condition"
            },
            {
                "c": "2,condition"
            }
        ],
        "arr_index": [
            "1,test arr",
            "2,test arr"
        ],
        "arr_table_cell": [
            "1,merge table cell",
            {
                "c": {
                    "a": [
                        {
                            "b": [
                                "deep"
                            ]
                        }
                    ]
                }
            },
            "3,merge table cell",
            "4,arr,push merge table cell"
        ],
        "arr_push": [
            "1,arr push",
            "2, arr push"
        ],
        "code_status": {
            "200": "success",
            "403": "Invalid"
        }
    }
]

安装

npm安装:

  • npm install excel-tobe-json --save

参数:

|参数名|必选|类型|说明| |:---- |:---|:----- |----- | |excelPathName |是 |string |excel路径 | |sheet |否 |number | 读取表格哪个sheet数据 | |isColOriented |否 |string | 默认true按列处理,按行请使用false | |dirOutput |否 |string | 输出的json文件路径(此时回调不会得到json数据)。如无,则回调第二个参数是json数据。 |

示例

// excelToJson入口方法。
var convertExcel = require('excel-tobe-json').excelToJson;
convertExcel(excelPathName, {isColOriented: true, dirOutput: 'excel.json'}, function (err, excelDatas) {
    if (err) {
        console.log(err)
    }else{
        console.log(JSON.stringify(excelDatas))
    }
})

插件扩展

考虑到很多在线excel表格,excel-tobe-json开放了扩展支持:

  • extendOnlineExcel 此方法用来扩展第三方在线excel表格。接收一个数组作为参数. 第一项为域名(如docs.google.com),第二项为handle方法(此方法也接收2个参数,第一个是在线url,第二个是个方法,当你处理好在线数据为原始结构数组,调用此方法并传入你的原始数据即可)。

谷歌在线表格扩展demo:

  • https://github.com/diyao/google-excel/blob/master/lib/google-excel.js
var excelTobeJson = require('excel-tobe-json');
// 谷歌excel扩展导出的一个数组,第一个域名,第二项handle函数。具体看地址源码
// 如此,excel-tobe-json可直接处理谷歌在线表格。
excelTobeJson.extendOnlineExcel(require('google-excel'))