I have been trying to convert excel sheet data to json format and I have already various modules like "xls-to-json","xls-to-json-lc","node-excel-to-json", So far I have got empty response.
My sample code goes like this :
var node_xj = require("xls-to-json");
node_xj({
input: req.file.path, // input xls
output: "output.json", // output json
sheet: "a" // specific sheetname
}, function(err, result) {
if(err) {
console.error(err);
} else {
console.log("--------result----");
console.log(result);
}
});
My excel sheet contains very simple data :
What am i doing wrong in this , I am getting file and its valid path .
got the solution , all the libraries consider first row as header , so it was not getting displayed , it got displayed when i added 2nd row and every module has got its own structure of output/ response. some modules consider excel headers in output and skip the first row and few include first row .
Related
I am using Exceljs library to export data from the database using Nodejs, Now I am trying to set the column Header name dynamically from columns=36 (i.e. AK) to till the end or until it has data. but nothing helps.
column name strictly needs to start from 36th (i.e. AK) column name
labels array are like this -
[
'Type',
'Competition',
'IDB',
'SOV Focus',
'Medium',
'Tone'
]
So, I only need to print these in the header.
con.query(query, id, function (err, result) {
if (err) throw err;
const labels = [];
result.forEach((result) => {
labels.push(result.label);
});
labels.forEach((label, index) => {
const columnName = label;
// Get the column using the column index (in this case, 1)
const firstRow = worksheet.getRow(1);
// Set the value of the first cell in the row to the dynamic column name
firstRow.getCell(36, columnName);
});
});
But it is not working or throwing any errors.
Previously I used PHPSpreadhsheet in PHP but it was not able to handle huge data export and took much time to export data.
but in PHPspreadsheet it was so easy to set dynamic header names.
$sheet->setCellValueByColumnAndRow($col, 1, trim($labels[$k] , ','));
How will I set columns/header names dynamically?
I need to load .xlsx in node and angularjs app.
i have used some packages for that purpose like js-xlsx it give me a all the data, but I can't find images of the excel sheets nor in JSON neither in HTML generated by js-xlsx package.
var wb = XLSX.read(data.data, {
type: "array"
});
let sheets = [];
for (const key in wb.Sheets) {
sheets.push({
paneId: key.replace(/ /g, '').toLowerCase(),
title: key,
active: false,
disabled: false,
data: $scope.processData(XLSX.utils.sheet_to_csv(wb.Sheets[key]))
})
}
I have also tried.
XLSX.utils.sheet_to_json(wb.Sheets[key])
XLSX.utils.sheet_to_html(wb.Sheets[key])
$scope.processData is the function for converting csv to array.
I am working in nodejs and have to read each row in excel and insert the data found there into tables. I am trying to iterate over rows but am unable to do so due to asynchronous nature.
I wish to iterate the below code on a for loop that contains total columns present in the excel sheet.
getStoneData(data, function (err, rst) {
if (err) {
console.log(err);
cb(err); // call callback with error
}
sql.close();
sql.connect(config, err => {
fetchLastID()
.then(insertFirstStoneData)
.then(fetchInsertedID)
.then(insertAllDataFromID)
.then(lastMethod);
})
}
Only the first data gets inserted.
I want to parse a csv file with csv-parse. At this moment, I can parse a file with header if there is not a caption at the first row of the file. So for example my file is like this:
Item1;Item2:Item3
Test1;Test2;Test3
But I need to be able to skip the first rows, because the actual data is like this:
This is a file with items
Items are stored below:
Item1;Item2:Item3
Test1;Test2;Test3
So I am in need to skip the first rows. csv-parse can do this with the from: option. But when I use this it will return an error that the Number of columns is inconsistent. This is true, because the first few rows are text, so only one column. But csv-parse will not ingnore the first few rows when I set for example from: 4 as an option.
My code:
var fs = require('fs');
var parse = require('csv-parse');
var parser = parse({delimiter: ';', from: 2}, function(err, data){
if(err){
return console.log(err);
}
var keys = data.shift();
var objects = data.map(function(values) {
return keys.reduce(function(o, k, i) {
o[k] = values[i];
return o;
}, {});
});
console.log(objects);
});
fs.createReadStream(path).pipe(parser);
Thank you in advance,
Sven
var availableNames=['Hello India', 'Hello India', 'Test', 'Test']
$.unique(availableNames);
$("#corpName").autocomplete({
source : availableNames,
minLength : 4
});
availableNames is my array source for auto-complete. I want to show unique values in the list so called jquery unique function.
The unique function is working fine for single words like 'Hello' but not for two word strings like 'Hello India'. Its showing two 'Hello India' in dropdown and one 'Hello'.
Please Suggest me how to display only unique values in the drop-down list.
Thank You.
you have to write your own function. There are two ways to do that:
use filter:
// returns a new array with unique entries
Array.prototype.unique = function() {
return this.filter(function(el, index, oThis) {
return index === oThis.indexOf(el);
});
}
EDIT here is a real prototype version, that changes the original array
Array.prototype.unique2 = function() {
var c=this.length;
while(c--)
c===this.indexOf(this[c])||this.splice(c,1);
};
you can test both versions in this fiddle: http://jsfiddle.net/6mpqaxhk/