這裏是我的代碼:爲什麼我不能在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",""
[[email protected]]$ file transcripts/index_07_19_2012_1043460.csv transcripts/index_07_19_2012_1043460.csv: ASCII text, with CRLF line terminators
第二console.log
不打印任何東西到我的控制檯。任何人有任何想法,爲什麼它不解析CSV?
'.from.path'需要一個文件路徑,而不是一串數據,但我不知道如何使用'.from(data)'傳遞選項。 –
對不起,我試過from.string(),而且看起來也沒有工作。 – sluther