Help - CSV node issue

Can you please attach only the script?
I still have problems.
Is it possible that my raspbian node-red javascript is different that yours?

Import the floe. Edit the second function node, change all cases where you see \" to ' (a single quote)

  1. what platform are you using? What OS and version?
  2. what version of NR and node.js? (can be found on NR start up log)

Screen Shot 2020-02-20 at 6.38.27 AM

The EXCEL unique box says:
[{"400":"550","12:51":"12:51","20/2/2020":"20/2/2020"}]

And node-red says:
20/2/2020, 12:51:30node: b839c2e4.531f9
f29ea04f.3e7fa : msg.payload : array[1]
array[1]
0: object
400: "550"
12:51: "12:51"
20/2/2020: "20/2/2020"

Here's my system:
19 Feb 12:56:07 - [info] Node-RED version: v1.0.3
19 Feb 12:56:07 - [info] Node.js version: v10.15.2
19 Feb 12:56:07 - [info] Linux 4.19.97-v7l+ arm LE

A question.... Have you tried open your excel export and verify the correctness of your script?

Given the fact that you have not provided your flow, the answer is 'no' since I don't have your flow.

Did you try the flow I provided - a simple inject -> function (to build a msg.payload with an array) -> function (with the code I provided)-> debug.

In my test the debug shows two lines of the data I posted above. When you run that flow, what output do you get (after fixing the "'s)?

1 Like

Hi.
Yesterday in the late afternoon I've changed the point of view... Thought that ok the values in a string separated by a comma, the goal should be acting into EXCEL and every time split the string into the columns.
I've spent too much time even now, and if I continue I'm almost sure not to go beyond.
Thanks and bye.

The CSV node is quite smart as it accepts three different types as its input: a JavaScript object, array or CSV string. The function in the OP is feeding an array of arrays to the CSV node. This is what the node help text says:

  • If the input is an array of simple values, it builds a single line CSV string.
  • If the input is an array of arrays, or an array of objects, a multiple-line CSV string is created.

so, the output seen in the OP is consistent with the help text: one line for each element of the array.

If the function node is changed to return an array of single values the result will be different and probably in the format that is wanted.

return {payload: [ z0, z1, t , tt ] };

My guess is that the code for the CSV node uses the JavaScript .join() method to transform an array of values into a string separated by comma ( , ).

I just donĀ“t get the last element of the array. Looks unusual to return [,]. Even the editor is warning with a yellow triangle that this construction has something wrong.

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