CSV string values containing new lines

Hi all,
just doing some tests with CSV and I notice that for string object values including commas it will put quotes around the value, but if there is a string containing a new line (e.g.) it doesn't.
This has some strange effects for things like Excel.

Wondering if this feature could be an addition.

(Example flow - CSV NR v2.1.4 on Windows)

[
    {
        "id": "7eb16217e25c257f",
        "type": "inject",
        "z": "5c26fd1ddff9dc3b",
        "name": "Sample Object",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "[{\"name1\":\"value1\",\"name2\":\"value,2\",\"name3\":\"value\\n3\"},{\"name1\":\"value1b\",\"name2\":\"value,2b\",\"name3\":\"value\\n\\r3b\"}]",
        "payloadType": "json",
        "x": 290,
        "y": 180,
        "wires": [
            [
                "2a883b09fe1c006c"
            ]
        ]
    },
    {
        "id": "2a883b09fe1c006c",
        "type": "csv",
        "z": "5c26fd1ddff9dc3b",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "all",
        "multi": "one",
        "ret": "\\r\\n",
        "temp": "",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 470,
        "y": 180,
        "wires": [
            [
                "f4bc05a9f2d6bfab",
                "53a47557e2ec91c1"
            ]
        ]
    },
    {
        "id": "f4bc05a9f2d6bfab",
        "type": "debug",
        "z": "5c26fd1ddff9dc3b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 650,
        "y": 180,
        "wires": []
    },
    {
        "id": "53a47557e2ec91c1",
        "type": "file",
        "z": "5c26fd1ddff9dc3b",
        "name": "write file",
        "filename": "c:\\Temp\\Testcsv.csv",
        "appendNewline": false,
        "createDir": false,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 640,
        "y": 240,
        "wires": [
            []
        ]
    }
] 

output is:
name1,name2,name3
value1,"value,2",value
3
value1b,"value,2b",value

3b

csv

if I manually put quotes around the strings with carriage returns, Excel is happy with it:

name1,name2,name3
value1,"value,2","value
3"
value1b,"value,2b","value

3b"

csv2

that could indeed be handled more cleanly.

PR raised here Fix CSV node to handle \n when outputting text fields by dceejay · Pull Request #3716 · node-red/node-red · GitHub

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.