0
我在本地服務器中有一個csv文件。我試圖一次獲取csvfile中的總行數。但我無法做到這個,請幫忙。如何使用node.js獲取csv文件中的記錄行總數
我在本地服務器中有一個csv文件。我試圖一次獲取csvfile中的總行數。但我無法做到這個,請幫忙。如何使用node.js獲取csv文件中的記錄行總數
按照柏拉圖的建議,通過庫使用CSV。
FWIW,讓任何文本文件的長度,
var content;
// First I want to read the file
fs.readFile('./local.csv', function read(err, data) {
if (err) {
throw err;
}
content = data;
processFile(); // Or put the next step in a function and invoke it
});
function processFile() {
lines = content.split("\r"); // look up
rowCount = lines.length;
}
看看這個庫https://github.com/wdavidw/node-csv – Plato
做到這一點可能:http://stackoverflow.com/a/12453463/711902 –
它無法正常工作。我想在csv文件中獲得全部no行。在我的情況下,沒有「\ r」或「\ n」。 – user2700253