Creating CSV file without headers

Hi, I need to create a csv file like this without headers

withoutheaders

I have this sample data:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 12,\n    }\n  },\n  {\n    json: {\n      id: 13,\n    }\n  },\n  {\n    json: {\n      id: 14,\n    }\n  },\n    {\n    json: {\n      id: 15,\n    }\n  },\n  {\n    json: {\n      id: 16,\n    }\n  }\n]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    }
  ],
  "connections": {}
}

How do I go about this in n8n?

Thanks

Hi @zocket, that’s a bit tricky as it’s not a built in feature of the Spreadsheet File node (so you might want to raise a feature request to have this as an option).

One possible approach would be to first read your CSV file as a string, then replace the first line with an empty string and then move the string back into a CSV file:

Example Workflow
{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      id: 12,\n    }\n  },\n  {\n    json: {\n      id: 13,\n    }\n  },\n  {\n    json: {\n      id: 14,\n    }\n  },\n    {\n    json: {\n      id: 15,\n    }\n  },\n  {\n    json: {\n      id: 16,\n    }\n  }\n]\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        450
      ]
    },
    {
      "parameters": {
        "operation": "toFile",
        "fileFormat": "csv",
        "options": {}
      },
      "name": "Spreadsheet File",
      "type": "n8n-nodes-base.spreadsheetFile",
      "typeVersion": 1,
      "position": [
        650,
        450
      ]
    },
    {
      "parameters": {
        "setAllData": false,
        "destinationKey": "csv_content",
        "options": {}
      },
      "name": "Move Binary Data",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        850,
        450
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "csv_content",
              "value": "={{$json[\"csv_content\"].replace(/.*/, \"\").substr(1)}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Remove first Line",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1050,
        450
      ]
    },
    {
      "parameters": {
        "mode": "jsonToBinary",
        "convertAllData": false,
        "sourceKey": "csv_content",
        "options": {
          "fileName": "headless.csv",
          "mimeType": "text/csv",
          "useRawData": true
        }
      },
      "name": "Move Binary Data1",
      "type": "n8n-nodes-base.moveBinaryData",
      "typeVersion": 1,
      "position": [
        1250,
        450
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "Spreadsheet File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spreadsheet File": {
      "main": [
        [
          {
            "node": "Move Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Move Binary Data": {
      "main": [
        [
          {
            "node": "Remove first Line",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove first Line": {
      "main": [
        [
          {
            "node": "Move Binary Data1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like