Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

excel2json

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

excel2json

excel2json

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
decreased by-35.29%
Maintainers
1
Weekly downloads
 
Created
Source

Excel2Json

Can be converted to JSON format any Excel data.

example Excel data

ABCD
1{}
2_idobj.codeobj.value:number
3
4firstone1
5secondtwo2
6
converted to Object
[
    {
        _id: 'first',
        obj: {
            code: 'one',
            value: 1
        }
    }, 
    {
        _id: 'second',
        obj: {
            code: 'two',
            value: 2
        }
    }
]

Installation

npm install excel2json

Usage

Quick start

example sheet.xlsx

ABCD
1{name: 'Test'}
2_idobj.codeobj.value:number
3
4firstone1
5secondtwo2
6
Sheet1
var excel2json = require('excel2json');

var filename = './sheet.xlsx';
var sheets = [1];
excel2json.parse(filename, sheets, function(err, data) {
    console.log(data);
    // [{
    //    num: 1,                    // sheet number
    //    name: 'Sheet1',            // sheet name
    //    option: { name: 'Test' },  // sheet option (A1)
    //    contents: [
    //        { _id: 'first', obj: { code: 'one', value: 1 } }, { _id: 'second', obj: { code: 'two', value: 2 } }
    //    ]
    // }]

    excel2json.toJson(data, function(err, json) {
        console.log(json);
        // {
        //    Test: {
        //        first: {
        //            _id: 'first',
        //            obj: { code: 'one', value: 1 }
        //        },
        //        second: {
        //            _id: 'second',
        //            obj: { code: 'two', value: 2 }
        //        }
        //    }
        // }
    });
});

Setup

Setup options.

var excel2json = require('excel2json');

excel2json.setup({
    optionCell: 'A1', // Cell with a custom sheet option. It is not yet used now. (default: 'A1'
    attrLine: '2',    // Line with a data attribute. (default: '2'
    dataLine: '4',    // Line with a data. (default: '4'
    refKey: '_id'     // ref key. (default: '_id'
});

Sheet option

sheet option. setting with optionCell (default: 'A1'

  • name
  • type
  • key
  • attrLine
  • dataLine
  • refKey

Attribute

Specify the key name.

Special character

  • # Use when the array.
  • :number Use when the parameters of type Number.
  • :boolean Use when the parameters of type Boolean.
  • :date Use when the parameters of unix time.
  • :index Use when the array of array.

Example

An example of a complex format.

test.xlsx > test.json

var excel2json = require('excel2json');

excel2json.parse('test.xlsx', [], function(err, sheetDatas) {
    excel2json.toJson(sheetDatas, function(err, result) {
        fs.writeFileSync('test.json', JSON.stringifi(result, null, 4));
    });
});

Test

Run npm test and npm run-script jshint

Keywords

FAQs

Package last updated on 10 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc