Papaparse无法解析添加__extra_data,我在做什么错?

时间:2019-01-11 15:15:40

标签: javascript json csv papaparse

我终于弄清楚了如何解析CSV文件,过滤数据,不解析回CSV文件,但是现在我遇到了CSV文件问题。当解析数据papa.unparse将所有标题添加到每一行时,我需要弄清楚如何阻止这种情况的发生。

https://imgur.com/a/Lg6Dyho

var fs = require("fs");
const papa = require("papaparse");
const file = fs.createReadStream("./csv/inventory.csv");
const finalFile = fs.createWriteStream("./csv/inventory_updated.csv");

papa.parse(file, {
  worker: true,
  header: true,
  transformHeader: true,
  skipEmptyLines: true,
  step: function(result) {
    let data = result.data;
    data = data.filter(d => d["Mill Description"].includes('adidas') || d["Mill Description"].includes('Champion'));
    var jsonData = JSON.stringify(data)

    var csvData = papa.unparse(jsonData, {
      worker: true,
      quotes: false,
        quoteChar: '"',
      skipEmptyLines: true
    })
    finalFile.write(csvData, "utf8")
  },
  complete: function() {
    finalFile.on('finish', () => {
      console.log("File Saved")
    });
    finalFile.end()
  }
});

0 个答案:

没有答案