Formatting Field Collection data with Views Data Export (CSV) I've got a Field Collection on use in a basic page content type on my Drupal 7 site. I've built a view with the Data Export module that is outputting the data from nodes of this content type as a CSV. The view is configured to dump all of the Field Collection data for each parent node into one cell... not ideal, but I'll live with it. 

The problem is that there is no separator between the fields in the Field Collection. So, the contents of the Field Collection cell in the CSV looks like this:

Fruit_1: AppleFruit_2: OrangeFruit_3: Banana


It makes reading through the data in that cell unbearable (the separator should be after Apple and Orange... oh and fruit is just for this example, not actual data). 

How do I get some kind of separator in there? Doesn't have to be anything fancy; something as simple as a comma and a space would be lovely! Ex:

Fruit_1: Apple, Fruit_2: Orange, Fruit_3: Banana


I've experimented with Field Collection Views, but no luck.
The solution is to implement a views_pre_render hook in a custom module.

function mymodule_views_pre_render(&amp;$view) {
    if ($view-&gt;name == 'myview') {
        foreach ($view-&gt;result as $key =&gt; $row) {
            $line = array();
            foreach ($view-&gt;result[$key]-&gt;field_field_fruit_collection as $n =&gt; $collection) {
                $item = current($collection['rendered']['entity']['field_collection_item']);
                $line[] = $item['field_fruit'][0]['#markup'] .  ' (' . $item['field_color'][0]['#markup'] . ')';
                unset($view-&gt;result[$key]-&gt;field_field_fruit_collection[$n]);
            }
            $view-&gt;result[$key]-&gt;field_field_fruit_collection[0]['rendered']['#markup'] = implode(', ', $line);
        }
    }
}


In this example, the collection field is field_fruit_collection which is made up of two fields: field_fruit and field_color. The contents of the exported collection field will look like :

"Apple (red), Banana (yellow), Kiwi (green)"