Excel2json
Can be converted to JSON format any Excel data.
Install / Use
/learn @iyu/Excel2jsonREADME
Excel2Json
Can be converted to JSON format any Excel data.
example Excel data
| | A | B | C | D | |:-:|:-------|:---------|:-----------------|---| | 1 | {} | | | | | 2 | _id | obj.code | obj.value:number | | | 3 | | | | | | 4 | first | one | 1 | | | 5 | second | two | 2 | | | 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
| | A | B | C | D | |:-:|:---------------|:---------|:-----------------|---| | 1 | {name: 'Test'} | | | | | 2 | _id | obj.code | obj.value:number | | | 3 | | | | | | 4 | first | one | 1 | | | 5 | second | two | 2 | | | 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: { // option extend sheet option (ex: A1)
// name: 'Test'
// attr_line:
// data_line:
// ref_key: '_id',
// format: {
// A: { type: null, key: '_id', keys: [ '_id' ] },
// B: { type: null, key: 'obj.code', keys: [ 'obj', 'code' ] },
// C: { type: 'number', key: 'obj.value', keys: [ 'obj', 'value' ] }
// }
// },
// 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({
option_cell: 'A1', // Cell with a custom sheet option. It is not yet used now. (default: 'A1'
attr_line: '2', // Line with a data attribute. (default: '2'
data_line: '4', // Line with a data. (default: '4'
ref_key: '_id' // ref key. (default: '_id'
logger: Logger // custom logger.
});
Sheet option
sheet option. setting with optionCell (default: 'A1'
nametypekeyattr_linedata_lineref_key
Attribute
Specify the key name.
Special character
#Use when the array.$Use when the split array.:numberor:numUse when the parameters of typeNumber.:booleanor:boolUse when the parameters of typeBoolean.:dateUse when the parameters of unix time.:indexUse when the array of array.
Example
An example of a complex format.
var excel2json = require('excel2json');
excel2json.parse('test.xlsx', [], function(err, sheetDatas) {
excel2json.toJson(sheetDatas, function(err, result) {
fs.writeFileSync('test.json', JSON.stringify(result, null, 4));
});
});
Contribution
- Fork it ( https://github.com/iyu/excel2json/fork )
- Create a feature branch
- Commit your changes
- Rebase your local changes against the master branch
- Run test suite with the
npm test; npm run lintcommand and confirm that it passes - Create new Pull Request
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
