stevetarver / excel-as-json Goto Github PK
View Code? Open in Web Editor NEWnpm package that converts excel data to json
License: MIT License
npm package that converts excel data to json
License: MIT License
Thank you for your great work. This library saved my time! Then I've got a problem from today.
My issue is that convertExcel() function callback returns empty array with no error. It could be a similar issue #7. Can I have any workaround?
Test environment
Hi,
Currently, the converter is outputting json as:
[
{
"name": "John Doe",
"age": "30"
},
{
"name": "Alex Len",
"age": "27"
},
{
"name": "Debbie John",
"age": "36"
}
]
But, is there a way to add a root node through configuration variables, so that the json looks like this:
[
{
"user": [
{
"name": "John Doe",
"age": "30"
},
{
"name": "Alex Len",
"age": "27"
},
{
"name": "Debbie John",
"age": "36"
}
]
}
]
Hi Steve,
I have tried converting excel to json... and added this code in my config file(protractor).
var convertExcel = require('excel-as-json').processFile;
convertExcel("D:\Protractor\Grunt_Pro\data.xlsx", "D:\Protractor\Grunt_Pro\test\sample1.json",false,function(err, data) {
if(err) console.log(err);
});
my data.xlsx contains three rows with header value1 and value2. the next two rows has values as similar to shown below.
|value1|value2|
|1 | 2|
|3 | 4|
However json file also created(sample1.json) but it contains only two braces "[]". If needed i will share you more details. Kindly help me to sort out this.
Hi Steve,
I am very thanks full to you. I have used this library and it is very useful to me even I recommended to my colleagues and other . Thanks a lot and gratitude towards your work. The way your handle this in NODE JS I rely like.
I need small help on this, please check my observation.
npm WARN notice [SECURITY] fstream has the following vulnerability: 1 high. Go here for more details: https://www.npmjs.com/advisories?search=fstream&version=0.1.31 - Run
npm i npm@latest -g
to upgrade your npm version, and thennpm audit
to get more info.
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: This module relies on Node.js's internals and will break at some point. Do not use it, and update to [email protected].[email protected] install C:\QA-DART-POC\nodejs\projectTemplate\node_modules\libxmljs
node-pre-gyp install --fallback-to-build --loglevel httpnode-pre-gyp http GET https://github.com/libxmljs/libxmljs/releases/download/v0.18.8/node-v59-win32-x64.tar.gz
node-pre-gyp http 404 https://github.com/libxmljs/libxmljs/releases/download/v0.18.8/node-v59-win32-x64.tar.gz
node-pre-gyp ERR! Tried to download(404): https://github.com/libxmljs/libxmljs/releases/download/v0.18.8/node-v59-win32-x64.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (node-v59 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp http 404 status code downloading tarball https://github.com/libxmljs/libxmljs/releases/download/v0.18.8/node-v59-win32-x64.tar.gz
It's a request to you,
Could you please update the repository address in npm lib and make this lib comfortable for updated version and old version. ?
Thanks,
Swapnil
In some spreadsheets with multiple sheets, it is desirable to specify which sheet to convert (currently it is only possible to convert 'Sheet 1', and will throw an exception if that sheet cannot be converted).
The solution would be to accept another (optional) parameter for the processFile method, but that would result in a breaking change in the API.
The change would be to accept the sheet name and alter the call on line 148 of excel-as-json.coffee from this:
excel src, (err, data) ->
to this:
excel src, sheet, (err, data) ->
I am happy to make the change, but if you have a preference on how to accept the sheet name in processFile please let me know!
(PS - thanks for this module, it's been very useful and has saved me lots of time)
This is the first time I am using this module.I am having a excel file which contains date format column as this (DD/MM/YYYY) but after conversion to json,this date changed to some number - 42912.
26/6/2017 changed to 42912.
What could be the issue ?
I have tried to install and execute. it's showing some issues. can i get the detailed instruction to configure this API.
issue:
d:\ExcelProject\exceljson>node excel-as-json.js (not finding this module file)
internal/modules/cjs/loader.js:638
throw err;
^
Error: Cannot find module 'd:\ExcelProject\exceljson\lib\excel-as-json.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Function.Module.runMain (internal/modules/cjs/loader.js:829:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Hello, I have an excel sheet that is row oriented. I am trying to export each rows into it's own separate JSON file.
Any suggestions or help would be highly appreciated.
Besides nodejs, do you have any prerequisite for installing this software?
Is there a way to set a field to be an array of objects? I see support for arrays and objects separately but maybe I'm missing this feature somewhere?
I need something like this in my JSON output:
variants : [{
size: 'S',
price: 5,
},{
size: 'M',
price: 10,
},{
size: 'L',
price: 15,
}]
Good day,
i believe there is a bug in the convert function:
node: 8.11.2
excel: 0.1.7
excel-as-json: 2.0.2
convert = function(data, options) {
// console.log(data);
var index, item, j, k, keys, len, len1, result, row, rows, value;
if (options.isColOriented) {
data = transpose(data);
}
keys = data[0];
rows = data.slice(1);
result = [];
for (j = 0, len = rows.length; j < len; j++) {
row = rows[j];
item = {};
for (index = k = 0, len1 = row.length; k < len1; index = ++k) {
console.log(value); // undefined
assign(item, keys[index], value, options);
}
result.push(item);
}
return result;
};
so when it goes to the assign function i get the error:
...\node_modules\node-promise\promise.js:204
throw error;
^
TypeError: Cannot read property 'length' of undefined
at convertValue (...\node_modules\excel-as-json\lib\excel-as-json.js:49:15)
at assign (...\node_modules\excel-as-json\lib\excel-as-json.js:106:33)
at convert (...\node_modules\excel-as-json\lib\excel-as-json.js:143:9)
at ...\node_modules\excel-as-json\lib\excel-as-json.js:218:20
at ...\node_modules\excel\excelParser.js:163:3
at Immediate._onImmediate (...\node_modules\node-promise\promise.js:164:27)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)
Hi, I'm using this project to automatically process some excel files in node. So far it's been very useful, but I'm having a little trouble due to having to provide an sheet index as argument yet not being able to get how many indexes are available, nor the name of each sheet - something that's a small bottleneck to my automation.
Would it be possible to get a new method that provides said data? perhaps an array of sheet index and name, something like[ {index:1, name:'nameOfThatSheet'} , {index:2, name:'nameOADifferentSheet'} ]
.
Hello, can we using this service, convert an excel file to JSon, while setting the names of some fields to the required fields in Json?
For example, we have an Excel file where the name of the fields is indicated as "product type", but when we convert we need this particular field to be changed as "type of goods" or like that... ???
Hi,
I am unable to install and excerpt of the error below. I have also attached the npm-debug.log, would you help please?
npm-debug.log.txt
Thanks
H:\node\testlab\excelJson>npm install excel-as-json --save-dev
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No README data
[email protected] install H:\node\testlab\excelJson\node_modules\excel-as-json\node_modules\excel\node_modules\libxmljs
node-gyp rebuild
H:\node\testlab\excelJson\node_modules\excel-as-json\node_modules\excel\node_modules\libxmljs>if not defined npm_config_node_gyp (node "I:\nodejs-0.10.24\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (rebuild)
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
...
When I am trying to install this package I am getting this error. My node version is v6.3.0 and npm version is 3.10.8
File is attached for reference
npm-debug.txt
Currently running windows subsystem for linux, recently installed node 10, here's the output error I get.
devon@DESKTOP-HCS87SE:~$ sudo -i
root@DESKTOP-HCS87SE:~# npm install excel-as-json --save-dev
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
> [email protected] install /root/node_modules/libxmljs
> node-pre-gyp install --fallback-to-build --loglevel http
sh: 1: node-pre-gyp: Permission denied
npm WARN enoent ENOENT: no such file or directory, open '/root/package.json'
npm WARN root No description
npm WARN root No repository field.
npm WARN root No README data
npm WARN root No license field.
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build --loglevel http`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-06-19T23_51_04_378Z-debug.log
I currently have an excel file which has the following data
Excel formats of the columns are:
crn (column A) - Number
accountNumber (column B) - Text
What I basically want in the converted JSON is to keep the 'crn' as integer type and 'accountNumber' as string type.
But after converting this to a JSON file, the 'accountNumber' value in JSON is of type integer (and also rounds up the values ex, 12000000000000111 to 12000000000000112 ). If I use the convertTextToNumber
flag in options
, then BOTH 'crn' and 'accountNumber' are converted to strings which I don't want either.
Any idea on how to resolve this ?
I have been trying to parse a simple excel file with just dummy data and 2 fields as:
firstName lastName
John Doe
but the result was coming as empty array: []
. So I tried to check out the library files and found that at excel library there was an parseError which was not being logged. It is as follows:
{ [Error: Could not locate the bindings file. Tried: → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/Debug/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/Release/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/out/Debug/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/Debug/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/out/Release/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/Release/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/default/xmljs.node → /mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/compiled/4.5.0/linux/x64/xmljs.node] tries: [ '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/Debug/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/Release/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/out/Debug/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/Debug/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/out/Release/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/Release/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/build/default/xmljs.node', '/mnt/c/Users/gamepr0/Mirrors/excel-to-json/node_modules/libxmljs/compiled/4.5.0/linux/x64/xmljs.node' ] }
I request you please fix this problem ASAP as my project is stuck due to this error
I am using multiparty node module to process the uploaded files and have XLSX file content as bytes.
Can i pass that bytes content to src
to API convertExcel(<src>, <dst>, isColOriented, callback);
instead of path to source Excel file ?
@stevetarver Waiting for your reply man.
Having excel columns using embedded arrays like aliases[] which are empty produce an array with an empty string. So
aliases[]: stormagedden;bob
creates
"aliases": [
"stormagedden",
"bob"
]
which is fine.
aliases[]:
creates
"aliases": [
""
]
which should be
"aliases": [ ]
Hi,
I want to read very huge file, and process data in parts, Does it has this option?
Hi,
I am getting this error when trying to convert an Excel file.
I am certainly missing something and I am quite unexperienced on the matter.
Could you please help ?
Thank you !
Is there away to pass in options the sheet name instead of sheet index?
If you (or someone else coming from Google) are ever gonna rewrite this in javascript.
I dropped the fs
part but the rest works like this.
This could be left open so that googlers see it.
I also rewrote this code and included it in read-excel-file
library which parses *.xlsx files as JSON:
https://github.com/catamphetamine/read-excel-file
// Create a list of json objects; 1 object per excel sheet row
//
// Assume: Excel spreadsheet is a rectangle of data, where the first row is
// object keys and remaining rows are object values and the desired json
// is a list of objects. Alternatively, data may be column oriented with
// col 0 containing key names.
//
// Dotted notation: Key row (0) containing firstName, lastName, address.street,
// address.city, address.state, address.zip would produce, per row, a doc with
// first and last names and an embedded doc named address, with the address.
//
// Arrays: may be indexed (phones[0].number) or flat (aliases[]). Indexed
// arrays imply a list of objects. Flat arrays imply a semicolon delimited list.
/**
* Classifies a key.
* If the key ends with a number in square brackets then it's an array element.
* If the key ends with a "[]" then it's an array.
* Otherwise it's a generic property.
* @param {string} key
* @return An array of shape `[isArrayOrArrayElement, property, arrayElementIndex]`.
*/
function parseKey(key) {
// If the key ends with a number in square brackets
// then it's an array element.
// `phones[2]` -> [true, 'phones', 2].
const index = key.match(/\[(\d+)\]$/);
if (index) {
return [true, key.split('[')[0], Number(index[1])];
}
// If the key ends with a "[]"
// then it's an array.
// `phones[]` -> [true, 'phones', undefined].
if (key.slice(-2) === '[]') {
return [true, key.slice(0, -2), undefined];
}
// It's a generic property.
// `phone` -> [false, 'phone', undefined].
return [false, key, undefined];
}
/**
* Converts textual value to a javascript typed value.
* @param {string} value
* @return {(string|number|boolean)}
*/
function convertValue(value) {
// If the value is empty.
if (!value || !/\S/.test(value)) {
return null;
}
if (isFinite(value)) {
return Number(value);
}
const testVal = value.toLowerCase();
if (testVal === 'true') {
return true;
}
if (testVal === 'false') {
return false;
}
return value;
}
// Assign a value to a dotted property key - set values on sub-objects
function set(obj, path, value, options) {
// On first call, a `path` is a string.
// Recursed calls, a `path` is an array.
if (typeof path === 'string') {
path = path.split('.');
}
// Array element accessors look like phones[0].type or aliases[]
const [isArrayOrArrayElement, property, arrayElementIndex] = parseKey(path.shift());
// If this is an array or object.
// (has some child keys let to set)
if (path.length > 0) {
if (isArrayOrArrayElement) {
if (!obj[property]) {
obj[property] = [];
}
let i = obj[property].length - (arrayElementIndex + 1);
while (i > 0) {
obj[property].push({})
i--;
}
return set(obj[property][arrayElementIndex], path, value, options);
} else {
if (!obj[property]) {
obj[property] = {};
}
return set(obj[property], path, value, options);
}
}
if (isArrayOrArrayElement && arrayElementIndex) {
console.error(`WARNING: Unexpected key path terminal containing an indexed list for <${property}>`);
console.error("WARNING: Indexed arrays indicate a list of objects and should not be the last element in a key path");
console.error("WARNING: The last element of a key path should be a key name or flat array. E.g. alias, aliases[]");
}
if (options.omitEmptyFields && value === '') {
return obj;
}
if (isArrayOrArrayElement && !arrayElementIndex) {
obj[property] = value.split(';').map(convertValue);
} else {
obj[property] = convertValue(value);
}
return obj;
}
// Transpose a 2D array.
// https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript
const transpose = array => array[0].map((_, i) => array.map(row => row[i]));
const DEFAULT_OPTIONS = {
sheet: '1',
isColOriented: false,
omitEmptyFields: false
};
// Convert 2D array to nested objects. If row oriented data, row 0 is dotted key names.
// Column oriented data is transposed.
export default function convert(data, options) {
if (options) {
options = {
...DEFAULT_OPTIONS,
...options
};
} else {
options = DEFAULT_OPTIONS;
}
if (options.isColOriented) {
data = transpose(data);
}
const keys = data[0];
const rows = data.slice(1);
const result = [];
for (const row of rows) {
const item = {};
for (let i = 0; i < row.length; i++) {
set(item, keys[i], row[i], options);
}
result.push(item);
}
return result;
}
Why are the doc examples in Coffeescript? Is this your syntactic dogma?
it can't read excel on nodejs 7.5.0
excel-as-json/src/excel-as-json.coffee
Line 26 in 440aaaa
Hi i was just checking what is under the hood, and asked myself how would I check if a variable was an Object or Array, so the more precise way seemed to let Array prototype method to decide it. Just a suggestion
Fields with the values like 2016-06-01 4:30:00 PM
are converted to doubles, like so 42522.6875
. I would expect strings at the very least.
When using nested fields like:
furtherInformation.icon | furtherInformation.description | button.title | button.link |
---|
excel-as-json creates:
{
"furtherInformation": {},
"button": {}
},
{
"furtherInformation": {},
"button": {}
},
{
"furtherInformation": {},
"button": {}
},
{
"furtherInformation": {},
"button": {}
},
{
"furtherInformation": {},
"button": {}
},
{
"furtherInformation": {},
"button": {}
}
Please advise/fix this unnecessary code. 👍
I have been trying to figure out a way to pass in my .xlsx file as an Object - as it is uploaded by the client (after which it will be converted). I haven't been able to get very far, are there any suggestions on how I could tackle this?
What if I were to store the .xlsx file in Mongo (although I am not entirely sure how it will be saved in there)?
Lets say i am having an Excel with three Sheets having different data with different headers. I need to convert all the data in the excel sheet to three separate Json files? Is it possible?
Hi,
I've got an excel file like this:
A | B |
---|---|
settings.layout[0][] | [i] |
settings.layout[0][] | [e] |
settings.layout[0][] | [ɛ] |
settings.layout[0][] | [a] |
settings.layout[0][] | [y] |
settings.layout[0][] | [ø] |
settings.layout[0][] | [œ] |
settings.layout[0][] | [u] |
settings.layout[0][] | [o] |
settings.layout[1][] | [ɔ] |
settings.layout[1][] | [ɛ̃] |
settings.layout[1][] | [f] |
I excepted the output to be:
[
{
"settings": {
"layout": [
[
"[i]",
"[e]",
"[ɛ]",
"[a]",
"[y]",
"[ø]",
"[œ]",
"[u]",
"[o]",
],
[
"[ɔ]",
"[ɛ̃]",
"[f]",
]
]
}
}
]
But instead I get:
[
{
"settings": {
"layout[0]": [
"[o]"
],
"layout[1]": [
"[f]"
],
"layout[3]": [
"****"
]
}
}
]
Am I missing something or the plugin doesn't handle the array markup recursively?
If I have in something like this in Excel:
A | B |
---|---|
settings.other[0].setting1 | value1 |
settings.other[0].setting2 | value2 |
I got the following output (as expected):
[
"settings": {
"other": [
{
"setting1": "value1",
"setting2": "value2"
}
]
But how I define an array in setting1
? If I do:
A | B |
---|---|
settings.other[0].setting1[] | value1.1 |
settings.other[0].setting1[] | value1.2 |
settings.other[0].setting2 | value2 |
I got the following output:
[
"settings": {
"other": [
{
"setting1": [
"value1.2"
],
"setting2": "value2"
}
]
}
]
Thanks for your help.
I'm getting this error. My code:
convertExcel = require('excel-as-json').processFile;
convertExcel('prodeint_seleccion_parcelas.xlsx',
'parcelas.json',
false,
function(err, data) {
if(err) console.log(err);
});
And the log:
throw new Error("This deferred has already been resolved");
^
Error: This deferred has already been resolved
at notifyAll (/var/www/html/test-projects/excel-json/node_modules/node-promise/promise.js:147:13)
at Deferred.reject.reject.errback.emitError (/var/www/html/test-projects/excel-json/node_modules/node-promise/promise.js:200:5)
at Parse.<anonymous> (/var/www/html/test-projects/excel-json/node_modules/excel/excelParser.js:29:13)
at emitOne (events.js:83:20)
at Parse.emit (events.js:170:7)
at /var/www/html/test-projects/excel-json/node_modules/unzip/lib/parse.js:60:12
at processImmediate [as _immediateCallback] (timers.js:384:17)
Hi,
I am using
MAC OS 10.14.2
excel-as-json 2.0.2
"[]" was generated as the only content in the json file for me.
I am quite sure there is no problem with my file path setting.
@stevetarver Could you please help to see what's wrong with the package?
Our application generates a XLS report, but right now we have an issue where it is generating a corrupted xls, but I realized that an error is not caught trying to read this corrupted xls, I try debugging and identified specifically in the "return excel()" function it doesn't enters, not sure how to provide my xls as an example.
processFile = function(src, dst, options = _DEFAULT_OPTIONS, callback = void 0) {
options = _validateOptions(options);
if (!callback) {
callback = function(err, data) {};
}
// NOTE: 'excel' does not properly bubble file not found and prints
// an ugly error we can't trap, so look for this common error first
if (!fs.existsSync(src)) {
return callback(`Cannot find src file ${src}`);
} else {
return excel(src, options.sheet, function(err, data) {
============>>> CODE NEVER REACHES THIS PART <<<==================
var result;
if (err) {
return callback(`Error reading ${src}: ${err}`);
} else {
result = convert(data, options);
if (dst) {
return write(result, dst, function(err) {
if (err) {
return callback(err);
} else {
return callback(void 0, result);
}
});
} else {
return callback(void 0, result);
}
}
});
============>>> CODE NEVER REACHES THIS PART <<<==================
}
};
So , when I try this, it doesn't even prints the first console.log();
convertExcel(filename, 'row.json', options, (err, data) => {
console.log("Starts")
if (err) {
console.log("err " + err);
console.log("data " + data)
}
else {
console.log("else");
}
});
numbers[] |
---|
1;2 |
3;5 |
Shold be:
[{
"numbers": [
1,
2
]
},
{
"numbers": []
},
{
"numbers": [
3,
5
]
}]
and not:
[{
"numbers": [
1,
2
]
},
{
"numbers": [
""
]
},
{
"numbers": [
3,
5
]
}]
Is it possible to skip some empty array fields in the excel. I have a use case where I may have multiple array objects for some rows and not for some like
packages[0].name packages[1].name packages[2].name
Discount Discount Offer
Discount Discount
when I try to parse such an excel, for the second row it gives me packages[2].name: 0 in the resulting json. Can you maybe add such a feature to skip empty fields ?
My use case is such that I'm trying to upload JSON data to Firestore.
My excel output currently gives me this JSON:
[
{
"itemName": "item",
"price": 1,
"unit": "unit",
"docId": "null",
"companyName": "temp",
"companyNameKey": "temp",
"companyDocId": "id",
"location": {
"country": "Country",
"state": "State",
"city": "City",
"_geoloc": {
"lat": 1,
"lng": -1
}
}
}
]
But I need each row/col to have an arbitrary unique identifier attached like this:
{
"1":{
"itemName": "item",
"price": 1,
"unit": "unit",
"docId": "null",
"companyName": "temp",
"companyNameKey": "temp",
"companyDocId": "id",
"location": {
"country": "Country",
"state": "State",
"city": "City",
"_geoloc": {
"lat": 1,
"lng": -1
}
}
}
}
How can I achieve this?
Ex:
My Nam | Date of Birth
...... | ............
---
// Output
[
{otherName:......, dob:....}
]
I am using this lib in a simple way where i get a excel and i have to covert the excel to json.
It works perfectly most of the time but sometimes the callback func is never called. Even though data is same and files its trying to read exist.
I am uploading the test file we are using also a small code sample
Test (2).xlsx
exports.excelToJson = (path, options) => {
return new Promise((resolve, reject) => {
ConvertExcel(path, null, options, (err, data) => {
if (err){
return reject(err);
}
return resolve(data);
});
});
};
path = "uploads/Test (1).xlsx_1531299759197"
options = {sheet: "1", isColOriented: false, omitEmtpyFields: false}
I will be available if any other details are required.
Hi,
Given below is the code snippet that I am using to generate the json file from the attached excel file.
NodeJS Version - v10.15.0
const convertexcel = require('excel-as-json').processFile
convertexcel('C:/RTC/METS_DEV_FUTURE/Get_Insured_Test_Data_Creator/Test_Data.xlsx','C:/RTC/METS_DEV_FUTURE/Get_Insured_Test_Data_Creator/Test_Data_New.json',{'isColOriented':true},()=>{
console.log('Completed')
})
When I execute the above code I keep getting the below error -
C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator>node temp.js
C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator\node_modules\node-promise\promise.js:204
throw error;
^
TypeError: Cannot read property 'length' of undefined
at transpose (C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator\node_modules\excel-as-json\lib\excel-as-json.js:153:37)
at convert (C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator\node_modules\excel-as-json\lib\excel-as-json.js:172:14)
at C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator\node_modules\excel-as-json\lib\excel-as-json.js:283:20
at C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator\node_modules\excel-as-json\node_modules\excel\excelParser.js:163:3
at Immediate. (C:\RTC\METS_DEV_FUTURE\Get_Insured_Test_Data_Creator\node_modules\node-promise\promise.js:164:27)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
Could you please let me know what I am doing incorrectly?
Hi,
This is very cool utility! thanks much for offering this!!
In excel, i have all cells formatted as string (to avoid auto formatting of numbers/date). While converting this excel to json, the string column is auto recognized as numeric column (based on cell value) and the converter is stripping off leading zeros (which is obvious for a numeric json node value).
Is there a way i can force converter to treat the number as string and retain those leading zeros.
Note: I'm using Excel workbook *.xlsx
Thanks!
Curious if sheets can be referenced by name vs number? i.e. "Employees" vs "Sheet1"
Thanks,
Mike Brown
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.