Append to csv not on new line

Hi all, really new here, just trying to append row to a csv, it works but all is added on one line, also there is a ZWNBSP between lines.

the workflow:

Hi and welcome to the community!

ZWNBSP is a Unicode zero-width no-break space character and it is a part of so called BOM (byte order mark). It is added to Unicode files so that multiple systems know how to properly interpret sequences of bytes that represent Unicode characters.

It is normally OK to have it the beginning of the file, not so OK within the file.

MS Excel and Google Sheets interpret those properly.

Just tested your setup with one more row but without actually writing the file (I use cloud n8n). Simply downloaded the file from the node. Managed to open with no problem with MS Excel and Google Sheets.

Not a solution to your question, but is there really a problem?

Hey! thanks for the reply. only thing different was the brackets in the code block but i copied anyway. Problem is with append is still not solved for me. here is a screenshot from google sheet.

also ZWNBSP is being added before each append/line

edit: i checked and the downloaded file from convert to file does looks good, but it shows the above after the save/append node

I do not have proper environment to test it, but I believe Append is the cause of the problem:

Some workarounds I would use if I were you:

  1. Read CSV file and extract data, append record, write entire file
  2. Store data in cloud (Google Sheets, Airtable etc)

Is any of the above an option for you to get unblocked?

i checked and the downloaded file from convert to file does looks good, but it shows the above after the save/append node

I managed to use the merge node by reading the file first from disk, but rewriting the whole file feels inefficient. What if i have a big csv later. It would be easier to just write a few lines of python instead. Append really should work here in a simple example

I agree with both statements. Maybe you could submit a bug for the n8n team to review. I am sorry for I cannot really be of any constructive help here.

So while i got it working with csv and xlsx using a combination of read, write, code and merge nodes, in the end i always had to overwrite the file. Everything works fine until you are forced to convert it to a binary file because that is what Write file node expects, and that adds ZWNBSP.

so my solution is to use Exec node, no need to use ten nodes to do something simple.

console.js file:

const fs = require('fs');

const path = require('path');

const filePath = path.join(__dirname, 'p.csv');

const newRow = `2023-10-05,200.50\n`;

fs.appendFileSync(filePath, newRow, 'utf8');

console.log('Row appended:', newRow.trim());

Looks like this is the way for you to get unblocked and proceed in development.

Yeah, I myself tend to employ Code blocks to implement complex data transformations and business logic, which otherwise would result in multiple Ifs, Sets, Switches etc with unbearably intertwined web of node links. Although I guess it defeats the n8n’s idea which is to enable not-so-techy folks. Guilty as I am.

I have made a note to see if I can reproduce this, Thanks for letting me know about it @Olek

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