我正在从我的系统中测试一个新流程,我需要将csv电子表格导入到我的database
,但是我所知道的excel有许多不必要的列我喜欢选择导入示例的特定列:
> **VERSION_ID TN RN1 DATA OPERACAO CN**
> 24246610 3000010300 55115 26/11/2012 22:02 1 11
> 28610111 3000012345 55115 06/08/2013 23:03 1 11
> 23041462 3000026314 55115 18/09/2012 23:01 1 11
> 33418254 3000052576 55115 27/06/2014 01:00 1 11
我需要在代码中执行代码以在JSON中仅选择TN和RN1列
我的代码已经将csv转换为JSON,但它需要excel的所有列..
代码:
var Converter = require("csvtojson").Converter;
var fs=require("fs");
//CSV File Path or CSV String or Readable Stream Object
var csvFileName="teste.csv";
//new converter instance
var csvConverter=new Converter({});
//end_parsed will be emitted once parsing finished
csvConverter.on("end_parsed",function(jsonObj){
console.log(jsonObj); //here is your result json object
});
//read from file
fs.createReadStream(csvFileName).pipe(csvConverter);
答案 0 :(得分:0)
var Converter = require("csvtojson").Converter;
var firebase = require("firebase");
var express = require("express");
var fs=require("fs");
csv({noheader:true,
delimiter:";"})
.fromFile(csvFilePath)
.on('json',(jsonObj)=>{
// combine csv header row and csv line to a json object
// jsonObj.a ==> 1 or 4
var TN = jsonObj.field2;
var cod_op = jsonObj.field3;
var msisdn = TN.toString();
noticia.child(msisdn).set(cod_op);
console.log(TN + ' ' + cod_op);
})
.on('done',(error)=>{
console.log()
})