为什么我不能在node.js中解析这个CSV文件?

时间:2013-07-01 20:15:58

标签: node.js csv

这是我的代码:

var options = {

    rowDelimiter: 'windows',
    encoding: 'ascii'

}

var data = fs.readFileSync(localFolder+'/'+file, 'ascii');                  

console.log(data);

csv().from.string(data, options).to.array(function(data, count) {

    console.log(data);

});

第一个console.log返回以下数据:

"Filename","DID#","Document Type","Date Sent","School","First Name","Middle Name","Last Name","DOB","SSN","Application #","Common App ID","RH CEEB","Class Of","Years Attended" "TR58A3D.pdf","TR58A3D","Transcript","07/19/2012","zz Screaming Eagle High School","Kim","","Smith","05/05/1995","","","","555555","2013","" "TR58AQH.pdf","TR58AQH","Transcript","07/19/2012","zz Screaming Eagle High School","Jon","","Sink","05/09/1996","","","","555555","2015",""

[scott@localhost]$ file transcripts/index_07_19_2012_1043460.csv transcripts/index_07_19_2012_1043460.csv: ASCII text, with CRLF line terminators

第二个console.log不会向我的控制台打印任何内容。任何人都有任何想法,为什么它不解析CSV?

1 个答案:

答案 0 :(得分:1)

问题是rowDelimiter选项的价值。它必须是使用的实际换行符 - 即:\r\n\r