# Separate CSV columns

**URL:** https://discourse.nodered.org/t/separate-csv-columns/86831
**Category:** General
**Created:** [28 March 2024 14:42 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831 "2024-03-28T14:42:18Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [28 March 2024 14:42 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/1 "2024-03-28T14:42:18Z")

</div>

Hello, I'm new to Node-RED. Having some trouble with sending data to CSV. I need two separate columns with different names and different data below for example but I'm getting everything in one line. Please tell me how to solve this.

Thank you

```auto
[{"id":"2f90ce8fb2a257e8","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"0ecfc4ef4d17d3e1","type":"inject","z":"2f90ce8fb2a257e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":120,"wires":[["d4254ce887f93f08"]]},{"id":"d4254ce887f93f08","type":"function","z":"2f90ce8fb2a257e8","name":"function 1","func":"msg.payload = {\n \"Time\" : Math.random()*10,\n \"Sensor\" : Math.random()*50\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":300,"y":120,"wires":[["836b5d25ef304aa5","b9fdab2c3579f04f"]]},{"id":"b9fdab2c3579f04f","type":"debug","z":"2f90ce8fb2a257e8","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":660,"y":60,"wires":[]},{"id":"836b5d25ef304aa5","type":"csv","z":"2f90ce8fb2a257e8","name":"","sep":",","hdrin":true,"hdrout":"once","multi":"one","ret":"\\r\\n","temp":"Time,Sensor","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":450,"y":140,"wires":[["e8717b2e16748674","b9fdab2c3579f04f"]]},{"id":"e8717b2e16748674","type":"file","z":"2f90ce8fb2a257e8","name":"","filename":"C:\\Users\\Dell\\Documents\\Test.csv","filenameType":"str","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":720,"y":180,"wires":[[]]}]

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [28 March 2024 16:40 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/2 "2024-03-28T16:40:15Z")

</div>

We cannot use that code, please replace by pasting the code into a preformatted text blog.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [28 March 2024 16:57 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/3 "2024-03-28T16:57:56Z")

</div>

Looking at your function code you are sending a single object into the csv node. If you require multiple lines then you would need to send an array of objects, an object for each line.  
e.g.

```auto
[
  {
    "Time": 10,
    "Sensor": 50
  },
  {
    "Time": 15,
    "Sensor": 20
  }
]

```

---

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [28 March 2024 17:17 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/4 "2024-03-28T17:17:11Z")

</div>

Yes. I see a single object on a debug node - (time with value and sensor with value). I want to get -  
(1 column - Time with value below), (2 column - Sensor with value below).

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [28 March 2024 17:35 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/5 "2024-03-28T17:35:12Z")

</div>

That is what you get.  
it is the followed by a carriage return `\r` and a new line `\n`. This is a text csv format.

As image shows

 ![chrome_screenshot_28 Mar 2024 17_40_10 GMT](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/800244c3d5fc3ab5eaf09ca396dee5c89812636b.png)

Attach the file that is created after you click inject several times, as i see no errors.

---

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [28 March 2024 17:40 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/6 "2024-03-28T17:40:10Z")

</div>

Here - [https://file.io/mguUlmI1rhfL](https://file.io/mguUlmI1rhfL)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [28 March 2024 17:43 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/7 "2024-03-28T17:43:23Z")

</div>

As said all working correct

 ![Screenshot_20240328-174235](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75474f7e4202961bd57f63b8f95233c4f128f3c8.png)

Unless you want one header row and only one value row, if so set csv node to always send header and file write node to overwrite and not append.

---

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [28 March 2024 17:49 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/8 "2024-03-28T17:49:28Z")

</div>

Hmm, maybe is something wrong with my Excel or something else, have no idea.

This is what I want to achieve -  
 ![test](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/deb2547505f75982909e5da42b375d9b8d1e2bb7.jpeg)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [28 March 2024 17:57 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/9 "2024-03-28T17:57:23Z")

</div>

When I open test,csv in my spreadsheet I get

 ![Screenshot_20240328-175515](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/8/e874e0f232f3665fb794fde2e0445c028d41cf99.png)

Must be an issue on your device/spreadsheet program if it is not opening like above.

---

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [28 March 2024 18:04 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/10 "2024-03-28T18:04:06Z")

</div>

So I achieved what I wanted just not for myself yet 😃  
I'll try to check my software settings later, whats wrong with my MS Excel.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [28 March 2024 18:05 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/11 "2024-03-28T18:05:38Z")

</div>

Not a windows user, so can not help you there, sorry.

---

<div class="post-metadata">

### Author: ![steerage250](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steerage250/32/38999_2.png) [@steerage250](https://discourse.nodered.org/u/steerage250)
#### Post date: [30 March 2024 23:09 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/12 "2024-03-30T23:09:36Z")

</div>

The other thing to check is the Properties of your CSV node and make sure the boxes concerned with writing the column headers are checked.

Sometimes I want to delete my CSV file, so I have an inject node that I can manually trigger to send a msg.reset to the CSV node to force it to write the header row again when it next writes.

 ![csv node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a4d6e0cde0a51483283a9e82234525c75a05bf28.jpeg)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [4 April 2024 15:21 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/13 "2024-04-04T15:21:08Z")

</div>

A post was split to a new topic: [Send csv to a line chart](https://discourse.nodered.org/t/send-csv-to-a-line-chart/87011)

---

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [5 April 2024 06:39 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/14 "2024-04-05T06:39:22Z")

</div>

Sorry for bothering you with so basic stuff, I'm still playing around with those .csv exports and got a problem again. Somehow it just stopped working correctly and passing _I guess empty string_ after each value line, can't figure it out whats wrong with the flow. Tried everything I could think of, even reinstalled Node-RED. I did not changed any settings, parameters or regional settings on my windows that could impact csv. Can anyone please help me get rid of that empty string after each value?

```auto
[{"id":"2264aaaad0fa21d2","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"14a01548145009e3","type":"inject","z":"2264aaaad0fa21d2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":120,"wires":[["2cd8ca29e301798b"]]},{"id":"2cd8ca29e301798b","type":"function","z":"2264aaaad0fa21d2","name":"function 1","func":"// Generate timestamp\nvar timestamp = new Date().getTime();\n\n// Generate random value between 0 and 1\nvar value1 = Math.random()*30;\n\n// Create payload object with timestamp and random value\nmsg.payload = {\n Timestamp: timestamp,\n Value1: value1\n}\n\n// Return the message\nreturn msg;\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":120,"wires":[["6412650615254c06","0cc2f16661a1127b"]]},{"id":"1d1e4cdc9cf055cf","type":"file","z":"2264aaaad0fa21d2","name":"","filename":"C:\\Users\\Dell\\Desktop\\Test1.csv","filenameType":"str","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":730,"y":120,"wires":[[]]},{"id":"6412650615254c06","type":"debug","z":"2264aaaad0fa21d2","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":80,"wires":[]},{"id":"0cc2f16661a1127b","type":"csv","z":"2264aaaad0fa21d2","name":"","sep":",","hdrin":true,"hdrout":"once","multi":"one","ret":"\\n","temp":"Timestamp,Value1","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":490,"y":120,"wires":[["1d1e4cdc9cf055cf"]]}]

```

![ES](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75a79188094e3afc9cbd8eda71d86250fcd6491d.jpeg)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [5 April 2024 06:50 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/15 "2024-04-05T06:50:42Z")

</div>

You are adding a \n in csv node, and also appending one in file write node.

Either add one in csv node, or file write node, but not both nodes.

---

<div class="post-metadata">

### Author: ![AleksDeco](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@AleksDeco](https://discourse.nodered.org/u/AleksDeco)
#### Post date: [5 April 2024 07:14 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/16 "2024-04-05T07:14:00Z")

</div>

Thanks a lot.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [19 April 2024 07:14 UTC](https://discourse.nodered.org/t/separate-csv-columns/86831/17 "2024-04-19T07:14:48Z")

</div>

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