cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

LF's in CSV to result in a Multi-Line Cell in Excel

alex_panganiban
Contributor

Could use some advice here. I am trying to take a string of data (a group of key/value pairs) that is comma delimited and insert it into a single Excel cell so that it shows as multiple lines within the cell.

For example, I have a data string that looks like this:

dataString == โ€œkey1:value1, key2:value2, key3, value3โ€

When I open my CSV file in Excel, I want the cell that holds this string to look like this:

key1:value1
key2:value2
key3:value3

In my attempt to do achieve this formatted cell, Iโ€™m using a mapper that has the following expression.

$dataString.replace(/,/g, /\n/)

I am expecting the commas to be replaced with line feed regex characters, but instead what I see in Excel looks like this:

key1:value1/\n/key2:value2/\n/key3:value3

I feel as though the CSV formatter is not recognizing the escape characters and resolving the \n into a line feed. Thatโ€™s just a guess because Iโ€™ve tried many things, but unsuccessfully. Can anyone help?

3 REPLIES 3

JensDeveloper
Contributor II

Hi @alex.panganiban.guild

You need to update your expression to
$dataString.replace(/,/g, โ€œ\nโ€)

This modification will replace the commas with line feed characters, resulting in the following formatted string:
{
dataString:
โ€œkey1:value1\n key2:value2\n key3:value3โ€
}
After using the csv formatter and file writer the excel file looks like this:
image

Let me know if this helps

Regards

Jens

Thanks, Jens. So I had tried this solution before and again after you posted. Unfortunately, what I get is a truncation after the first line feed. I get the first key/value pair in the cell, but lose the remaining data in my string. Iโ€™ll try and play around some more and see if I can send you an actual sample of what Iโ€™m doing.

Thanks.

Hi. I got this figured out. The problem was in Excel, where the cellโ€™s height wasnโ€™t automatically adjusting to the height of the data, so only the first line was displaying, and the remaining lines were obfuscated. Thanks for the assist!